feat: enable context isolation by default (#26890)

* feat: enable context isolation by default

* chore: set default in ctx iso getter

* spec: make all specs work with the new contextIsolation default

* spec: fix affinity specs

* spec: update tests for new ctx iso default

* spec: update tests for new ctx iso default

* spec: update tests for new ctx iso default

* spec: update tests for new ctx iso default

* chore: move stray prod deps to dev deps

* spec: update tests for new ctx iso default

* turn off contextIsolation for visibility tests

* turn off contextIsolation for <webview> tag nodeintegration attribute loads native modules when navigation happens

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
Samuel Attard 2021-03-01 13:52:29 -08:00 committed by GitHub
parent 2d0ad0b96a
commit 186301e126
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 291 additions and 194 deletions

View file

@ -127,16 +127,7 @@ WebContentsPreferences::WebContentsPreferences(
SetDefaultBoolIfUndefined(options::kWebviewTag, false); SetDefaultBoolIfUndefined(options::kWebviewTag, false);
SetDefaultBoolIfUndefined(options::kSandbox, false); SetDefaultBoolIfUndefined(options::kSandbox, false);
SetDefaultBoolIfUndefined(options::kNativeWindowOpen, false); SetDefaultBoolIfUndefined(options::kNativeWindowOpen, false);
if (IsUndefined(options::kContextIsolation)) { SetDefaultBoolIfUndefined(options::kContextIsolation, true);
node::Environment* env = node::Environment::GetCurrent(isolate);
EmitWarning(env,
"The default of contextIsolation is deprecated and will be "
"changing from false to true in a future release of Electron. "
"See https://github.com/electron/electron/issues/23506 for "
"more information",
"electron");
}
SetDefaultBoolIfUndefined(options::kContextIsolation, false);
SetDefaultBoolIfUndefined(options::kWorldSafeExecuteJavaScript, true); SetDefaultBoolIfUndefined(options::kWorldSafeExecuteJavaScript, true);
SetDefaultBoolIfUndefined(options::kJavaScript, true); SetDefaultBoolIfUndefined(options::kJavaScript, true);
SetDefaultBoolIfUndefined(options::kImages, true); SetDefaultBoolIfUndefined(options::kImages, true);
@ -429,7 +420,7 @@ void WebContentsPreferences::OverrideWebkitPrefs(
prefs->opener_id = opener_id; prefs->opener_id = opener_id;
// Run Electron APIs and preload script in isolated world // Run Electron APIs and preload script in isolated world
prefs->context_isolation = IsEnabled(options::kContextIsolation); prefs->context_isolation = IsEnabled(options::kContextIsolation, true);
#if BUILDFLAG(ENABLE_REMOTE_MODULE) #if BUILDFLAG(ENABLE_REMOTE_MODULE)
// Whether to enable the remote module // Whether to enable the remote module

View file

@ -409,7 +409,8 @@ describe('app module', () => {
w = new BrowserWindow({ w = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
@ -426,7 +427,8 @@ describe('app module', () => {
w = new BrowserWindow({ w = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
@ -444,7 +446,8 @@ describe('app module', () => {
w = new BrowserWindow({ w = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
@ -463,7 +466,8 @@ describe('app module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
enableRemoteModule: true enableRemoteModule: true,
contextIsolation: false
} }
}); });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
@ -481,7 +485,8 @@ describe('app module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
enableRemoteModule: true enableRemoteModule: true,
contextIsolation: false
} }
}); });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
@ -499,7 +504,8 @@ describe('app module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
enableRemoteModule: true enableRemoteModule: true,
contextIsolation: false
} }
}); });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
@ -517,7 +523,8 @@ describe('app module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
enableRemoteModule: true enableRemoteModule: true,
contextIsolation: false
} }
}); });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
@ -534,7 +541,8 @@ describe('app module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
enableRemoteModule: true enableRemoteModule: true,
contextIsolation: false
} }
}); });
await w.loadURL('about:blank'); await w.loadURL('about:blank');

View file

