feat: expose dummy module.exports to the sandboxed preload scripts (#39484)
This commit is contained in:
parent
90865fa97d
commit
3102a257af
3 changed files with 5 additions and 3 deletions
|
@ -120,15 +120,16 @@ require('@electron/internal/renderer/common-init');
|
||||||
// - `Buffer`: Shim of `Buffer` implementation
|
// - `Buffer`: Shim of `Buffer` implementation
|
||||||
// - `global`: The window object, which is aliased to `global` by webpack.
|
// - `global`: The window object, which is aliased to `global` by webpack.
|
||||||
function runPreloadScript (preloadSrc: string) {
|
function runPreloadScript (preloadSrc: string) {
|
||||||
const preloadWrapperSrc = `(function(require, process, Buffer, global, setImmediate, clearImmediate, exports) {
|
const preloadWrapperSrc = `(function(require, process, Buffer, global, setImmediate, clearImmediate, exports, module) {
|
||||||
${preloadSrc}
|
${preloadSrc}
|
||||||
})`;
|
})`;
|
||||||
|
|
||||||
// eval in window scope
|
// eval in window scope
|
||||||
const preloadFn = binding.createPreloadScript(preloadWrapperSrc);
|
const preloadFn = binding.createPreloadScript(preloadWrapperSrc);
|
||||||
const { setImmediate, clearImmediate } = require('timers');
|
const { setImmediate, clearImmediate } = require('timers');
|
||||||
|
const exports = {};
|
||||||
|
|
||||||
preloadFn(preloadRequire, preloadProcess, Buffer, global, setImmediate, clearImmediate, {});
|
preloadFn(preloadRequire, preloadProcess, Buffer, global, setImmediate, clearImmediate, exports, { exports });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const { preloadPath, preloadSrc, preloadError } of preloadScripts) {
|
for (const { preloadPath, preloadSrc, preloadError } of preloadScripts) {
|
||||||
|
|
|
@ -1186,7 +1186,7 @@ describe('chromium features', () => {
|
||||||
w.webContents.executeJavaScript('window.child = window.open(); child.opener = null');
|
w.webContents.executeJavaScript('window.child = window.open(); child.opener = null');
|
||||||
const [, { webContents }] = await once(app, 'browser-window-created');
|
const [, { webContents }] = await once(app, 'browser-window-created');
|
||||||
const [,, message] = await once(webContents, 'console-message');
|
const [,, message] = await once(webContents, 'console-message');
|
||||||
expect(message).to.equal('{"require":"function","module":"undefined","process":"object","Buffer":"function"}');
|
expect(message).to.equal('{"require":"function","module":"object","exports":"object","process":"object","Buffer":"function"}');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('disables the <webview> tag when it is disabled on the parent window', async () => {
|
it('disables the <webview> tag when it is disabled on the parent window', async () => {
|
||||||
|
|
1
spec/fixtures/module/preload.js
vendored
1
spec/fixtures/module/preload.js
vendored
|
@ -1,6 +1,7 @@
|
||||||
const types = {
|
const types = {
|
||||||
require: typeof require,
|
require: typeof require,
|
||||||
module: typeof module,
|
module: typeof module,
|
||||||
|
exports: typeof exports,
|
||||||
process: typeof process,
|
process: typeof process,
|
||||||
Buffer: typeof Buffer
|
Buffer: typeof Buffer
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue