 window.onload = ->
+  inspectorFrame = document.getElementById('inspector-app-iframe').contentWindow
+
   # Use menu API to show context menu.
-  InspectorFrontendHost.showContextMenuAtPoint = (x, y, items, document) ->
-    createMenu items
+  inspectorFrame.eval 'InspectorFrontendHost.showContextMenuAtPoint = parent.createMenu'
 
   # Use dialog API to override file chooser dialog.
-  WebInspector.createFileSelectorElement = (callback) ->
-    fileSelectorElement = document.createElement 'span'
-    fileSelectorElement.style.display = 'none'
-    fileSelectorElement.click = showFileChooserDialog.bind this, callback
-    return fileSelectorElement
+  inspectorFrame.eval 'WebInspector.createFileSelectorElement = parent.createFileSelectorElement'
 
 convertToMenuTemplate = (items) ->
   template = []

  # The menu is expected to show asynchronously.
  setImmediate ->
    menu.popup remote.getCurrentWindow()
    InspectorFrontendAPI.contextMenuCleared()

showFileChooserDialog = (callback) ->
  remote = require 'remote'

          label: item.label
          enabled: item.enabled
      if item.id?
        transformed.click = -> DevToolsAPI.contextMenuItemSelected item.id
      template.push transformed
  template

createMenu = (x, y, items, document) ->
  remote = require 'remote'
  Menu = remote.require 'menu'