@ -3,6 +3,7 @@ import * as path from 'path';
import { ipcMain, BrowserWindow, WebPreferences, app } from 'electron/main'; import { ipcMain, BrowserWindow, WebPreferences, app } from 'electron/main';
import { closeWindow } from './window-helpers'; import { closeWindow } from './window-helpers';
import { emittedOnce } from './events-helpers';
describe('BrowserWindow with affinity module', () => { describe('BrowserWindow with affinity module', () => {
const fixtures = path.resolve(__dirname, '..', 'spec', 'fixtures'); const fixtures = path.resolve(__dirname, '..', 'spec', 'fixtures');
@ -88,19 +89,15 @@ describe('BrowserWindow with affinity module', () => {
const affinityWithNodeTrue = 'affinityWithNodeTrue'; const affinityWithNodeTrue = 'affinityWithNodeTrue';
const affinityWithNodeFalse = 'affinityWithNodeFalse'; const affinityWithNodeFalse = 'affinityWithNodeFalse';
function testNodeIntegration (present: boolean) { async function testNodeIntegration (present: boolean) {
return new Promise<void>((resolve) => { const [, typeofProcess, typeofBuffer] = await emittedOnce(ipcMain, 'answer');
ipcMain.once('answer', (event, typeofProcess, typeofBuffer) => { if (present) {
if (present) { expect(typeofProcess).to.not.equal('undefined');
expect(typeofProcess).to.not.equal('undefined'); expect(typeofBuffer).to.not.equal('undefined');
expect(typeofBuffer).to.not.equal('undefined'); } else {
} else { expect(typeofProcess).to.equal('undefined');
expect(typeofProcess).to.equal('undefined'); expect(typeofBuffer).to.equal('undefined');
expect(typeofBuffer).to.equal('undefined'); }
}
resolve();
});
});
} }
it('disables node integration when specified to false', async () => { it('disables node integration when specified to false', async () => {
@ -109,7 +106,8 @@ describe('BrowserWindow with affinity module', () => {
createWindowWithWebPrefs({ createWindowWithWebPrefs({
affinity: affinityWithNodeTrue, affinity: affinityWithNodeTrue,
preload, preload,
nodeIntegration: false nodeIntegration: false,
contextIsolation: false
}) })
]); ]);
await closeWindow(w, { assertNotWindows: false }); await closeWindow(w, { assertNotWindows: false });
@ -120,7 +118,8 @@ describe('BrowserWindow with affinity module', () => {
createWindowWithWebPrefs({ createWindowWithWebPrefs({
affinity: affinityWithNodeTrue, affinity: affinityWithNodeTrue,
preload, preload,
nodeIntegration: false nodeIntegration: false,
contextIsolation: false
}) })
]); ]);
const [, w2] = await Promise.all([ const [, w2] = await Promise.all([
@ -128,7 +127,8 @@ describe('BrowserWindow with affinity module', () => {
createWindowWithWebPrefs({ createWindowWithWebPrefs({
affinity: affinityWithNodeTrue, affinity: affinityWithNodeTrue,
preload, preload,
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
}) })
]); ]);
await Promise.all([ await Promise.all([
@ -143,7 +143,8 @@ describe('BrowserWindow with affinity module', () => {
createWindowWithWebPrefs({ createWindowWithWebPrefs({
affinity: affinityWithNodeFalse, affinity: affinityWithNodeFalse,
preload, preload,
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
}) })
]); ]);
await closeWindow(w, { assertNotWindows: false }); await closeWindow(w, { assertNotWindows: false });
@ -155,7 +156,8 @@ describe('BrowserWindow with affinity module', () => {
createWindowWithWebPrefs({ createWindowWithWebPrefs({
affinity: affinityWithNodeFalse, affinity: affinityWithNodeFalse,
preload, preload,
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
}) })
]); ]);
const [, w2] = await Promise.all([ const [, w2] = await Promise.all([
@ -163,7 +165,8 @@ describe('BrowserWindow with affinity module', () => {
createWindowWithWebPrefs({ createWindowWithWebPrefs({
affinity: affinityWithNodeFalse, affinity: affinityWithNodeFalse,
preload, preload,
nodeIntegration: false nodeIntegration: false,
contextIsolation: false
}) })
]); ]);
await Promise.all([ await Promise.all([

View file

@ -95,7 +95,7 @@ describe('BrowserWindow module', () => {
describe('BrowserWindow.close()', () => { describe('BrowserWindow.close()', () => {
let w = null as unknown as BrowserWindow; let w = null as unknown as BrowserWindow;
beforeEach(() => { beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
}); });
afterEach(async () => { afterEach(async () => {
await closeWindow(w); await closeWindow(w);
@ -190,7 +190,7 @@ describe('BrowserWindow module', () => {
describe('window.close()', () => { describe('window.close()', () => {
let w = null as unknown as BrowserWindow; let w = null as unknown as BrowserWindow;
beforeEach(() => { beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
}); });
afterEach(async () => { afterEach(async () => {
await closeWindow(w); await closeWindow(w);
@ -445,11 +445,9 @@ describe('BrowserWindow module', () => {
}); });
}); });
it('should support support base url for data urls', async () => { it('should support base url for data urls', async () => {
const answer = emittedOnce(ipcMain, 'answer'); await w.loadURL('data:text/html,<script src="loaded-from-dataurl.js"></script>', { baseURLForDataURL: `other://${path.join(fixtures, 'api')}${path.sep}` });
w.loadURL('data:text/html,<script src="loaded-from-dataurl.js"></script>', { baseURLForDataURL: `other://${path.join(fixtures, 'api')}${path.sep}` }); expect(await w.webContents.executeJavaScript('window.ping')).to.equal('pong');
const [, test] = await answer;
expect(test).to.equal('test');
}); });
}); });
@ -2009,6 +2007,7 @@ describe('BrowserWindow module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
contextIsolation: false,
preload preload
} }
}); });
@ -2023,6 +2022,7 @@ describe('BrowserWindow module', () => {
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
enableRemoteModule: true, enableRemoteModule: true,
contextIsolation: false,
preload preload
} }
}); });
@ -2036,6 +2036,7 @@ describe('BrowserWindow module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
contextIsolation: false,
preload preload
} }
}); });
@ -2075,7 +2076,8 @@ describe('BrowserWindow module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
sandbox, sandbox,
preload: path.join(fixtures, 'module', 'get-global-preload.js') preload: path.join(fixtures, 'module', 'get-global-preload.js'),
contextIsolation: false
} }
}); });
w.loadURL('about:blank'); w.loadURL('about:blank');
@ -2129,7 +2131,8 @@ describe('BrowserWindow module', () => {
const w = new BrowserWindow({ const w = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
preload preload,
contextIsolation: false
} }
}); });
w.loadFile(path.join(fixtures, 'api', 'blank.html')); w.loadFile(path.join(fixtures, 'api', 'blank.html'));
@ -2224,7 +2227,8 @@ describe('BrowserWindow module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
sandbox: true, sandbox: true,
preload preload,
contextIsolation: false
} }
}); });
w.loadFile(path.join(fixtures, 'api', 'preload.html')); w.loadFile(path.join(fixtures, 'api', 'preload.html'));
@ -2238,7 +2242,8 @@ describe('BrowserWindow module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
sandbox: true, sandbox: true,
preload: preloadSpecialChars preload: preloadSpecialChars,
contextIsolation: false
} }
}); });
w.loadFile(path.join(fixtures, 'api', 'preload.html')); w.loadFile(path.join(fixtures, 'api', 'preload.html'));
@ -2263,7 +2268,8 @@ describe('BrowserWindow module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
sandbox: true, sandbox: true,
preload preload,
contextIsolation: false
} }
}); });
const htmlPath = path.join(__dirname, 'fixtures', 'api', 'sandbox.html?exit-event'); const htmlPath = path.join(__dirname, 'fixtures', 'api', 'sandbox.html?exit-event');
@ -2281,7 +2287,8 @@ describe('BrowserWindow module', () => {
show: true, show: true,
webPreferences: { webPreferences: {
sandbox: true, sandbox: true,
preload preload,
contextIsolation: false
} }
}); });
@ -2315,7 +2322,8 @@ describe('BrowserWindow module', () => {
show: true, show: true,
webPreferences: { webPreferences: {
sandbox: true, sandbox: true,
preload preload,
contextIsolation: false
} }
}); });
@ -2413,7 +2421,8 @@ describe('BrowserWindow module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
sandbox: true, sandbox: true,
preload preload,
contextIsolation: false
} }
}); });
let childWc: WebContents | null = null; let childWc: WebContents | null = null;
@ -2510,7 +2519,8 @@ describe('BrowserWindow module', () => {
webPreferences: { webPreferences: {
preload, preload,
sandbox: true, sandbox: true,
enableRemoteModule: true enableRemoteModule: true,
contextIsolation: false
} }
}); });
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'sandbox.html'), { search: 'reload-remote' }); w.loadFile(path.join(__dirname, 'fixtures', 'api', 'sandbox.html'), { search: 'reload-remote' });
@ -2547,7 +2557,8 @@ describe('BrowserWindow module', () => {
webPreferences: { webPreferences: {
preload, preload,
sandbox: true, sandbox: true,
enableRemoteModule: true enableRemoteModule: true,
contextIsolation: false
} }
}); });
w.webContents.setWindowOpenHandler(() => ({ action: 'allow', overrideBrowserWindowOptions: { webPreferences: { preload } } })); w.webContents.setWindowOpenHandler(() => ({ action: 'allow', overrideBrowserWindowOptions: { webPreferences: { preload } } }));
@ -2585,7 +2596,8 @@ describe('BrowserWindow module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
sandbox: true, sandbox: true,
preload preload,
contextIsolation: false
} }
}); });
w.webContents.once('preload-error', (event, preloadPath, error) => { w.webContents.once('preload-error', (event, preloadPath, error) => {
@ -2627,7 +2639,8 @@ describe('BrowserWindow module', () => {
webPreferences: { webPreferences: {
sandbox: true, sandbox: true,
preload, preload,
webviewTag: true webviewTag: true,
contextIsolation: false
} }
}); });
const didAttachWebview = emittedOnce(w.webContents, 'did-attach-webview'); const didAttachWebview = emittedOnce(w.webContents, 'did-attach-webview');
@ -2650,7 +2663,8 @@ describe('BrowserWindow module', () => {
nodeIntegration: true, nodeIntegration: true,
nativeWindowOpen: true, nativeWindowOpen: true,
// tests relies on preloads in opened windows // tests relies on preloads in opened windows
nodeIntegrationInSubFrames: true nodeIntegrationInSubFrames: true,
contextIsolation: false
} }
}); });
}); });
@ -2700,6 +2714,7 @@ describe('BrowserWindow module', () => {
nodeIntegrationInSubFrames: true, nodeIntegrationInSubFrames: true,
nativeWindowOpen: true, nativeWindowOpen: true,
webviewTag: true, webviewTag: true,
contextIsolation: false,
preload preload
} }
}); });
@ -2772,7 +2787,8 @@ describe('BrowserWindow module', () => {
webPreferences: { webPreferences: {
nativeWindowOpen: true, nativeWindowOpen: true,
// test relies on preloads in opened window // test relies on preloads in opened window
nodeIntegrationInSubFrames: true nodeIntegrationInSubFrames: true,
contextIsolation: false
} }
}); });
@ -2959,7 +2975,8 @@ describe('BrowserWindow module', () => {
width: 100, width: 100,
height: 100, height: 100,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
@ -2983,7 +3000,8 @@ describe('BrowserWindow module', () => {
width: 100, width: 100,
height: 100, height: 100,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
@ -3010,7 +3028,8 @@ describe('BrowserWindow module', () => {
width: 100, width: 100,
height: 100, height: 100,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
@ -3030,7 +3049,8 @@ describe('BrowserWindow module', () => {
width: 100, width: 100,
height: 100, height: 100,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
w.loadFile(path.join(fixtures, 'pages', 'visibilitychange.html')); w.loadFile(path.join(fixtures, 'pages', 'visibilitychange.html'));
@ -3050,7 +3070,8 @@ describe('BrowserWindow module', () => {
width: 100, width: 100,
height: 100, height: 100,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
w.loadFile(path.join(fixtures, 'pages', 'visibilitychange.html')); w.loadFile(path.join(fixtures, 'pages', 'visibilitychange.html'));
@ -4423,7 +4444,8 @@ describe('BrowserWindow module', () => {
const w = new BrowserWindow({ const w = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });

View file

@ -239,7 +239,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
remotely(() => { remotely(() => {
const { BrowserWindow } = require('electron'); const { BrowserWindow } = require('electron');
const bw = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const bw = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
bw.loadURL('about:blank'); bw.loadURL('about:blank');
bw.webContents.executeJavaScript('process._linkedBinding(\'electron_common_v8_util\').triggerFatalErrorForTesting()'); bw.webContents.executeJavaScript('process._linkedBinding(\'electron_common_v8_util\').triggerFatalErrorForTesting()');
}); });
@ -409,7 +409,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
// 2. generate a crash in the renderer. // 2. generate a crash in the renderer.
remotely(() => { remotely(() => {
const { BrowserWindow } = require('electron'); const { BrowserWindow } = require('electron');
const bw = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const bw = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
bw.loadURL('about:blank'); bw.loadURL('about:blank');
bw.webContents.executeJavaScript('process.crash()'); bw.webContents.executeJavaScript('process.crash()');
}); });
@ -485,7 +485,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
const rendererParameters = await remotely(async () => { const rendererParameters = await remotely(async () => {
const { crashReporter, BrowserWindow } = require('electron'); const { crashReporter, BrowserWindow } = require('electron');
crashReporter.start({ submitURL: 'http://' }); crashReporter.start({ submitURL: 'http://' });
const bw = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const bw = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
bw.loadURL('about:blank'); bw.loadURL('about:blank');
await bw.webContents.executeJavaScript('require(\'electron\').crashReporter.addExtraParameter(\'hello\', \'world\')'); await bw.webContents.executeJavaScript('require(\'electron\').crashReporter.addExtraParameter(\'hello\', \'world\')');
return bw.webContents.executeJavaScript('require(\'electron\').crashReporter.getParameters()'); return bw.webContents.executeJavaScript('require(\'electron\').crashReporter.getParameters()');
@ -531,7 +531,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
} else if (processType === 'renderer') { } else if (processType === 'renderer') {
return remotely(() => { return remotely(() => {
const { BrowserWindow } = require('electron'); const { BrowserWindow } = require('electron');
const bw = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const bw = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
bw.loadURL('about:blank'); bw.loadURL('about:blank');
bw.webContents.executeJavaScript('process.crash()'); bw.webContents.executeJavaScript('process.crash()');
}); });
@ -539,7 +539,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
const preloadPath = path.join(__dirname, 'fixtures', 'apps', 'crash', 'sandbox-preload.js'); const preloadPath = path.join(__dirname, 'fixtures', 'apps', 'crash', 'sandbox-preload.js');
return remotely((preload: string) => { return remotely((preload: string) => {
const { BrowserWindow } = require('electron'); const { BrowserWindow } = require('electron');
const bw = new BrowserWindow({ show: false, webPreferences: { sandbox: true, preload } }); const bw = new BrowserWindow({ show: false, webPreferences: { sandbox: true, preload, contextIsolation: false } });
bw.loadURL('about:blank'); bw.loadURL('about:blank');
}, preloadPath); }, preloadPath);
} else if (processType === 'node') { } else if (processType === 'node') {

View file

@ -17,7 +17,7 @@ ifdescribe(!process.arch.includes('arm') && process.platform !== 'win32')('deskt
let w: BrowserWindow; let w: BrowserWindow;
before(async () => { before(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
}); });
@ -96,7 +96,7 @@ ifdescribe(!process.arch.includes('arm') && process.platform !== 'win32')('deskt
}); });
it('disabling thumbnail should return empty images', async () => { it('disabling thumbnail should return empty images', async () => {
const w2 = new BrowserWindow({ show: false, width: 200, height: 200 }); const w2 = new BrowserWindow({ show: false, width: 200, height: 200, webPreferences: { contextIsolation: false } });
const wShown = emittedOnce(w2, 'show'); const wShown = emittedOnce(w2, 'show');
w2.show(); w2.show();
await wShown; await wShown;
@ -116,7 +116,7 @@ ifdescribe(!process.arch.includes('arm') && process.platform !== 'win32')('deskt
}); });
it('getMediaSourceId should match DesktopCapturerSource.id', async () => { it('getMediaSourceId should match DesktopCapturerSource.id', async () => {
const w = new BrowserWindow({ show: false, width: 100, height: 100 }); const w = new BrowserWindow({ show: false, width: 100, height: 100, webPreferences: { contextIsolation: false } });
const wShown = emittedOnce(w, 'show'); const wShown = emittedOnce(w, 'show');
const wFocused = emittedOnce(w, 'focus'); const wFocused = emittedOnce(w, 'focus');
w.show(); w.show();

View file

@ -18,7 +18,8 @@ describe('ipc main module', () => {
const w = new BrowserWindow({ const w = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
ipcMain.once('send-sync-message', (event) => { ipcMain.once('send-sync-message', (event) => {
@ -32,7 +33,8 @@ describe('ipc main module', () => {
const w = new BrowserWindow({ const w = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
ipcMain.on('send-sync-message', (event) => { ipcMain.on('send-sync-message', (event) => {
@ -72,7 +74,8 @@ describe('ipc main module', () => {
const w = new BrowserWindow({ const w = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
w.loadURL('about:blank'); w.loadURL('about:blank');

View file

@ -9,7 +9,7 @@ describe('ipcRenderer module', () => {
let w: BrowserWindow; let w: BrowserWindow;
before(async () => { before(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, nativeWindowOpen: true } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, nativeWindowOpen: true, contextIsolation: false } });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
}); });
after(async () => { after(async () => {

View file

@ -11,7 +11,7 @@ describe('ipc module', () => {
let w = (null as unknown as BrowserWindow); let w = (null as unknown as BrowserWindow);
before(async () => { before(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
}); });
after(async () => { after(async () => {
@ -125,7 +125,7 @@ describe('ipc module', () => {
let w = (null as unknown as BrowserWindow); let w = (null as unknown as BrowserWindow);
before(async () => { before(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
}); });
after(async () => { after(async () => {
@ -202,7 +202,7 @@ describe('ipc module', () => {
afterEach(closeAllWindows); afterEach(closeAllWindows);
it('can send a port to the main process', async () => { it('can send a port to the main process', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank'); w.loadURL('about:blank');
const p = emittedOnce(ipcMain, 'port'); const p = emittedOnce(ipcMain, 'port');
await w.webContents.executeJavaScript(`(${function () { await w.webContents.executeJavaScript(`(${function () {
@ -217,7 +217,7 @@ describe('ipc module', () => {
}); });
it('can communicate between main and renderer', async () => { it('can communicate between main and renderer', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank'); w.loadURL('about:blank');
const p = emittedOnce(ipcMain, 'port'); const p = emittedOnce(ipcMain, 'port');
await w.webContents.executeJavaScript(`(${function () { await w.webContents.executeJavaScript(`(${function () {
@ -237,7 +237,7 @@ describe('ipc module', () => {
}); });
it('can receive a port from a renderer over a MessagePort connection', async () => { it('can receive a port from a renderer over a MessagePort connection', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank'); w.loadURL('about:blank');
function fn () { function fn () {
const channel1 = new MessageChannel(); const channel1 = new MessageChannel();
@ -256,8 +256,8 @@ describe('ipc module', () => {
}); });
it('can forward a port from one renderer to another renderer', async () => { it('can forward a port from one renderer to another renderer', async () => {
const w1 = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w1 = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
const w2 = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w2 = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w1.loadURL('about:blank'); w1.loadURL('about:blank');
w2.loadURL('about:blank'); w2.loadURL('about:blank');
w1.webContents.executeJavaScript(`(${function () { w1.webContents.executeJavaScript(`(${function () {
@ -281,7 +281,7 @@ describe('ipc module', () => {
describe('close event', () => { describe('close event', () => {
describe('in renderer', () => { describe('in renderer', () => {
it('is emitted when the main process closes its end of the port', async () => { it('is emitted when the main process closes its end of the port', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank'); w.loadURL('about:blank');
await w.webContents.executeJavaScript(`(${function () { await w.webContents.executeJavaScript(`(${function () {
const { ipcRenderer } = require('electron'); const { ipcRenderer } = require('electron');
@ -300,7 +300,7 @@ describe('ipc module', () => {
}); });
it('is emitted when the other end of a port is garbage-collected', async () => { it('is emitted when the other end of a port is garbage-collected', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank'); w.loadURL('about:blank');
await w.webContents.executeJavaScript(`(${async function () { await w.webContents.executeJavaScript(`(${async function () {
const { port2 } = new MessageChannel(); const { port2 } = new MessageChannel();
@ -313,7 +313,7 @@ describe('ipc module', () => {
}); });
it('is emitted when the other end of a port is sent to nowhere', async () => { it('is emitted when the other end of a port is sent to nowhere', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank'); w.loadURL('about:blank');
ipcMain.once('do-a-gc', () => v8Util.requestGarbageCollectionForTesting()); ipcMain.once('do-a-gc', () => v8Util.requestGarbageCollectionForTesting());
await w.webContents.executeJavaScript(`(${async function () { await w.webContents.executeJavaScript(`(${async function () {
@ -345,7 +345,7 @@ describe('ipc module', () => {
}); });
it('can pass one end to a WebContents', async () => { it('can pass one end to a WebContents', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank'); w.loadURL('about:blank');
await w.webContents.executeJavaScript(`(${function () { await w.webContents.executeJavaScript(`(${function () {
const { ipcRenderer } = require('electron'); const { ipcRenderer } = require('electron');
@ -363,7 +363,7 @@ describe('ipc module', () => {
}); });
it('can be passed over another channel', async () => { it('can be passed over another channel', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank'); w.loadURL('about:blank');
await w.webContents.executeJavaScript(`(${function () { await w.webContents.executeJavaScript(`(${function () {
const { ipcRenderer } = require('electron'); const { ipcRenderer } = require('electron');
@ -452,7 +452,7 @@ describe('ipc module', () => {
const generateTests = (title: string, postMessage: (contents: WebContents) => typeof WebContents.prototype.postMessage) => { const generateTests = (title: string, postMessage: (contents: WebContents) => typeof WebContents.prototype.postMessage) => {
describe(title, () => { describe(title, () => {
it('sends a message', async () => { it('sends a message', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank'); w.loadURL('about:blank');
await w.webContents.executeJavaScript(`(${function () { await w.webContents.executeJavaScript(`(${function () {
const { ipcRenderer } = require('electron'); const { ipcRenderer } = require('electron');

View file

@ -987,7 +987,7 @@ describe('protocol module', () => {
await registerStreamProtocol(standardScheme, protocolHandler); await registerStreamProtocol(standardScheme, protocolHandler);
await registerStreamProtocol('stream', protocolHandler); await registerStreamProtocol('stream', protocolHandler);
const newContents: WebContents = (webContents as any).create({ nodeIntegration: true }); const newContents: WebContents = (webContents as any).create({ nodeIntegration: true, contextIsolation: false });
try { try {
newContents.loadURL(testingScheme + '://fake-host'); newContents.loadURL(testingScheme + '://fake-host');
const [, response] = await emittedOnce(ipcMain, 'result'); const [, response] = await emittedOnce(ipcMain, 'result');

View file

@ -49,7 +49,7 @@ function makeRemotely (windowGetter: () => BrowserWindow) {
function makeWindow () { function makeWindow () {
let w: BrowserWindow; let w: BrowserWindow;
before(async () => { before(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, enableRemoteModule: true } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, enableRemoteModule: true, contextIsolation: false } });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
await w.webContents.executeJavaScript(`{ await w.webContents.executeJavaScript(`{
const chai_1 = window.chai_1 = require('chai') const chai_1 = window.chai_1 = require('chai')
@ -65,7 +65,7 @@ function makeWindow () {
function makeEachWindow () { function makeEachWindow () {
let w: BrowserWindow; let w: BrowserWindow;
beforeEach(async () => { beforeEach(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, enableRemoteModule: true } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, enableRemoteModule: true, contextIsolation: false } });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
await w.webContents.executeJavaScript(`{ await w.webContents.executeJavaScript(`{
const chai_1 = window.chai_1 = require('chai') const chai_1 = window.chai_1 = require('chai')
@ -333,7 +333,8 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
preload, preload,
enableRemoteModule: true enableRemoteModule: true,
contextIsolation: false
} }
}); });
w.loadURL('about:blank'); w.loadURL('about:blank');
@ -347,7 +348,8 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
enableRemoteModule: true enableRemoteModule: true,
contextIsolation: false
} }
}); });
@ -434,7 +436,8 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
enableRemoteModule: true enableRemoteModule: true,
contextIsolation: false
} }
}); });
await w.loadFile(path.join(fixtures, 'remote-event-handler.html')); await w.loadFile(path.join(fixtures, 'remote-event-handler.html'));

View file

@ -328,7 +328,8 @@ describe('session module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
partition: partitionName, partition: partitionName,
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
customSession = session.fromPartition(partitionName); customSession = session.fromPartition(partitionName);
@ -999,7 +1000,8 @@ describe('session module', () => {
show: false, show: false,
webPreferences: { webPreferences: {
partition: 'very-temp-permision-handler', partition: 'very-temp-permision-handler',
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });

View file

@ -121,7 +121,7 @@ describe('renderer nodeIntegrationInSubFrames', () => {
const senders = details.map(event => event[0].sender); const senders = details.map(event => event[0].sender);
const isolatedGlobals = await Promise.all(senders.map(sender => sender.executeJavaScript('window.isolatedGlobal'))); const isolatedGlobals = await Promise.all(senders.map(sender => sender.executeJavaScript('window.isolatedGlobal')));
for (const result of isolatedGlobals) { for (const result of isolatedGlobals) {
if (webPreferences.contextIsolation) { if (webPreferences.contextIsolation === undefined || webPreferences.contextIsolation) {
expect(result).to.be.undefined(); expect(result).to.be.undefined();
} else { } else {
expect(result).to.equal(true); expect(result).to.equal(true);
@ -167,8 +167,8 @@ describe('renderer nodeIntegrationInSubFrames', () => {
webPreferences: { sandbox: true } webPreferences: { sandbox: true }
}, },
{ {
name: 'context isolation', name: 'context isolation disabled',
webPreferences: { contextIsolation: true } webPreferences: { contextIsolation: false }
}, },
{ {
name: 'webview', name: 'webview',
@ -190,7 +190,8 @@ describe('renderer nodeIntegrationInSubFrames', () => {
webPreferences: { webPreferences: {
preload: path.resolve(__dirname, 'fixtures/sub-frames/webview-iframe-preload.js'), preload: path.resolve(__dirname, 'fixtures/sub-frames/webview-iframe-preload.js'),
nodeIntegrationInSubFrames: true, nodeIntegrationInSubFrames: true,
webviewTag: true webviewTag: true,
contextIsolation: false
} }
}); });
}); });

View file

@ -194,7 +194,7 @@ describe('webContents module', () => {
let w: BrowserWindow; let w: BrowserWindow;
before(async () => { before(async () => {
w = new BrowserWindow({ show: false }); w = new BrowserWindow({ show: false, webPreferences: { contextIsolation: false } });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
}); });
after(closeAllWindows); after(closeAllWindows);
@ -516,7 +516,7 @@ describe('webContents module', () => {
describe('before-input-event event', () => { describe('before-input-event event', () => {
afterEach(closeAllWindows); afterEach(closeAllWindows);
it('can prevent document keyboard events', async () => { it('can prevent document keyboard events', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
await w.loadFile(path.join(fixturesPath, 'pages', 'key-events.html')); await w.loadFile(path.join(fixturesPath, 'pages', 'key-events.html'));
const keyDown = new Promise(resolve => { const keyDown = new Promise(resolve => {
ipcMain.once('keydown', (event, key) => resolve(key)); ipcMain.once('keydown', (event, key) => resolve(key));
@ -657,7 +657,7 @@ describe('webContents module', () => {
describe('sendInputEvent(event)', () => { describe('sendInputEvent(event)', () => {
let w: BrowserWindow; let w: BrowserWindow;
beforeEach(async () => { beforeEach(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
await w.loadFile(path.join(fixturesPath, 'pages', 'key-events.html')); await w.loadFile(path.join(fixturesPath, 'pages', 'key-events.html'));
}); });
afterEach(closeAllWindows); afterEach(closeAllWindows);
@ -950,7 +950,7 @@ describe('webContents module', () => {
}); });
it('can persist zoom level across navigation', (done) => { it('can persist zoom level across navigation', (done) => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
let finalNavigation = false; let finalNavigation = false;
ipcMain.on('set-zoom', (e, host) => { ipcMain.on('set-zoom', (e, host) => {
const zoomLevel = hostZoomMap[host]; const zoomLevel = hostZoomMap[host];
@ -1070,7 +1070,7 @@ describe('webContents module', () => {
}); });
it('cannot propagate when used with webframe', async () => { it('cannot propagate when used with webframe', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
const w2 = new BrowserWindow({ show: false }); const w2 = new BrowserWindow({ show: false });
const temporaryZoomSet = emittedOnce(ipcMain, 'temporary-zoom-set'); const temporaryZoomSet = emittedOnce(ipcMain, 'temporary-zoom-set');
@ -1111,7 +1111,7 @@ describe('webContents module', () => {
}); });
it('cannot persist zoom level after navigation with webFrame', async () => { it('cannot persist zoom level after navigation with webFrame', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
const source = ` const source = `
const {ipcRenderer, webFrame} = require('electron') const {ipcRenderer, webFrame} = require('electron')
webFrame.setZoomLevel(0.6) webFrame.setZoomLevel(0.6)
@ -1423,7 +1423,7 @@ describe('webContents module', () => {
describe('ipc-message event', () => { describe('ipc-message event', () => {
afterEach(closeAllWindows); afterEach(closeAllWindows);
it('emits when the renderer process sends an asynchronous message', async () => { it('emits when the renderer process sends an asynchronous message', async () => {
const w = new BrowserWindow({ show: true, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: true, webPreferences: { nodeIntegration: true, contextIsolation: false } });
await w.webContents.loadURL('about:blank'); await w.webContents.loadURL('about:blank');
w.webContents.executeJavaScript(` w.webContents.executeJavaScript(`
require('electron').ipcRenderer.send('message', 'Hello World!') require('electron').ipcRenderer.send('message', 'Hello World!')
@ -1438,7 +1438,7 @@ describe('webContents module', () => {
describe('ipc-message-sync event', () => { describe('ipc-message-sync event', () => {
afterEach(closeAllWindows); afterEach(closeAllWindows);
it('emits when the renderer process sends a synchronous message', async () => { it('emits when the renderer process sends a synchronous message', async () => {
const w = new BrowserWindow({ show: true, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: true, webPreferences: { nodeIntegration: true, contextIsolation: false } });
await w.webContents.loadURL('about:blank'); await w.webContents.loadURL('about:blank');
const promise: Promise<[string, string]> = new Promise(resolve => { const promise: Promise<[string, string]> = new Promise(resolve => {
w.webContents.once('ipc-message-sync', (event, channel, arg) => { w.webContents.once('ipc-message-sync', (event, channel, arg) => {
@ -1865,7 +1865,7 @@ describe('webContents module', () => {
afterEach(closeAllWindows); afterEach(closeAllWindows);
it('can get multiple shared workers', async () => { it('can get multiple shared workers', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
const ready = emittedOnce(ipcMain, 'ready'); const ready = emittedOnce(ipcMain, 'ready');
w.loadFile(path.join(fixturesPath, 'api', 'shared-worker', 'shared-worker.html')); w.loadFile(path.join(fixturesPath, 'api', 'shared-worker', 'shared-worker.html'));
@ -1879,7 +1879,7 @@ describe('webContents module', () => {
}); });
it('can inspect a specific shared worker', async () => { it('can inspect a specific shared worker', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
const ready = emittedOnce(ipcMain, 'ready'); const ready = emittedOnce(ipcMain, 'ready');
w.loadFile(path.join(fixturesPath, 'api', 'shared-worker', 'shared-worker.html')); w.loadFile(path.join(fixturesPath, 'api', 'shared-worker', 'shared-worker.html'));

View file

@ -48,7 +48,8 @@ describe('webFrame module', () => {
const w = new BrowserWindow({ const w = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
await w.loadFile(path.join(fixtures, 'pages', 'webframe-spell-check.html')); await w.loadFile(path.join(fixtures, 'pages', 'webframe-spell-check.html'));

View file

@ -495,7 +495,8 @@ describe('webRequest module', () => {
const contents = (webContents as any).create({ const contents = (webContents as any).create({
session: ses, session: ses,
nodeIntegration: true, nodeIntegration: true,
webSecurity: false webSecurity: false,
contextIsolation: false
}); });
// Cleanup. // Cleanup.

View file

@ -21,7 +21,8 @@ describe('asar package', () => {
width: 400, width: 400,
height: 400, height: 400,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
const p = path.resolve(asarDir, 'web.asar', 'index.html'); const p = path.resolve(asarDir, 'web.asar', 'index.html');
@ -41,7 +42,8 @@ describe('asar package', () => {
width: 400, width: 400,
height: 400, height: 400,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
const p = path.resolve(asarDir, 'script.asar', 'index.html'); const p = path.resolve(asarDir, 'script.asar', 'index.html');
@ -63,7 +65,8 @@ describe('asar package', () => {
width: 400, width: 400,
height: 400, height: 400,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
const p = path.resolve(asarDir, 'video.asar', 'index.html'); const p = path.resolve(asarDir, 'video.asar', 'index.html');

View file

@ -89,7 +89,7 @@ describe('window.postMessage', () => {
for (const nativeWindowOpen of [true, false]) { for (const nativeWindowOpen of [true, false]) {
describe(`when nativeWindowOpen: ${nativeWindowOpen}`, () => { describe(`when nativeWindowOpen: ${nativeWindowOpen}`, () => {
it('sets the source and origin correctly', async () => { it('sets the source and origin correctly', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, nativeWindowOpen } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, nativeWindowOpen, contextIsolation: false } });
w.loadURL(`file://${fixturesPath}/pages/window-open-postMessage-driver.html`); w.loadURL(`file://${fixturesPath}/pages/window-open-postMessage-driver.html`);
const [, message] = await emittedOnce(ipcMain, 'complete'); const [, message] = await emittedOnce(ipcMain, 'complete');
expect(message.data).to.equal('testing'); expect(message.data).to.equal('testing');
@ -110,7 +110,8 @@ describe('focus handling', () => {
show: true, show: true,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
webviewTag: true webviewTag: true,
contextIsolation: false
} }
}); });
@ -230,7 +231,7 @@ describe('web security', () => {
}); });
it('engages CORB when web security is not disabled', async () => { it('engages CORB when web security is not disabled', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: true, nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: true, nodeIntegration: true, contextIsolation: false } });
const p = emittedOnce(ipcMain, 'success'); const p = emittedOnce(ipcMain, 'success');
await w.loadURL(`data:text/html,<script> await w.loadURL(`data:text/html,<script>
const s = document.createElement('script') const s = document.createElement('script')
@ -244,7 +245,7 @@ describe('web security', () => {
}); });
it('bypasses CORB when web security is disabled', async () => { it('bypasses CORB when web security is disabled', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: false, nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: false, nodeIntegration: true, contextIsolation: false } });
const p = emittedOnce(ipcMain, 'success'); const p = emittedOnce(ipcMain, 'success');
await w.loadURL(`data:text/html, await w.loadURL(`data:text/html,
<script> <script>
@ -255,7 +256,7 @@ describe('web security', () => {
}); });
it('engages CORS when web security is not disabled', async () => { it('engages CORS when web security is not disabled', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: true, nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: true, nodeIntegration: true, contextIsolation: false } });
const p = emittedOnce(ipcMain, 'response'); const p = emittedOnce(ipcMain, 'response');
await w.loadURL(`data:text/html,<script> await w.loadURL(`data:text/html,<script>
(async function() { (async function() {
@ -272,7 +273,7 @@ describe('web security', () => {
}); });
it('bypasses CORS when web security is disabled', async () => { it('bypasses CORS when web security is disabled', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: false, nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: false, nodeIntegration: true, contextIsolation: false } });
const p = emittedOnce(ipcMain, 'response'); const p = emittedOnce(ipcMain, 'response');
await w.loadURL(`data:text/html,<script> await w.loadURL(`data:text/html,<script>
(async function() { (async function() {
@ -452,7 +453,8 @@ describe('chromium features', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
partition: 'sw-file-scheme-spec' partition: 'sw-file-scheme-spec',
contextIsolation: false
} }
}); });
w.webContents.on('ipc-message', (event, channel, message) => { w.webContents.on('ipc-message', (event, channel, message) => {
@ -489,7 +491,8 @@ describe('chromium features', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
session: customSession session: customSession,
contextIsolation: false
} }
}); });
w.webContents.on('ipc-message', (event, channel, message) => { w.webContents.on('ipc-message', (event, channel, message) => {
@ -517,7 +520,8 @@ describe('chromium features', () => {
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
nodeIntegrationInWorker: true, nodeIntegrationInWorker: true,
partition: 'sw-file-scheme-worker-spec' partition: 'sw-file-scheme-worker-spec',
contextIsolation: false
} }
}); });
@ -551,7 +555,8 @@ describe('chromium features', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
partition: 'geolocation-spec' partition: 'geolocation-spec',
contextIsolation: false
} }
}); });
const message = emittedOnce(w.webContents, 'ipc-message'); const message = emittedOnce(w.webContents, 'ipc-message');
@ -670,7 +675,7 @@ describe('chromium features', () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
w.loadURL('about:blank'); w.loadURL('about:blank');
w.webContents.executeJavaScript(` w.webContents.executeJavaScript(`
b = window.open('devtools://devtools/bundled/inspector.html', '', 'nodeIntegration=no,show=no') { b = window.open('devtools://devtools/bundled/inspector.html', '', 'nodeIntegration=no,show=no'); null }
`); `);
const [, contents] = await emittedOnce(app, 'web-contents-created'); const [, contents] = await emittedOnce(app, 'web-contents-created');
const typeofProcessGlobal = await contents.executeJavaScript('typeof process'); const typeofProcessGlobal = await contents.executeJavaScript('typeof process');
@ -686,7 +691,7 @@ describe('chromium features', () => {
slashes: true slashes: true
}); });
w.webContents.executeJavaScript(` w.webContents.executeJavaScript(`
b = window.open(${JSON.stringify(windowUrl)}, '', 'javascript=no,show=no') { b = window.open(${JSON.stringify(windowUrl)}, '', 'javascript=no,show=no'); null }
`); `);
const [, contents] = await emittedOnce(app, 'web-contents-created'); const [, contents] = await emittedOnce(app, 'web-contents-created');
await emittedOnce(contents, 'did-finish-load'); await emittedOnce(contents, 'did-finish-load');
@ -796,7 +801,8 @@ describe('chromium features', () => {
const w = new BrowserWindow({ const w = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
w.loadFile(path.join(fixturesPath, 'pages', 'window-opener.html')); w.loadFile(path.join(fixturesPath, 'pages', 'window-opener.html'));
@ -833,7 +839,8 @@ describe('chromium features', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
session: ses session: ses,
contextIsolation: false
} }
}); });
w.loadFile(path.join(fixturesPath, 'pages', 'media-id-reset.html')); w.loadFile(path.join(fixturesPath, 'pages', 'media-id-reset.html'));
@ -848,7 +855,8 @@ describe('chromium features', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
session: ses session: ses,
contextIsolation: false
} }
}); });
w.loadFile(path.join(fixturesPath, 'pages', 'media-id-reset.html')); w.loadFile(path.join(fixturesPath, 'pages', 'media-id-reset.html'));
@ -916,7 +924,7 @@ describe('chromium features', () => {
for (const sandboxPopup of [false, true]) { for (const sandboxPopup of [false, true]) {
const description = `when parent=${s(parent)} opens child=${s(child)} with nodeIntegration=${nodeIntegration} nativeWindowOpen=${nativeWindowOpen} sandboxPopup=${sandboxPopup}, child should ${openerAccessible ? '' : 'not '}be able to access opener`; const description = `when parent=${s(parent)} opens child=${s(child)} with nodeIntegration=${nodeIntegration} nativeWindowOpen=${nativeWindowOpen} sandboxPopup=${sandboxPopup}, child should ${openerAccessible ? '' : 'not '}be able to access opener`;
it(description, async () => { it(description, async () => {
const w = new BrowserWindow({ show: true, webPreferences: { nodeIntegration: true, nativeWindowOpen } }); const w = new BrowserWindow({ show: true, webPreferences: { nodeIntegration: true, nativeWindowOpen, contextIsolation: false } });
w.webContents.setWindowOpenHandler(() => ({ w.webContents.setWindowOpenHandler(() => ({
action: 'allow', action: 'allow',
overrideBrowserWindowOptions: { overrideBrowserWindowOptions: {
@ -955,7 +963,7 @@ describe('chromium features', () => {
// We are testing whether context (3) can access context (2) under various conditions. // We are testing whether context (3) can access context (2) under various conditions.
// This is context (1), the base window for the test. // This is context (1), the base window for the test.
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true, contextIsolation: false } });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
const parentCode = `new Promise((resolve) => { const parentCode = `new Promise((resolve) => {
@ -969,7 +977,7 @@ describe('chromium features', () => {
// This is context (2), a WebView which will call window.open() // This is context (2), a WebView which will call window.open()
const webview = new WebView() const webview = new WebView()
webview.setAttribute('nodeintegration', '${nodeIntegration ? 'on' : 'off'}') webview.setAttribute('nodeintegration', '${nodeIntegration ? 'on' : 'off'}')
webview.setAttribute('webpreferences', 'nativeWindowOpen=${nativeWindowOpen ? 'yes' : 'no'}') webview.setAttribute('webpreferences', 'nativeWindowOpen=${nativeWindowOpen ? 'yes' : 'no'},contextIsolation=no')
webview.setAttribute('allowpopups', 'on') webview.setAttribute('allowpopups', 'on')
webview.src = ${JSON.stringify(parent + '?p=' + encodeURIComponent(child))} webview.src = ${JSON.stringify(parent + '?p=' + encodeURIComponent(child))}
webview.addEventListener('dom-ready', async () => { webview.addEventListener('dom-ready', async () => {
@ -1013,7 +1021,8 @@ describe('chromium features', () => {
beforeEach(() => { beforeEach(() => {
contents = (webContents as any).create({ contents = (webContents as any).create({
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
}); });
}); });
@ -1145,7 +1154,8 @@ describe('chromium features', () => {
it('default value allows websql', async () => { it('default value allows websql', async () => {
contents = (webContents as any).create({ contents = (webContents as any).create({
session: sqlSession, session: sqlSession,
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
}); });
contents.loadURL(origin); contents.loadURL(origin);
const [, error] = await emittedOnce(ipcMain, 'web-sql-response'); const [, error] = await emittedOnce(ipcMain, 'web-sql-response');
@ -1156,7 +1166,8 @@ describe('chromium features', () => {
contents = (webContents as any).create({ contents = (webContents as any).create({
session: sqlSession, session: sqlSession,
nodeIntegration: true, nodeIntegration: true,
enableWebSQL: false enableWebSQL: false,
contextIsolation: false
}); });
contents.loadURL(origin); contents.loadURL(origin);
const [, error] = await emittedOnce(ipcMain, 'web-sql-response'); const [, error] = await emittedOnce(ipcMain, 'web-sql-response');
@ -1167,7 +1178,8 @@ describe('chromium features', () => {
contents = (webContents as any).create({ contents = (webContents as any).create({
session: sqlSession, session: sqlSession,
nodeIntegration: true, nodeIntegration: true,
enableWebSQL: false enableWebSQL: false,
contextIsolation: false
}); });
contents.loadURL(origin); contents.loadURL(origin);
const [, error] = await emittedOnce(ipcMain, 'web-sql-response'); const [, error] = await emittedOnce(ipcMain, 'web-sql-response');
@ -1196,7 +1208,8 @@ describe('chromium features', () => {
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
webviewTag: true, webviewTag: true,
session: sqlSession session: sqlSession,
contextIsolation: false
} }
}); });
w.webContents.loadURL(origin); w.webContents.loadURL(origin);
@ -1207,7 +1220,7 @@ describe('chromium features', () => {
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const webview = new WebView(); const webview = new WebView();
webview.setAttribute('src', '${origin}'); webview.setAttribute('src', '${origin}');
webview.setAttribute('webpreferences', 'enableWebSQL=0'); webview.setAttribute('webpreferences', 'enableWebSQL=0,contextIsolation=no');
webview.setAttribute('partition', '${sqlPartition}'); webview.setAttribute('partition', '${sqlPartition}');
webview.setAttribute('nodeIntegration', 'on'); webview.setAttribute('nodeIntegration', 'on');
document.body.appendChild(webview); document.body.appendChild(webview);
@ -1225,7 +1238,8 @@ describe('chromium features', () => {
nodeIntegration: true, nodeIntegration: true,
enableWebSQL: false, enableWebSQL: false,
webviewTag: true, webviewTag: true,
session: sqlSession session: sqlSession,
contextIsolation: false
} }
}); });
w.webContents.loadURL('data:text/html,<html></html>'); w.webContents.loadURL('data:text/html,<html></html>');
@ -1234,7 +1248,7 @@ describe('chromium features', () => {
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const webview = new WebView(); const webview = new WebView();
webview.setAttribute('src', '${origin}'); webview.setAttribute('src', '${origin}');
webview.setAttribute('webpreferences', 'enableWebSQL=1'); webview.setAttribute('webpreferences', 'enableWebSQL=1,contextIsolation=no');
webview.setAttribute('partition', '${sqlPartition}'); webview.setAttribute('partition', '${sqlPartition}');
webview.setAttribute('nodeIntegration', 'on'); webview.setAttribute('nodeIntegration', 'on');
document.body.appendChild(webview); document.body.appendChild(webview);
@ -1251,7 +1265,8 @@ describe('chromium features', () => {
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
webviewTag: true, webviewTag: true,
session: sqlSession session: sqlSession,
contextIsolation: false
} }
}); });
w.webContents.loadURL(origin); w.webContents.loadURL(origin);
@ -1262,7 +1277,7 @@ describe('chromium features', () => {
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const webview = new WebView(); const webview = new WebView();
webview.setAttribute('src', '${origin}'); webview.setAttribute('src', '${origin}');
webview.setAttribute('webpreferences', 'enableWebSQL=1'); webview.setAttribute('webpreferences', 'enableWebSQL=1,contextIsolation=no');
webview.setAttribute('partition', '${sqlPartition}'); webview.setAttribute('partition', '${sqlPartition}');
webview.setAttribute('nodeIntegration', 'on'); webview.setAttribute('nodeIntegration', 'on');
document.body.appendChild(webview); document.body.appendChild(webview);
@ -1406,7 +1421,8 @@ describe('iframe using HTML fullscreen API while window is OS-fullscreened', ()
fullscreen: true, fullscreen: true,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
nodeIntegrationInSubFrames: true nodeIntegrationInSubFrames: true,
contextIsolation: false
} }
}); });
}); });

View file

@ -201,7 +201,7 @@ describe('chrome extensions', () => {
beforeEach(async () => { beforeEach(async () => {
const customSession = session.fromPartition(`persist:${uuid.v4()}`); const customSession = session.fromPartition(`persist:${uuid.v4()}`);
extension = await customSession.loadExtension(path.join(fixtures, 'extensions', 'chrome-i18n')); extension = await customSession.loadExtension(path.join(fixtures, 'extensions', 'chrome-i18n'));
w = new BrowserWindow({ show: false, webPreferences: { session: customSession, nodeIntegration: true } }); w = new BrowserWindow({ show: false, webPreferences: { session: customSession, nodeIntegration: true, contextIsolation: false } });
await w.loadURL(url); await w.loadURL(url);
}); });
it('getAcceptLanguages()', async () => { it('getAcceptLanguages()', async () => {
@ -226,7 +226,7 @@ describe('chrome extensions', () => {
beforeEach(async () => { beforeEach(async () => {
const customSession = session.fromPartition(`persist:${uuid.v4()}`); const customSession = session.fromPartition(`persist:${uuid.v4()}`);
await customSession.loadExtension(path.join(fixtures, 'extensions', 'chrome-runtime')); await customSession.loadExtension(path.join(fixtures, 'extensions', 'chrome-runtime'));
w = new BrowserWindow({ show: false, webPreferences: { session: customSession, nodeIntegration: true } }); w = new BrowserWindow({ show: false, webPreferences: { session: customSession, nodeIntegration: true, contextIsolation: false } });
await w.loadURL(url); await w.loadURL(url);
}); });
it('getManifest()', async () => { it('getManifest()', async () => {
@ -254,7 +254,7 @@ describe('chrome extensions', () => {
it('stores and retrieves a key', async () => { it('stores and retrieves a key', async () => {
const customSession = session.fromPartition(`persist:${uuid.v4()}`); const customSession = session.fromPartition(`persist:${uuid.v4()}`);
await customSession.loadExtension(path.join(fixtures, 'extensions', 'chrome-storage')); await customSession.loadExtension(path.join(fixtures, 'extensions', 'chrome-storage'));
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession, nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { session: customSession, nodeIntegration: true, contextIsolation: false } });
try { try {
const p = emittedOnce(ipcMain, 'storage-success'); const p = emittedOnce(ipcMain, 'storage-success');
await w.loadURL(url); await w.loadURL(url);
@ -385,7 +385,7 @@ describe('chrome extensions', () => {
it('loads a lazy background page when sending a message', async () => { it('loads a lazy background page when sending a message', async () => {
const customSession = session.fromPartition(`persist:${uuid.v4()}`); const customSession = session.fromPartition(`persist:${uuid.v4()}`);
await customSession.loadExtension(path.join(fixtures, 'extensions', 'lazy-background-page')); await customSession.loadExtension(path.join(fixtures, 'extensions', 'lazy-background-page'));
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession, nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { session: customSession, nodeIntegration: true, contextIsolation: false } });
try { try {
w.loadURL(url); w.loadURL(url);
const [, resp] = await emittedOnce(ipcMain, 'bg-page-message-response'); const [, resp] = await emittedOnce(ipcMain, 'bg-page-message-response');
@ -481,7 +481,7 @@ describe('chrome extensions', () => {
const customSession = session.fromPartition(`persist:${uuid.v4()}`); const customSession = session.fromPartition(`persist:${uuid.v4()}`);
customSession.loadExtension(path.join(fixtures, 'extensions', 'devtools-extension')); customSession.loadExtension(path.join(fixtures, 'extensions', 'devtools-extension'));
const winningMessage = emittedOnce(ipcMain, 'winning'); const winningMessage = emittedOnce(ipcMain, 'winning');
const w = new BrowserWindow({ show: true, webPreferences: { session: customSession, nodeIntegration: true } }); const w = new BrowserWindow({ show: true, webPreferences: { session: customSession, nodeIntegration: true, contextIsolation: false } });
await w.loadURL(url); await w.loadURL(url);
w.webContents.openDevTools(); w.webContents.openDevTools();
showLastDevToolsPanel(w); showLastDevToolsPanel(w);

View file

@ -28,7 +28,7 @@ app.whenReady().then(() => {
if (crashType === 'main') { if (crashType === 'main') {
process.crash(); process.crash();
} else if (crashType === 'renderer') { } else if (crashType === 'renderer') {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank'); w.loadURL('about:blank');
if (setExtraParameters) { if (setExtraParameters) {
w.webContents.executeJavaScript(` w.webContents.executeJavaScript(`
@ -44,7 +44,8 @@ app.whenReady().then(() => {
show: false, show: false,
webPreferences: { webPreferences: {
sandbox: true, sandbox: true,
preload: path.resolve(__dirname, 'sandbox-preload.js') preload: path.resolve(__dirname, 'sandbox-preload.js'),
contextIsolation: false
} }
}); });
w.loadURL(`about:blank?set_extra=${setExtraParameters ? 1 : 0}`); w.loadURL(`about:blank?set_extra=${setExtraParameters ? 1 : 0}`);

View file

@ -16,6 +16,7 @@
"nativeWindowOpen": true, "nativeWindowOpen": true,
"sandbox": true, "sandbox": true,
"backgroundColor": "blue", "backgroundColor": "blue",
"contextIsolation": true,
"nodeIntegration": false, "nodeIntegration": false,
"webviewTag": false, "webviewTag": false,
"nodeIntegrationInSubFrames": false, "nodeIntegrationInSubFrames": false,
@ -55,6 +56,7 @@
"sandbox": true, "sandbox": true,
"backgroundColor": "blue", "backgroundColor": "blue",
"zoomFactor": "2", "zoomFactor": "2",
"contextIsolation": true,
"nodeIntegration": false, "nodeIntegration": false,
"webviewTag": false, "webviewTag": false,
"nodeIntegrationInSubFrames": false, "nodeIntegrationInSubFrames": false,
@ -91,6 +93,7 @@
"nativeWindowOpen": true, "nativeWindowOpen": true,
"sandbox": true, "sandbox": true,
"backgroundColor": "gray", "backgroundColor": "gray",
"contextIsolation": true,
"nodeIntegration": false, "nodeIntegration": false,
"webviewTag": false, "webviewTag": false,
"nodeIntegrationInSubFrames": false, "nodeIntegrationInSubFrames": false,
@ -126,6 +129,7 @@
"nativeWindowOpen": true, "nativeWindowOpen": true,
"sandbox": true, "sandbox": true,
"backgroundColor": "blue", "backgroundColor": "blue",
"contextIsolation": true,
"nodeIntegration": false, "nodeIntegration": false,
"webviewTag": false, "webviewTag": false,
"nodeIntegrationInSubFrames": false, "nodeIntegrationInSubFrames": false,
@ -161,6 +165,7 @@
"nativeWindowOpen": true, "nativeWindowOpen": true,
"sandbox": true, "sandbox": true,
"backgroundColor": "blue", "backgroundColor": "blue",
"contextIsolation": true,
"nodeIntegration": false, "nodeIntegration": false,
"webviewTag": false, "webviewTag": false,
"nodeIntegrationInSubFrames": false, "nodeIntegrationInSubFrames": false,
@ -181,4 +186,4 @@
}, },
null null
] ]
] ]

View file

@ -19,6 +19,7 @@
"x": 10, "x": 10,
"y": 5, "y": 5,
"webPreferences": { "webPreferences": {
"contextIsolation": true,
"nodeIntegration": false, "nodeIntegration": false,
"webviewTag": false, "webviewTag": false,
"nodeIntegrationInSubFrames": false, "nodeIntegrationInSubFrames": false,
@ -52,6 +53,7 @@
"y": 10, "y": 10,
"webPreferences": { "webPreferences": {
"zoomFactor": "2", "zoomFactor": "2",
"contextIsolation": true,
"nodeIntegration": false, "nodeIntegration": false,
"webviewTag": false, "webviewTag": false,
"nodeIntegrationInSubFrames": false, "nodeIntegrationInSubFrames": false,
@ -82,6 +84,7 @@
"height": 600, "height": 600,
"backgroundColor": "gray", "backgroundColor": "gray",
"webPreferences": { "webPreferences": {
"contextIsolation": true,
"nodeIntegration": false, "nodeIntegration": false,
"webviewTag": false, "webviewTag": false,
"nodeIntegrationInSubFrames": false, "nodeIntegrationInSubFrames": false,
@ -117,6 +120,7 @@
"y": 20, "y": 20,
"title": "sup", "title": "sup",
"webPreferences": { "webPreferences": {
"contextIsolation": true,
"nodeIntegration": false, "nodeIntegration": false,
"webviewTag": false, "webviewTag": false,
"nodeIntegrationInSubFrames": false, "nodeIntegrationInSubFrames": false,
@ -150,6 +154,7 @@
"x": 1, "x": 1,
"y": 1, "y": 1,
"webPreferences": { "webPreferences": {
"contextIsolation": true,
"nodeIntegration": false, "nodeIntegration": false,
"webviewTag": false, "webviewTag": false,
"nodeIntegrationInSubFrames": false, "nodeIntegrationInSubFrames": false,

View file

@ -8,6 +8,6 @@
</head> </head>
<body> <body>
This is the root page with a webview This is the root page with a webview
<webview src="./frame-container.html" sandbox nodeIntegrationInSubFrames preload="./preload.js"></webview> <webview src="./frame-container.html" sandbox nodeIntegrationInSubFrames preload="./preload.js" webpreferences="contextIsolation=no"></webview>
</body> </body>
</html> </html>

View file

@ -4,6 +4,7 @@ if (process.isMainFrame) {
window.addEventListener('DOMContentLoaded', () => { window.addEventListener('DOMContentLoaded', () => {
const webview = document.createElement('webview'); const webview = document.createElement('webview');
webview.src = 'about:blank'; webview.src = 'about:blank';
webview.setAttribute('webpreferences', 'contextIsolation=no');
webview.addEventListener('did-finish-load', () => { webview.addEventListener('did-finish-load', () => {
ipcRenderer.send('webview-loaded'); ipcRenderer.send('webview-loaded');
}, { once: true }); }, { once: true });

View file

@ -19,7 +19,7 @@ describe('modules support', () => {
ifdescribe(nativeModulesEnabled)('echo', () => { ifdescribe(nativeModulesEnabled)('echo', () => {
afterEach(closeAllWindows); afterEach(closeAllWindows);
it('can be required in renderer', async () => { it('can be required in renderer', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank'); w.loadURL('about:blank');
await expect(w.webContents.executeJavaScript('{ require(\'echo\'); null }')).to.be.fulfilled(); await expect(w.webContents.executeJavaScript('{ require(\'echo\'); null }')).to.be.fulfilled();
}); });
@ -51,7 +51,7 @@ describe('modules support', () => {
]; ];
ifdescribe(nativeModulesEnabled && enablePlatforms.includes(process.platform))('module that use uv_dlopen', () => { ifdescribe(nativeModulesEnabled && enablePlatforms.includes(process.platform))('module that use uv_dlopen', () => {
it('can be required in renderer', async () => { it('can be required in renderer', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank'); w.loadURL('about:blank');
await expect(w.webContents.executeJavaScript('{ require(\'uv-dlopen\'); null }')).to.be.fulfilled(); await expect(w.webContents.executeJavaScript('{ require(\'uv-dlopen\'); null }')).to.be.fulfilled();
}); });
@ -163,7 +163,7 @@ describe('modules support', () => {
describe('when loaded URL is not file: protocol', () => { describe('when loaded URL is not file: protocol', () => {
afterEach(closeAllWindows); afterEach(closeAllWindows);
it('searches for module under app directory', async () => { it('searches for module under app directory', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank'); w.loadURL('about:blank');
const result = await w.webContents.executeJavaScript('typeof require("q").when'); const result = await w.webContents.executeJavaScript('typeof require("q").when');
expect(result).to.equal('function'); expect(result).to.equal('function');

View file

@ -81,7 +81,8 @@ describe('security warnings', () => {
w = new BrowserWindow({ w = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
@ -248,6 +249,6 @@ describe('security warnings', () => {
}); });
}; };
generateSpecs('without sandbox', {}); generateSpecs('without sandbox', { contextIsolation: false });
generateSpecs('with sandbox', { sandbox: true }); generateSpecs('with sandbox', { sandbox: true, contextIsolation: false });
}); });

View file

@ -16,7 +16,8 @@ ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', () => {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
partition: `unique-spell-${Date.now()}` partition: `unique-spell-${Date.now()}`,
contextIsolation: false
} }
}); });
w.webContents.session.setSpellCheckerLanguages(['en-US']); w.webContents.session.setSpellCheckerLanguages(['en-US']);

View file

@ -25,7 +25,8 @@ ifdescribe(process.platform !== 'linux')('document.visibilityState', () => {
paintWhenInitiallyHidden: false, paintWhenInitiallyHidden: false,
webPreferences: { webPreferences: {
...(options.webPreferences || {}), ...(options.webPreferences || {}),
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
await Promise.resolve(fn.apply(this, args)); await Promise.resolve(fn.apply(this, args));

View file

@ -52,7 +52,8 @@ describe('<webview> tag', function () {
show: false, show: false,
webPreferences: { webPreferences: {
webviewTag: true, webviewTag: true,
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
w.loadFile(path.join(fixtures, 'pages', 'webview-no-script.html')); w.loadFile(path.join(fixtures, 'pages', 'webview-no-script.html'));
@ -169,7 +170,8 @@ describe('<webview> tag', function () {
show: false, show: false,
webPreferences: { webPreferences: {
webviewTag: true, webviewTag: true,
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
const didAttachWebview = emittedOnce(w.webContents, 'did-attach-webview'); const didAttachWebview = emittedOnce(w.webContents, 'did-attach-webview');
@ -212,7 +214,8 @@ describe('<webview> tag', function () {
show: false, show: false,
webPreferences: { webPreferences: {
webviewTag: true, webviewTag: true,
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });
w.webContents.session.removeExtension('foo'); w.webContents.session.removeExtension('foo');
@ -223,6 +226,7 @@ describe('<webview> tag', function () {
w.loadFile(path.join(__dirname, 'fixtures', 'pages', 'webview-devtools.html')); w.loadFile(path.join(__dirname, 'fixtures', 'pages', 'webview-devtools.html'));
loadWebView(w.webContents, { loadWebView(w.webContents, {
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${path.join(__dirname, 'fixtures', 'blank.html')}` src: `file://${path.join(__dirname, 'fixtures', 'blank.html')}`
}, true); }, true);
let childWebContentsId = 0; let childWebContentsId = 0;
@ -271,7 +275,8 @@ describe('<webview> tag', function () {
webPreferences: { webPreferences: {
webviewTag: true, webviewTag: true,
nodeIntegration: true, nodeIntegration: true,
zoomFactor: 1.2 zoomFactor: 1.2,
contextIsolation: false
} }
}); });
const zoomEventPromise = emittedOnce(ipcMain, 'webview-parent-zoom-level'); const zoomEventPromise = emittedOnce(ipcMain, 'webview-parent-zoom-level');
@ -288,7 +293,8 @@ describe('<webview> tag', function () {
webPreferences: { webPreferences: {
webviewTag: true, webviewTag: true,
nodeIntegration: true, nodeIntegration: true,
zoomFactor: 1.2 zoomFactor: 1.2,
contextIsolation: false
} }
}); });
const promise = new Promise<void>((resolve) => { const promise = new Promise<void>((resolve) => {
@ -318,7 +324,8 @@ describe('<webview> tag', function () {
webPreferences: { webPreferences: {
webviewTag: true, webviewTag: true,
nodeIntegration: true, nodeIntegration: true,
zoomFactor: 1.2 zoomFactor: 1.2,
contextIsolation: false
} }
}); });
const promise = new Promise<void>((resolve) => { const promise = new Promise<void>((resolve) => {
@ -343,7 +350,8 @@ describe('<webview> tag', function () {
webPreferences: { webPreferences: {
webviewTag: true, webviewTag: true,
nodeIntegration: true, nodeIntegration: true,
zoomFactor: 1.2 zoomFactor: 1.2,
contextIsolation: false
} }
}); });
w.loadFile(path.join(fixtures, 'pages', 'webview-origin-zoom-level.html')); w.loadFile(path.join(fixtures, 'pages', 'webview-origin-zoom-level.html'));
@ -359,7 +367,8 @@ describe('<webview> tag', function () {
webviewTag: true, webviewTag: true,
nodeIntegration: true, nodeIntegration: true,
zoomFactor: 1.2, zoomFactor: 1.2,
session: webviewSession session: webviewSession,
contextIsolation: false
} }
}); });
const attachPromise = emittedOnce(w.webContents, 'did-attach-webview'); const attachPromise = emittedOnce(w.webContents, 'did-attach-webview');
@ -375,7 +384,7 @@ describe('<webview> tag', function () {
describe('nativeWindowOpen option', () => { describe('nativeWindowOpen option', () => {
let w: BrowserWindow; let w: BrowserWindow;
beforeEach(async () => { beforeEach(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true, contextIsolation: false } });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
}); });
afterEach(closeAllWindows); afterEach(closeAllWindows);
@ -385,7 +394,7 @@ describe('<webview> tag', function () {
loadWebView(w.webContents, { loadWebView(w.webContents, {
allowpopups: 'on', allowpopups: 'on',
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'nativeWindowOpen=1', webpreferences: 'nativeWindowOpen=1,contextIsolation=no',
src: `file://${path.join(fixtures, 'api', 'native-window-open-blank.html')}` src: `file://${path.join(fixtures, 'api', 'native-window-open-blank.html')}`
}); });
@ -398,7 +407,7 @@ describe('<webview> tag', function () {
loadWebView(w.webContents, { loadWebView(w.webContents, {
allowpopups: 'on', allowpopups: 'on',
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'nativeWindowOpen=1', webpreferences: 'nativeWindowOpen=1,contextIsolation=no',
src: `file://${path.join(fixtures, 'api', 'native-window-open-file.html')}` src: `file://${path.join(fixtures, 'api', 'native-window-open-file.html')}`
}); });
@ -410,7 +419,7 @@ describe('<webview> tag', function () {
// Don't wait for loading to finish. // Don't wait for loading to finish.
loadWebView(w.webContents, { loadWebView(w.webContents, {
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'nativeWindowOpen=1', webpreferences: 'nativeWindowOpen=1,contextIsolation=no',
src: `file://${path.join(fixtures, 'api', 'native-window-open-no-allowpopups.html')}` src: `file://${path.join(fixtures, 'api', 'native-window-open-no-allowpopups.html')}`
}); });
@ -423,7 +432,7 @@ describe('<webview> tag', function () {
loadWebView(w.webContents, { loadWebView(w.webContents, {
allowpopups: 'on', allowpopups: 'on',
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'nativeWindowOpen=1', webpreferences: 'nativeWindowOpen=1,contextIsolation=no',
src: `file://${path.join(fixtures, 'api', 'native-window-open-cross-origin.html')}` src: `file://${path.join(fixtures, 'api', 'native-window-open-cross-origin.html')}`
}); });
@ -439,7 +448,7 @@ describe('<webview> tag', function () {
const attributes = { const attributes = {
allowpopups: 'on', allowpopups: 'on',
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'nativeWindowOpen=1', webpreferences: 'nativeWindowOpen=1,contextIsolation=no',
src: `file://${fixtures}/pages/window-open.html` src: `file://${fixtures}/pages/window-open.html`
}; };
const { url, frameName } = await w.webContents.executeJavaScript(` const { url, frameName } = await w.webContents.executeJavaScript(`
@ -463,7 +472,7 @@ describe('<webview> tag', function () {
// Don't wait for loading to finish. // Don't wait for loading to finish.
loadWebView(w.webContents, { loadWebView(w.webContents, {
allowpopups: 'on', allowpopups: 'on',
webpreferences: 'nativeWindowOpen=1', webpreferences: 'nativeWindowOpen=1,contextIsolation=no',
src: `file://${fixtures}/pages/window-open.html` src: `file://${fixtures}/pages/window-open.html`
}); });
@ -476,7 +485,7 @@ describe('<webview> tag', function () {
loadWebView(w.webContents, { loadWebView(w.webContents, {
allowpopups: 'on', allowpopups: 'on',
webpreferences: 'nativeWindowOpen=1', webpreferences: 'nativeWindowOpen=1,contextIsolation=no',
src: `file://${fixtures}/pages/window-open.html` src: `file://${fixtures}/pages/window-open.html`
}); });
@ -528,7 +537,7 @@ describe('<webview> tag', function () {
describe('permission request handlers', () => { describe('permission request handlers', () => {
let w: BrowserWindow; let w: BrowserWindow;
beforeEach(async () => { beforeEach(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true, contextIsolation: false } });
await w.loadURL('about:blank'); await w.loadURL('about:blank');
}); });
afterEach(closeAllWindows); afterEach(closeAllWindows);
@ -582,7 +591,8 @@ describe('<webview> tag', function () {
loadWebView(w.webContents, { loadWebView(w.webContents, {
src: `file://${fixtures}/pages/permissions/geolocation.html`, src: `file://${fixtures}/pages/permissions/geolocation.html`,
partition, partition,
nodeintegration: 'on' nodeintegration: 'on',
webpreferences: 'contextIsolation=no'
}); });
const [, webViewContents] = await emittedOnce(app, 'web-contents-created'); const [, webViewContents] = await emittedOnce(app, 'web-contents-created');
setUpRequestHandler(webViewContents.id, 'geolocation'); setUpRequestHandler(webViewContents.id, 'geolocation');
@ -595,7 +605,8 @@ describe('<webview> tag', function () {
loadWebView(w.webContents, { loadWebView(w.webContents, {
src: `file://${fixtures}/pages/permissions/midi.html`, src: `file://${fixtures}/pages/permissions/midi.html`,
partition, partition,
nodeintegration: 'on' nodeintegration: 'on',
webpreferences: 'contextIsolation=no'
}); });
const [, webViewContents] = await emittedOnce(app, 'web-contents-created'); const [, webViewContents] = await emittedOnce(app, 'web-contents-created');
setUpRequestHandler(webViewContents.id, 'midi'); setUpRequestHandler(webViewContents.id, 'midi');
@ -608,7 +619,8 @@ describe('<webview> tag', function () {
loadWebView(w.webContents, { loadWebView(w.webContents, {
src: `file://${fixtures}/pages/permissions/midi-sysex.html`, src: `file://${fixtures}/pages/permissions/midi-sysex.html`,
partition, partition,
nodeintegration: 'on' nodeintegration: 'on',
webpreferences: 'contextIsolation=no'
}); });
const [, webViewContents] = await emittedOnce(app, 'web-contents-created'); const [, webViewContents] = await emittedOnce(app, 'web-contents-created');
setUpRequestHandler(webViewContents.id, 'midiSysex'); setUpRequestHandler(webViewContents.id, 'midiSysex');
@ -630,7 +642,8 @@ describe('<webview> tag', function () {
loadWebView(w.webContents, { loadWebView(w.webContents, {
src: `file://${fixtures}/pages/permissions/notification.html`, src: `file://${fixtures}/pages/permissions/notification.html`,
partition, partition,
nodeintegration: 'on' nodeintegration: 'on',
webpreferences: 'contextIsolation=no'
}); });
const [, webViewContents] = await emittedOnce(app, 'web-contents-created'); const [, webViewContents] = await emittedOnce(app, 'web-contents-created');

View file

@ -181,6 +181,7 @@ describe('chromium feature', () => {
const webview = new WebView(); const webview = new WebView();
const consoleMessage = waitForEvent(webview, 'console-message'); const consoleMessage = waitForEvent(webview, 'console-message');
webview.allowpopups = true; webview.allowpopups = true;
webview.setAttribute('webpreferences', 'contextIsolation=no');
webview.src = url.format({ webview.src = url.format({
pathname: `${fixtures}/pages/webview-opener-postMessage.html`, pathname: `${fixtures}/pages/webview-opener-postMessage.html`,
protocol: 'file', protocol: 'file',
@ -266,7 +267,7 @@ describe('chromium feature', () => {
const webview = new WebView(); const webview = new WebView();
const eventPromise = waitForEvent(webview, 'ipc-message'); const eventPromise = waitForEvent(webview, 'ipc-message');
webview.src = `file://${fixtures}/pages/worker.html`; webview.src = `file://${fixtures}/pages/worker.html`;
webview.setAttribute('webpreferences', 'nodeIntegration, nodeIntegrationInWorker'); webview.setAttribute('webpreferences', 'nodeIntegration, nodeIntegrationInWorker, contextIsolation=no');
document.body.appendChild(webview); document.body.appendChild(webview);
const event = await eventPromise; const event = await eventPromise;
webview.remove(); webview.remove();

View file

@ -1 +1 @@
require('electron').ipcRenderer.send('answer', 'test'); window.ping = 'pong';

View file

@ -16,7 +16,8 @@ app.whenReady().then(() => {
window = new BrowserWindow({ window = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
contextIsolation: false
} }
}); });

View file

@ -20,7 +20,7 @@
<div> <div>
<button id="element-1">Button 1</button> <button id="element-1">Button 1</button>
<button id="element-2">Button 2</button> <button id="element-2">Button 2</button>
<webview src="tab-focus-loop-elements-wv.html" nodeintegration></webview> <webview src="tab-focus-loop-elements-wv.html" nodeintegration webpreferences="contextIsolation=no"></webview>
<button id="element-3">Button 3</button> <button id="element-3">Button 3</button>
</div> </div>
</body> </body>

View file

@ -1,5 +1,5 @@
<html> <html>
<body> <body>
<webview nodeintegration src="ping.html"/> <webview nodeintegration src="ping.html" webpreferences="contextIsolation=no" />
</body> </body>
</html> </html>

View file

@ -1,5 +1,5 @@
<html> <html>
<body> <body>
<webview nodeintegration src="zoom-factor.html"/> <webview nodeintegration src="zoom-factor.html" webpreferences="contextIsolation=no" />
</body> </body>
</html> </html>

View file

@ -109,7 +109,8 @@ app.whenReady().then(async function () {
backgroundThrottling: false, backgroundThrottling: false,
nodeIntegration: true, nodeIntegration: true,
enableRemoteModule: false, enableRemoteModule: false,
webviewTag: true webviewTag: true,
contextIsolation: false
} }
}); });
window.loadFile('static/index.html', { window.loadFile('static/index.html', {

View file

@ -112,6 +112,7 @@ describe('<webview> tag', function () {
it('inserts node symbols when set', async () => { it('inserts node symbols when set', async () => {
const message = await startLoadingWebViewAndWaitForMessage(webview, { const message = await startLoadingWebViewAndWaitForMessage(webview, {
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/d.html` src: `file://${fixtures}/pages/d.html`
}); });
@ -132,6 +133,7 @@ describe('<webview> tag', function () {
const message = await startLoadingWebViewAndWaitForMessage(webview, { const message = await startLoadingWebViewAndWaitForMessage(webview, {
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/post.html` src: `file://${fixtures}/pages/post.html`
}); });
@ -154,6 +156,7 @@ describe('<webview> tag', function () {
}); });
loadWebView(webview, { loadWebView(webview, {
allowpopups: 'on', allowpopups: 'on',
webpreferences: 'contextIsolation=no',
src src
}); });
const { message } = await waitForEvent(webview, 'console-message'); const { message } = await waitForEvent(webview, 'console-message');
@ -163,6 +166,7 @@ describe('<webview> tag', function () {
(nativeModulesEnabled ? it : it.skip)('loads native modules when navigation happens', async function () { (nativeModulesEnabled ? it : it.skip)('loads native modules when navigation happens', async function () {
await loadWebView(webview, { await loadWebView(webview, {
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/native-module.html` src: `file://${fixtures}/pages/native-module.html`
}); });
@ -177,7 +181,8 @@ describe('<webview> tag', function () {
it('loads the script before other scripts in window', async () => { it('loads the script before other scripts in window', async () => {
const message = await startLoadingWebViewAndWaitForMessage(webview, { const message = await startLoadingWebViewAndWaitForMessage(webview, {
preload: `${fixtures}/module/preload.js`, preload: `${fixtures}/module/preload.js`,
src: `file://${fixtures}/pages/e.html` src: `file://${fixtures}/pages/e.html`,
contextIsolation: false
}); });
expect(message).to.be.a('string'); expect(message).to.be.a('string');
@ -343,6 +348,7 @@ describe('<webview> tag', function () {
const message = await startLoadingWebViewAndWaitForMessage(webview, { const message = await startLoadingWebViewAndWaitForMessage(webview, {
disablewebsecurity: '', disablewebsecurity: '',
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/d.html` src: `file://${fixtures}/pages/d.html`
}); });
@ -391,6 +397,7 @@ describe('<webview> tag', function () {
const message = await startLoadingWebViewAndWaitForMessage(webview, { const message = await startLoadingWebViewAndWaitForMessage(webview, {
nodeintegration: 'on', nodeintegration: 'on',
partition: 'test2', partition: 'test2',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/d.html` src: `file://${fixtures}/pages/d.html`
}); });
@ -464,7 +471,7 @@ describe('<webview> tag', function () {
it('can enable nodeintegration', async () => { it('can enable nodeintegration', async () => {
const message = await startLoadingWebViewAndWaitForMessage(webview, { const message = await startLoadingWebViewAndWaitForMessage(webview, {
src: `file://${fixtures}/pages/d.html`, src: `file://${fixtures}/pages/d.html`,
webpreferences: 'nodeIntegration' webpreferences: 'nodeIntegration,contextIsolation=no'
}); });
const types = JSON.parse(message); const types = JSON.parse(message);
@ -493,7 +500,7 @@ describe('<webview> tag', function () {
const message = await startLoadingWebViewAndWaitForMessage(webview, { const message = await startLoadingWebViewAndWaitForMessage(webview, {
src: `data:text/html;base64,${encoded}`, src: `data:text/html;base64,${encoded}`,
webpreferences: 'webSecurity=no, nodeIntegration=yes' webpreferences: 'webSecurity=no, nodeIntegration=yes, contextIsolation=no'
}); });
expect(message).to.equal('function'); expect(message).to.equal('function');
@ -526,6 +533,7 @@ describe('<webview> tag', function () {
it('emits when guest sends an ipc message to browser', async () => { it('emits when guest sends an ipc message to browser', async () => {
loadWebView(webview, { loadWebView(webview, {
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/ipc-message.html` src: `file://${fixtures}/pages/ipc-message.html`
}); });
const { channel, args } = await waitForEvent(webview, 'ipc-message'); const { channel, args } = await waitForEvent(webview, 'ipc-message');
@ -710,6 +718,7 @@ describe('<webview> tag', function () {
it('should emit beforeunload handler', async () => { it('should emit beforeunload handler', async () => {
await loadWebView(webview, { await loadWebView(webview, {
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/beforeunload-false.html` src: `file://${fixtures}/pages/beforeunload-false.html`
}); });
@ -821,6 +830,7 @@ describe('<webview> tag', function () {
}); });
loadWebView(webview, { loadWebView(webview, {
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/basic-auth.html?port=${port}` src: `file://${fixtures}/pages/basic-auth.html?port=${port}`
}); });
}); });
@ -896,6 +906,7 @@ describe('<webview> tag', function () {
it('can send keyboard event', async () => { it('can send keyboard event', async () => {
loadWebView(webview, { loadWebView(webview, {
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/onkeyup.html` src: `file://${fixtures}/pages/onkeyup.html`
}); });
await waitForEvent(webview, 'dom-ready'); await waitForEvent(webview, 'dom-ready');
@ -915,6 +926,7 @@ describe('<webview> tag', function () {
it('can send mouse event', async () => { it('can send mouse event', async () => {
loadWebView(webview, { loadWebView(webview, {
nodeintegration: 'on', nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/onmouseup.html` src: `file://${fixtures}/pages/onmouseup.html`
}); });
await waitForEvent(webview, 'dom-ready'); await waitForEvent(webview, 'dom-ready');