Fix context menu for sandbox devtools (#11933)
This commit is contained in:
parent
67f052a6e1
commit
9d1527b1df
2 changed files with 26 additions and 15 deletions
|
@ -32,8 +32,6 @@ const preloadModules = new Map([
|
|||
['timers', require('timers')]
|
||||
])
|
||||
|
||||
const preloadSrc = fs.readFileSync(preloadPath).toString()
|
||||
|
||||
// Pass different process object to the preload script(which should not have
|
||||
// access to things like `process.atomBinding`).
|
||||
const preloadProcess = new events.EventEmitter()
|
||||
|
@ -55,6 +53,11 @@ function preloadRequire (module) {
|
|||
throw new Error('module not found')
|
||||
}
|
||||
|
||||
if (window.location.protocol === 'chrome-devtools:') {
|
||||
// Override some inspector APIs.
|
||||
require('../renderer/inspector')
|
||||
}
|
||||
|
||||
// Wrap the script into a function executed in global scope. It won't have
|
||||
// access to the current scope, so we'll expose a few objects as arguments:
|
||||
//
|
||||
|
@ -74,13 +77,16 @@ function preloadRequire (module) {
|
|||
// and any `require('electron')` calls in `preload.js` will work as expected
|
||||
// since browserify won't try to include `electron` in the bundle, falling back
|
||||
// to the `preloadRequire` function above.
|
||||
const preloadWrapperSrc = `(function(require, process, Buffer, global, setImmediate) {
|
||||
${preloadSrc}
|
||||
})`
|
||||
if (preloadPath) {
|
||||
const preloadSrc = fs.readFileSync(preloadPath).toString()
|
||||
const preloadWrapperSrc = `(function(require, process, Buffer, global, setImmediate) {
|
||||
${preloadSrc}
|
||||
})`
|
||||
|
||||
// eval in window scope:
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.2
|
||||
const geval = eval
|
||||
const preloadFn = geval(preloadWrapperSrc)
|
||||
const {setImmediate} = require('timers')
|
||||
preloadFn(preloadRequire, preloadProcess, Buffer, global, setImmediate)
|
||||
// eval in window scope:
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.2
|
||||
const geval = eval
|
||||
const preloadFn = geval(preloadWrapperSrc)
|
||||
const {setImmediate} = require('timers')
|
||||
preloadFn(preloadRequire, preloadProcess, Buffer, global, setImmediate)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue