fix: regressions introduced by adding world isolation to Chrome extension content scripts (#17422)

This commit is contained in:
Milan Burda
2019-03-19 14:45:48 +01:00
committed by Alexey Kuzmin
parent 2fb9085e5b
commit 53f4af7722
6 changed files with 83 additions and 11 deletions

View File

@@ -7,9 +7,11 @@ const { EventEmitter } = require('events')
process.electronBinding = require('@electron/internal/common/atom-binding-setup').electronBindingSetup(nodeProcess.binding, 'renderer')
const v8Util = process.electronBinding('v8_util')
// The `lib/renderer/ipc-renderer-internal.js` module looks for the ipc object in the
// "ipc-internal" hidden value
v8Util.setHiddenValue(global, 'ipc-internal', new EventEmitter())
v8Util.setHiddenValue(global, 'ipc-internal', v8Util.getHiddenValue(isolatedWorld, 'ipc-internal'))
// The process object created by browserify is not an event emitter, fix it so
// the API is more compatible with non-sandboxed renderers.
for (const prop of Object.keys(EventEmitter.prototype)) {

View File

@@ -45,7 +45,7 @@ const runContentScript = function (this: any, extensionId: string, url: string,
})
const sources = [{ code, url }]
webFrame.executeJavaScriptInIsolatedWorld(worldId, sources)
return webFrame.executeJavaScriptInIsolatedWorld(worldId, sources)
}
const runAllContentScript = function (scripts: Array<Electron.InjectionBase>, extensionId: string) {
@@ -102,8 +102,9 @@ ipcRendererInternal.on('CHROME_TABS_EXECUTESCRIPT', function (
url: string,
code: string
) {
const result = runContentScript.call(window, extensionId, url, code)
ipcRendererInternal.sendToAll(senderWebContentsId, `CHROME_TABS_EXECUTESCRIPT_RESULT_${requestId}`, result)
runContentScript.call(window, extensionId, url, code).then(result => {
ipcRendererInternal.sendToAll(senderWebContentsId, `CHROME_TABS_EXECUTESCRIPT_RESULT_${requestId}`, result)
})
})
module.exports = (getRenderProcessPreferences: typeof process.getRenderProcessPreferences) => {