diff --git a/shell/browser/web_contents_preferences.cc b/shell/browser/web_contents_preferences.cc index f72400479b2..32029ef99f1 100644 --- a/shell/browser/web_contents_preferences.cc +++ b/shell/browser/web_contents_preferences.cc @@ -127,16 +127,7 @@ WebContentsPreferences::WebContentsPreferences( SetDefaultBoolIfUndefined(options::kWebviewTag, false); SetDefaultBoolIfUndefined(options::kSandbox, false); SetDefaultBoolIfUndefined(options::kNativeWindowOpen, false); - if (IsUndefined(options::kContextIsolation)) { - 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::kContextIsolation, true); SetDefaultBoolIfUndefined(options::kWorldSafeExecuteJavaScript, true); SetDefaultBoolIfUndefined(options::kJavaScript, true); SetDefaultBoolIfUndefined(options::kImages, true); @@ -429,7 +420,7 @@ void WebContentsPreferences::OverrideWebkitPrefs( prefs->opener_id = opener_id; // 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) // Whether to enable the remote module diff --git a/spec-main/api-app-spec.ts b/spec-main/api-app-spec.ts index 931eee30527..79017954827 100644 --- a/spec-main/api-app-spec.ts +++ b/spec-main/api-app-spec.ts @@ -409,7 +409,8 @@ describe('app module', () => { w = new BrowserWindow({ show: false, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); await w.loadURL('about:blank'); @@ -426,7 +427,8 @@ describe('app module', () => { w = new BrowserWindow({ show: false, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); await w.loadURL('about:blank'); @@ -444,7 +446,8 @@ describe('app module', () => { w = new BrowserWindow({ show: false, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); await w.loadURL('about:blank'); @@ -463,7 +466,8 @@ describe('app module', () => { show: false, webPreferences: { nodeIntegration: true, - enableRemoteModule: true + enableRemoteModule: true, + contextIsolation: false } }); await w.loadURL('about:blank'); @@ -481,7 +485,8 @@ describe('app module', () => { show: false, webPreferences: { nodeIntegration: true, - enableRemoteModule: true + enableRemoteModule: true, + contextIsolation: false } }); await w.loadURL('about:blank'); @@ -499,7 +504,8 @@ describe('app module', () => { show: false, webPreferences: { nodeIntegration: true, - enableRemoteModule: true + enableRemoteModule: true, + contextIsolation: false } }); await w.loadURL('about:blank'); @@ -517,7 +523,8 @@ describe('app module', () => { show: false, webPreferences: { nodeIntegration: true, - enableRemoteModule: true + enableRemoteModule: true, + contextIsolation: false } }); await w.loadURL('about:blank'); @@ -534,7 +541,8 @@ describe('app module', () => { show: false, webPreferences: { nodeIntegration: true, - enableRemoteModule: true + enableRemoteModule: true, + contextIsolation: false } }); await w.loadURL('about:blank'); diff --git a/spec-main/api-browser-window-affinity-spec.ts b/spec-main/api-browser-window-affinity-spec.ts index 23d2af93b5e..4dbaa15518e 100644 --- a/spec-main/api-browser-window-affinity-spec.ts +++ b/spec-main/api-browser-window-affinity-spec.ts @@ -3,6 +3,7 @@ import * as path from 'path'; import { ipcMain, BrowserWindow, WebPreferences, app } from 'electron/main'; import { closeWindow } from './window-helpers'; +import { emittedOnce } from './events-helpers'; describe('BrowserWindow with affinity module', () => { const fixtures = path.resolve(__dirname, '..', 'spec', 'fixtures'); @@ -88,19 +89,15 @@ describe('BrowserWindow with affinity module', () => { const affinityWithNodeTrue = 'affinityWithNodeTrue'; const affinityWithNodeFalse = 'affinityWithNodeFalse'; - function testNodeIntegration (present: boolean) { - return new Promise((resolve) => { - ipcMain.once('answer', (event, typeofProcess, typeofBuffer) => { - if (present) { - expect(typeofProcess).to.not.equal('undefined'); - expect(typeofBuffer).to.not.equal('undefined'); - } else { - expect(typeofProcess).to.equal('undefined'); - expect(typeofBuffer).to.equal('undefined'); - } - resolve(); - }); - }); + async function testNodeIntegration (present: boolean) { + const [, typeofProcess, typeofBuffer] = await emittedOnce(ipcMain, 'answer'); + if (present) { + expect(typeofProcess).to.not.equal('undefined'); + expect(typeofBuffer).to.not.equal('undefined'); + } else { + expect(typeofProcess).to.equal('undefined'); + expect(typeofBuffer).to.equal('undefined'); + } } it('disables node integration when specified to false', async () => { @@ -109,7 +106,8 @@ describe('BrowserWindow with affinity module', () => { createWindowWithWebPrefs({ affinity: affinityWithNodeTrue, preload, - nodeIntegration: false + nodeIntegration: false, + contextIsolation: false }) ]); await closeWindow(w, { assertNotWindows: false }); @@ -120,7 +118,8 @@ describe('BrowserWindow with affinity module', () => { createWindowWithWebPrefs({ affinity: affinityWithNodeTrue, preload, - nodeIntegration: false + nodeIntegration: false, + contextIsolation: false }) ]); const [, w2] = await Promise.all([ @@ -128,7 +127,8 @@ describe('BrowserWindow with affinity module', () => { createWindowWithWebPrefs({ affinity: affinityWithNodeTrue, preload, - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false }) ]); await Promise.all([ @@ -143,7 +143,8 @@ describe('BrowserWindow with affinity module', () => { createWindowWithWebPrefs({ affinity: affinityWithNodeFalse, preload, - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false }) ]); await closeWindow(w, { assertNotWindows: false }); @@ -155,7 +156,8 @@ describe('BrowserWindow with affinity module', () => { createWindowWithWebPrefs({ affinity: affinityWithNodeFalse, preload, - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false }) ]); const [, w2] = await Promise.all([ @@ -163,7 +165,8 @@ describe('BrowserWindow with affinity module', () => { createWindowWithWebPrefs({ affinity: affinityWithNodeFalse, preload, - nodeIntegration: false + nodeIntegration: false, + contextIsolation: false }) ]); await Promise.all([ diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index 20c770c37b9..dd02458ff67 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -95,7 +95,7 @@ describe('BrowserWindow module', () => { describe('BrowserWindow.close()', () => { let w = null as unknown as BrowserWindow; beforeEach(() => { - w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); + w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } }); }); afterEach(async () => { await closeWindow(w); @@ -190,7 +190,7 @@ describe('BrowserWindow module', () => { describe('window.close()', () => { let w = null as unknown as BrowserWindow; beforeEach(() => { - w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); + w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } }); }); afterEach(async () => { await closeWindow(w); @@ -445,11 +445,9 @@ describe('BrowserWindow module', () => { }); }); - it('should support support base url for data urls', async () => { - const answer = emittedOnce(ipcMain, 'answer'); - w.loadURL('data:text/html,', { baseURLForDataURL: `other://${path.join(fixtures, 'api')}${path.sep}` }); - const [, test] = await answer; - expect(test).to.equal('test'); + it('should support base url for data urls', async () => { + await w.loadURL('data:text/html,', { baseURLForDataURL: `other://${path.join(fixtures, 'api')}${path.sep}` }); + expect(await w.webContents.executeJavaScript('window.ping')).to.equal('pong'); }); }); @@ -2009,6 +2007,7 @@ describe('BrowserWindow module', () => { show: false, webPreferences: { nodeIntegration: true, + contextIsolation: false, preload } }); @@ -2023,6 +2022,7 @@ describe('BrowserWindow module', () => { webPreferences: { nodeIntegration: true, enableRemoteModule: true, + contextIsolation: false, preload } }); @@ -2036,6 +2036,7 @@ describe('BrowserWindow module', () => { show: false, webPreferences: { nodeIntegration: true, + contextIsolation: false, preload } }); @@ -2075,7 +2076,8 @@ describe('BrowserWindow module', () => { show: false, webPreferences: { 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'); @@ -2129,7 +2131,8 @@ describe('BrowserWindow module', () => { const w = new BrowserWindow({ show: false, webPreferences: { - preload + preload, + contextIsolation: false } }); w.loadFile(path.join(fixtures, 'api', 'blank.html')); @@ -2224,7 +2227,8 @@ describe('BrowserWindow module', () => { show: false, webPreferences: { sandbox: true, - preload + preload, + contextIsolation: false } }); w.loadFile(path.join(fixtures, 'api', 'preload.html')); @@ -2238,7 +2242,8 @@ describe('BrowserWindow module', () => { show: false, webPreferences: { sandbox: true, - preload: preloadSpecialChars + preload: preloadSpecialChars, + contextIsolation: false } }); w.loadFile(path.join(fixtures, 'api', 'preload.html')); @@ -2263,7 +2268,8 @@ describe('BrowserWindow module', () => { show: false, webPreferences: { sandbox: true, - preload + preload, + contextIsolation: false } }); const htmlPath = path.join(__dirname, 'fixtures', 'api', 'sandbox.html?exit-event'); @@ -2281,7 +2287,8 @@ describe('BrowserWindow module', () => { show: true, webPreferences: { sandbox: true, - preload + preload, + contextIsolation: false } }); @@ -2315,7 +2322,8 @@ describe('BrowserWindow module', () => { show: true, webPreferences: { sandbox: true, - preload + preload, + contextIsolation: false } }); @@ -2413,7 +2421,8 @@ describe('BrowserWindow module', () => { show: false, webPreferences: { sandbox: true, - preload + preload, + contextIsolation: false } }); let childWc: WebContents | null = null; @@ -2510,7 +2519,8 @@ describe('BrowserWindow module', () => { webPreferences: { preload, sandbox: true, - enableRemoteModule: true + enableRemoteModule: true, + contextIsolation: false } }); w.loadFile(path.join(__dirname, 'fixtures', 'api', 'sandbox.html'), { search: 'reload-remote' }); @@ -2547,7 +2557,8 @@ describe('BrowserWindow module', () => { webPreferences: { preload, sandbox: true, - enableRemoteModule: true + enableRemoteModule: true, + contextIsolation: false } }); w.webContents.setWindowOpenHandler(() => ({ action: 'allow', overrideBrowserWindowOptions: { webPreferences: { preload } } })); @@ -2585,7 +2596,8 @@ describe('BrowserWindow module', () => { show: false, webPreferences: { sandbox: true, - preload + preload, + contextIsolation: false } }); w.webContents.once('preload-error', (event, preloadPath, error) => { @@ -2627,7 +2639,8 @@ describe('BrowserWindow module', () => { webPreferences: { sandbox: true, preload, - webviewTag: true + webviewTag: true, + contextIsolation: false } }); const didAttachWebview = emittedOnce(w.webContents, 'did-attach-webview'); @@ -2650,7 +2663,8 @@ describe('BrowserWindow module', () => { nodeIntegration: true, nativeWindowOpen: true, // tests relies on preloads in opened windows - nodeIntegrationInSubFrames: true + nodeIntegrationInSubFrames: true, + contextIsolation: false } }); }); @@ -2700,6 +2714,7 @@ describe('BrowserWindow module', () => { nodeIntegrationInSubFrames: true, nativeWindowOpen: true, webviewTag: true, + contextIsolation: false, preload } }); @@ -2772,7 +2787,8 @@ describe('BrowserWindow module', () => { webPreferences: { nativeWindowOpen: true, // test relies on preloads in opened window - nodeIntegrationInSubFrames: true + nodeIntegrationInSubFrames: true, + contextIsolation: false } }); @@ -2959,7 +2975,8 @@ describe('BrowserWindow module', () => { width: 100, height: 100, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); @@ -2983,7 +3000,8 @@ describe('BrowserWindow module', () => { width: 100, height: 100, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); @@ -3010,7 +3028,8 @@ describe('BrowserWindow module', () => { width: 100, height: 100, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); @@ -3030,7 +3049,8 @@ describe('BrowserWindow module', () => { width: 100, height: 100, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); w.loadFile(path.join(fixtures, 'pages', 'visibilitychange.html')); @@ -3050,7 +3070,8 @@ describe('BrowserWindow module', () => { width: 100, height: 100, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); w.loadFile(path.join(fixtures, 'pages', 'visibilitychange.html')); @@ -4423,7 +4444,8 @@ describe('BrowserWindow module', () => { const w = new BrowserWindow({ show: false, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); diff --git a/spec-main/api-crash-reporter-spec.ts b/spec-main/api-crash-reporter-spec.ts index e5acc3f6751..1136d9a522b 100644 --- a/spec-main/api-crash-reporter-spec.ts +++ b/spec-main/api-crash-reporter-spec.ts @@ -239,7 +239,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_ remotely(() => { 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.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. remotely(() => { 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.webContents.executeJavaScript('process.crash()'); }); @@ -485,7 +485,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_ const rendererParameters = await remotely(async () => { const { crashReporter, BrowserWindow } = require('electron'); 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'); await bw.webContents.executeJavaScript('require(\'electron\').crashReporter.addExtraParameter(\'hello\', \'world\')'); 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') { return remotely(() => { 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.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'); return remotely((preload: string) => { 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'); }, preloadPath); } else if (processType === 'node') { diff --git a/spec-main/api-desktop-capturer-spec.ts b/spec-main/api-desktop-capturer-spec.ts index 44bf9bbb4cf..df1fb27e822 100644 --- a/spec-main/api-desktop-capturer-spec.ts +++ b/spec-main/api-desktop-capturer-spec.ts @@ -17,7 +17,7 @@ ifdescribe(!process.arch.includes('arm') && process.platform !== 'win32')('deskt let w: BrowserWindow; 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'); }); @@ -96,7 +96,7 @@ ifdescribe(!process.arch.includes('arm') && process.platform !== 'win32')('deskt }); 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'); w2.show(); await wShown; @@ -116,7 +116,7 @@ ifdescribe(!process.arch.includes('arm') && process.platform !== 'win32')('deskt }); 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 wFocused = emittedOnce(w, 'focus'); w.show(); diff --git a/spec-main/api-ipc-main-spec.ts b/spec-main/api-ipc-main-spec.ts index b63dd7e8c05..614020561f4 100644 --- a/spec-main/api-ipc-main-spec.ts +++ b/spec-main/api-ipc-main-spec.ts @@ -18,7 +18,8 @@ describe('ipc main module', () => { const w = new BrowserWindow({ show: false, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); ipcMain.once('send-sync-message', (event) => { @@ -32,7 +33,8 @@ describe('ipc main module', () => { const w = new BrowserWindow({ show: false, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); ipcMain.on('send-sync-message', (event) => { @@ -72,7 +74,8 @@ describe('ipc main module', () => { const w = new BrowserWindow({ show: false, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); w.loadURL('about:blank'); diff --git a/spec-main/api-ipc-renderer-spec.ts b/spec-main/api-ipc-renderer-spec.ts index c07fb34513f..6e09796a3ce 100644 --- a/spec-main/api-ipc-renderer-spec.ts +++ b/spec-main/api-ipc-renderer-spec.ts @@ -9,7 +9,7 @@ describe('ipcRenderer module', () => { let w: BrowserWindow; 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'); }); after(async () => { diff --git a/spec-main/api-ipc-spec.ts b/spec-main/api-ipc-spec.ts index f8181a641f2..a67372bcd8d 100644 --- a/spec-main/api-ipc-spec.ts +++ b/spec-main/api-ipc-spec.ts @@ -11,7 +11,7 @@ describe('ipc module', () => { let w = (null as unknown as BrowserWindow); 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'); }); after(async () => { @@ -125,7 +125,7 @@ describe('ipc module', () => { let w = (null as unknown as BrowserWindow); 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'); }); after(async () => { @@ -202,7 +202,7 @@ describe('ipc module', () => { afterEach(closeAllWindows); 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'); const p = emittedOnce(ipcMain, 'port'); await w.webContents.executeJavaScript(`(${function () { @@ -217,7 +217,7 @@ describe('ipc module', () => { }); 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'); const p = emittedOnce(ipcMain, 'port'); 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 () => { - const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); + const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } }); w.loadURL('about:blank'); function fn () { const channel1 = new MessageChannel(); @@ -256,8 +256,8 @@ describe('ipc module', () => { }); it('can forward a port from one renderer to another renderer', async () => { - const w1 = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); - const w2 = 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, contextIsolation: false } }); w1.loadURL('about:blank'); w2.loadURL('about:blank'); w1.webContents.executeJavaScript(`(${function () { @@ -281,7 +281,7 @@ describe('ipc module', () => { describe('close event', () => { describe('in renderer', () => { 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'); await w.webContents.executeJavaScript(`(${function () { 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 () => { - const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); + const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } }); w.loadURL('about:blank'); await w.webContents.executeJavaScript(`(${async function () { 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 () => { - const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); + const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } }); w.loadURL('about:blank'); ipcMain.once('do-a-gc', () => v8Util.requestGarbageCollectionForTesting()); await w.webContents.executeJavaScript(`(${async function () { @@ -345,7 +345,7 @@ describe('ipc module', () => { }); 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'); await w.webContents.executeJavaScript(`(${function () { const { ipcRenderer } = require('electron'); @@ -363,7 +363,7 @@ describe('ipc module', () => { }); 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'); await w.webContents.executeJavaScript(`(${function () { const { ipcRenderer } = require('electron'); @@ -452,7 +452,7 @@ describe('ipc module', () => { const generateTests = (title: string, postMessage: (contents: WebContents) => typeof WebContents.prototype.postMessage) => { describe(title, () => { 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'); await w.webContents.executeJavaScript(`(${function () { const { ipcRenderer } = require('electron'); diff --git a/spec-main/api-protocol-spec.ts b/spec-main/api-protocol-spec.ts index 207ae36872d..54483eb98a0 100644 --- a/spec-main/api-protocol-spec.ts +++ b/spec-main/api-protocol-spec.ts @@ -987,7 +987,7 @@ describe('protocol module', () => { await registerStreamProtocol(standardScheme, 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 { newContents.loadURL(testingScheme + '://fake-host'); const [, response] = await emittedOnce(ipcMain, 'result'); diff --git a/spec-main/api-remote-spec.ts b/spec-main/api-remote-spec.ts index 67685e7463f..e9934a73e5f 100644 --- a/spec-main/api-remote-spec.ts +++ b/spec-main/api-remote-spec.ts @@ -49,7 +49,7 @@ function makeRemotely (windowGetter: () => BrowserWindow) { function makeWindow () { let w: BrowserWindow; 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.webContents.executeJavaScript(`{ const chai_1 = window.chai_1 = require('chai') @@ -65,7 +65,7 @@ function makeWindow () { function makeEachWindow () { let w: BrowserWindow; 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.webContents.executeJavaScript(`{ const chai_1 = window.chai_1 = require('chai') @@ -333,7 +333,8 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { show: false, webPreferences: { preload, - enableRemoteModule: true + enableRemoteModule: true, + contextIsolation: false } }); w.loadURL('about:blank'); @@ -347,7 +348,8 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { show: false, webPreferences: { nodeIntegration: true, - enableRemoteModule: true + enableRemoteModule: true, + contextIsolation: false } }); @@ -434,7 +436,8 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { show: false, webPreferences: { nodeIntegration: true, - enableRemoteModule: true + enableRemoteModule: true, + contextIsolation: false } }); await w.loadFile(path.join(fixtures, 'remote-event-handler.html')); diff --git a/spec-main/api-session-spec.ts b/spec-main/api-session-spec.ts index f7505eacd2e..295acdd16f6 100644 --- a/spec-main/api-session-spec.ts +++ b/spec-main/api-session-spec.ts @@ -328,7 +328,8 @@ describe('session module', () => { show: false, webPreferences: { partition: partitionName, - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); customSession = session.fromPartition(partitionName); @@ -999,7 +1000,8 @@ describe('session module', () => { show: false, webPreferences: { partition: 'very-temp-permision-handler', - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); diff --git a/spec-main/api-subframe-spec.ts b/spec-main/api-subframe-spec.ts index 9fe962f393b..7eeb775e5b0 100644 --- a/spec-main/api-subframe-spec.ts +++ b/spec-main/api-subframe-spec.ts @@ -121,7 +121,7 @@ describe('renderer nodeIntegrationInSubFrames', () => { const senders = details.map(event => event[0].sender); const isolatedGlobals = await Promise.all(senders.map(sender => sender.executeJavaScript('window.isolatedGlobal'))); for (const result of isolatedGlobals) { - if (webPreferences.contextIsolation) { + if (webPreferences.contextIsolation === undefined || webPreferences.contextIsolation) { expect(result).to.be.undefined(); } else { expect(result).to.equal(true); @@ -167,8 +167,8 @@ describe('renderer nodeIntegrationInSubFrames', () => { webPreferences: { sandbox: true } }, { - name: 'context isolation', - webPreferences: { contextIsolation: true } + name: 'context isolation disabled', + webPreferences: { contextIsolation: false } }, { name: 'webview', @@ -190,7 +190,8 @@ describe('renderer nodeIntegrationInSubFrames', () => { webPreferences: { preload: path.resolve(__dirname, 'fixtures/sub-frames/webview-iframe-preload.js'), nodeIntegrationInSubFrames: true, - webviewTag: true + webviewTag: true, + contextIsolation: false } }); }); diff --git a/spec-main/api-web-contents-spec.ts b/spec-main/api-web-contents-spec.ts index 2b9694f2832..d0e113eeff4 100644 --- a/spec-main/api-web-contents-spec.ts +++ b/spec-main/api-web-contents-spec.ts @@ -194,7 +194,7 @@ describe('webContents module', () => { let w: BrowserWindow; before(async () => { - w = new BrowserWindow({ show: false }); + w = new BrowserWindow({ show: false, webPreferences: { contextIsolation: false } }); await w.loadURL('about:blank'); }); after(closeAllWindows); @@ -516,7 +516,7 @@ describe('webContents module', () => { describe('before-input-event event', () => { afterEach(closeAllWindows); 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')); const keyDown = new Promise(resolve => { ipcMain.once('keydown', (event, key) => resolve(key)); @@ -657,7 +657,7 @@ describe('webContents module', () => { describe('sendInputEvent(event)', () => { let w: BrowserWindow; 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')); }); afterEach(closeAllWindows); @@ -950,7 +950,7 @@ describe('webContents module', () => { }); 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; ipcMain.on('set-zoom', (e, host) => { const zoomLevel = hostZoomMap[host]; @@ -1070,7 +1070,7 @@ describe('webContents module', () => { }); 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 temporaryZoomSet = emittedOnce(ipcMain, 'temporary-zoom-set'); @@ -1111,7 +1111,7 @@ describe('webContents module', () => { }); 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 {ipcRenderer, webFrame} = require('electron') webFrame.setZoomLevel(0.6) @@ -1423,7 +1423,7 @@ describe('webContents module', () => { describe('ipc-message event', () => { afterEach(closeAllWindows); 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'); w.webContents.executeJavaScript(` require('electron').ipcRenderer.send('message', 'Hello World!') @@ -1438,7 +1438,7 @@ describe('webContents module', () => { describe('ipc-message-sync event', () => { afterEach(closeAllWindows); 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'); const promise: Promise<[string, string]> = new Promise(resolve => { w.webContents.once('ipc-message-sync', (event, channel, arg) => { @@ -1865,7 +1865,7 @@ describe('webContents module', () => { afterEach(closeAllWindows); 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'); 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 () => { - 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'); w.loadFile(path.join(fixturesPath, 'api', 'shared-worker', 'shared-worker.html')); diff --git a/spec-main/api-web-frame-spec.ts b/spec-main/api-web-frame-spec.ts index 6c969013169..bf75679c2a6 100644 --- a/spec-main/api-web-frame-spec.ts +++ b/spec-main/api-web-frame-spec.ts @@ -48,7 +48,8 @@ describe('webFrame module', () => { const w = new BrowserWindow({ show: false, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); await w.loadFile(path.join(fixtures, 'pages', 'webframe-spell-check.html')); diff --git a/spec-main/api-web-request-spec.ts b/spec-main/api-web-request-spec.ts index 100ad8b2676..7bf6f32d0d7 100644 --- a/spec-main/api-web-request-spec.ts +++ b/spec-main/api-web-request-spec.ts @@ -495,7 +495,8 @@ describe('webRequest module', () => { const contents = (webContents as any).create({ session: ses, nodeIntegration: true, - webSecurity: false + webSecurity: false, + contextIsolation: false }); // Cleanup. diff --git a/spec-main/asar-spec.ts b/spec-main/asar-spec.ts index 1cc45a1fa5b..f63ae0ecbf6 100644 --- a/spec-main/asar-spec.ts +++ b/spec-main/asar-spec.ts @@ -21,7 +21,8 @@ describe('asar package', () => { width: 400, height: 400, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); const p = path.resolve(asarDir, 'web.asar', 'index.html'); @@ -41,7 +42,8 @@ describe('asar package', () => { width: 400, height: 400, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); const p = path.resolve(asarDir, 'script.asar', 'index.html'); @@ -63,7 +65,8 @@ describe('asar package', () => { width: 400, height: 400, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); const p = path.resolve(asarDir, 'video.asar', 'index.html'); diff --git a/spec-main/chromium-spec.ts b/spec-main/chromium-spec.ts index 4d5ef17e7a4..7d30afddb03 100644 --- a/spec-main/chromium-spec.ts +++ b/spec-main/chromium-spec.ts @@ -89,7 +89,7 @@ describe('window.postMessage', () => { for (const nativeWindowOpen of [true, false]) { describe(`when nativeWindowOpen: ${nativeWindowOpen}`, () => { 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`); const [, message] = await emittedOnce(ipcMain, 'complete'); expect(message.data).to.equal('testing'); @@ -110,7 +110,8 @@ describe('focus handling', () => { show: true, webPreferences: { 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 () => { - 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'); await w.loadURL(`data:text/html,