mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
Don't require browser process module from renderer
This can cause issues when it is accessed from the require cache or module tree since the getters throw errors when called.
This commit is contained in:
@@ -288,18 +288,6 @@ ipcRenderer.on('ELECTRON_RENDERER_RELEASE_CALLBACK', function (event, id) {
|
||||
callbacksRegistry.remove(id)
|
||||
})
|
||||
|
||||
// List all built-in modules in browser process.
|
||||
const browserModules = require('../../browser/api/exports/electron')
|
||||
|
||||
// And add a helper receiver for each one.
|
||||
for (let name of Object.getOwnPropertyNames(browserModules)) {
|
||||
Object.defineProperty(exports, name, {
|
||||
get: function () {
|
||||
return exports.getBuiltin(name)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Get remote module.
|
||||
exports.require = function (module) {
|
||||
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_REQUIRE', module))
|
||||
@@ -344,3 +332,40 @@ exports.getGuestWebContents = function (guestInstanceId) {
|
||||
const meta = ipcRenderer.sendSync('ELECTRON_BROWSER_GUEST_WEB_CONTENTS', guestInstanceId)
|
||||
return metaToValue(meta)
|
||||
}
|
||||
|
||||
const addBuiltinProperty = (name) => {
|
||||
Object.defineProperty(exports, name, {
|
||||
get: function () {
|
||||
return exports.getBuiltin(name)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Add each browser module name as a property
|
||||
// This list should match the exports in browser/api/exports/electron.js
|
||||
const browserModules = [
|
||||
'app',
|
||||
'autoUpdater',
|
||||
'BrowserWindow',
|
||||
'contentTracing',
|
||||
'dialog',
|
||||
'globalShortcut',
|
||||
'ipcMain',
|
||||
'Menu',
|
||||
'MenuItem',
|
||||
'net',
|
||||
'powerMonitor',
|
||||
'powerSaveBlocker',
|
||||
'protocol',
|
||||
'screen',
|
||||
'session',
|
||||
'systemPreferences',
|
||||
'Tray',
|
||||
'webContents'
|
||||
]
|
||||
browserModules.forEach(addBuiltinProperty)
|
||||
|
||||
// Add each common module name as a property
|
||||
const commonModules = {}
|
||||
require('../../common/api/exports/electron').defineProperties(commonModules)
|
||||
Object.getOwnPropertyNames(commonModules).forEach(addBuiltinProperty)
|
||||
|
||||
Reference in New Issue
Block a user