Browse Source

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 <[email protected]>
Samuel Attard 4 years ago
parent
commit
186301e126
37 changed files with 291 additions and 194 deletions
  1. 2 11
      shell/browser/web_contents_preferences.cc
  2. 16 8
      spec-main/api-app-spec.ts
  3. 22 19
      spec-main/api-browser-window-affinity-spec.ts
  4. 49 27
      spec-main/api-browser-window-spec.ts
  5. 5 5
      spec-main/api-crash-reporter-spec.ts
  6. 3 3
      spec-main/api-desktop-capturer-spec.ts
  7. 6 3
      spec-main/api-ipc-main-spec.ts
  8. 1 1
      spec-main/api-ipc-renderer-spec.ts
  9. 13 13
      spec-main/api-ipc-spec.ts
  10. 1 1
      spec-main/api-protocol-spec.ts
  11. 8 5
      spec-main/api-remote-spec.ts
  12. 4 2
      spec-main/api-session-spec.ts
  13. 5 4
      spec-main/api-subframe-spec.ts
  14. 10 10
      spec-main/api-web-contents-spec.ts
  15. 2 1
      spec-main/api-web-frame-spec.ts
  16. 2 1
      spec-main/api-web-request-spec.ts
  17. 6 3
      spec-main/asar-spec.ts
  18. 45 29
      spec-main/chromium-spec.ts
  19. 5 5
      spec-main/extensions-spec.ts
  20. 3 2
      spec-main/fixtures/apps/crash/main.js
  21. 6 1
      spec-main/fixtures/snapshots/native-window-open.snapshot.txt
  22. 5 0
      spec-main/fixtures/snapshots/proxy-window-open.snapshot.txt
  23. 1 1
      spec-main/fixtures/sub-frames/frame-container-webview.html
  24. 1 0
      spec-main/fixtures/sub-frames/webview-iframe-preload.js
  25. 3 3
      spec-main/modules-spec.ts
  26. 4 3
      spec-main/security-warnings-spec.ts
  27. 2 1
      spec-main/spellchecker-spec.ts
  28. 2 1
      spec-main/visibility-state-spec.ts
  29. 34 21
      spec-main/webview-spec.ts
  30. 2 1
      spec/chromium-spec.js
  31. 1 1
      spec/fixtures/api/loaded-from-dataurl.js
  32. 2 1
      spec/fixtures/no-proprietary-codecs.js
  33. 1 1
      spec/fixtures/pages/tab-focus-loop-elements.html
  34. 1 1
      spec/fixtures/pages/webview-no-script.html
  35. 1 1
      spec/fixtures/pages/webview-zoom-factor.html
  36. 2 1
      spec/static/main.js
  37. 15 3
      spec/webview-spec.js

+ 2 - 11
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

+ 16 - 8
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');

+ 22 - 19
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<void>((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([

+ 49 - 27
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,<script src="loaded-from-dataurl.js"></script>', { 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,<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');
     });
   });
 
@@ -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
         }
       });
 

+ 5 - 5
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') {

+ 3 - 3
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();

+ 6 - 3
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');

+ 1 - 1
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 () => {

+ 13 - 13
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');

+ 1 - 1
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');

+ 8 - 5
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'));

+ 4 - 2
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
         }
       });
 

+ 5 - 4
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
         }
       });
     });

+ 10 - 10
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'));

+ 2 - 1
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'));

+ 2 - 1
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.

+ 6 - 3
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');

+ 45 - 29
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,<script>
         const s = document.createElement('script')
@@ -244,7 +245,7 @@ describe('web security', () => {
   });
 
   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');
     await w.loadURL(`data:text/html,
       <script>
@@ -255,7 +256,7 @@ describe('web security', () => {
   });
 
   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');
     await w.loadURL(`data:text/html,<script>
         (async function() {
@@ -272,7 +273,7 @@ describe('web security', () => {
   });
 
   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');
     await w.loadURL(`data:text/html,<script>
         (async function() {
@@ -452,7 +453,8 @@ describe('chromium features', () => {
         show: false,
         webPreferences: {
           nodeIntegration: true,
-          partition: 'sw-file-scheme-spec'
+          partition: 'sw-file-scheme-spec',
+          contextIsolation: false
         }
       });
       w.webContents.on('ipc-message', (event, channel, message) => {
@@ -489,7 +491,8 @@ describe('chromium features', () => {
         show: false,
         webPreferences: {
           nodeIntegration: true,
-          session: customSession
+          session: customSession,
+          contextIsolation: false
         }
       });
       w.webContents.on('ipc-message', (event, channel, message) => {
@@ -517,7 +520,8 @@ describe('chromium features', () => {
         webPreferences: {
           nodeIntegration: 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,
         webPreferences: {
           nodeIntegration: true,
-          partition: 'geolocation-spec'
+          partition: 'geolocation-spec',
+          contextIsolation: false
         }
       });
       const message = emittedOnce(w.webContents, 'ipc-message');
@@ -670,7 +675,7 @@ describe('chromium features', () => {
       const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
       w.loadURL('about:blank');
       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 typeofProcessGlobal = await contents.executeJavaScript('typeof process');
@@ -686,7 +691,7 @@ describe('chromium features', () => {
         slashes: true
       });
       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');
       await emittedOnce(contents, 'did-finish-load');
@@ -796,7 +801,8 @@ describe('chromium features', () => {
       const w = new BrowserWindow({
         show: false,
         webPreferences: {
-          nodeIntegration: true
+          nodeIntegration: true,
+          contextIsolation: false
         }
       });
       w.loadFile(path.join(fixturesPath, 'pages', 'window-opener.html'));
@@ -833,7 +839,8 @@ describe('chromium features', () => {
         show: false,
         webPreferences: {
           nodeIntegration: true,
-          session: ses
+          session: ses,
+          contextIsolation: false
         }
       });
       w.loadFile(path.join(fixturesPath, 'pages', 'media-id-reset.html'));
@@ -848,7 +855,8 @@ describe('chromium features', () => {
         show: false,
         webPreferences: {
           nodeIntegration: true,
-          session: ses
+          session: ses,
+          contextIsolation: false
         }
       });
       w.loadFile(path.join(fixturesPath, 'pages', 'media-id-reset.html'));
@@ -916,7 +924,7 @@ describe('chromium features', () => {
         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`;
           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(() => ({
               action: 'allow',
               overrideBrowserWindowOptions: {
@@ -955,7 +963,7 @@ describe('chromium features', () => {
           // We are testing whether context (3) can access context (2) under various conditions.
 
           // 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');
 
           const parentCode = `new Promise((resolve) => {
@@ -969,7 +977,7 @@ describe('chromium features', () => {
             // This is context (2), a WebView which will call window.open()
             const webview = new WebView()
             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.src = ${JSON.stringify(parent + '?p=' + encodeURIComponent(child))}
             webview.addEventListener('dom-ready', async () => {
@@ -1013,7 +1021,8 @@ describe('chromium features', () => {
 
       beforeEach(() => {
         contents = (webContents as any).create({
-          nodeIntegration: true
+          nodeIntegration: true,
+          contextIsolation: false
         });
       });
 
@@ -1145,7 +1154,8 @@ describe('chromium features', () => {
       it('default value allows websql', async () => {
         contents = (webContents as any).create({
           session: sqlSession,
-          nodeIntegration: true
+          nodeIntegration: true,
+          contextIsolation: false
         });
         contents.loadURL(origin);
         const [, error] = await emittedOnce(ipcMain, 'web-sql-response');
@@ -1156,7 +1166,8 @@ describe('chromium features', () => {
         contents = (webContents as any).create({
           session: sqlSession,
           nodeIntegration: true,
-          enableWebSQL: false
+          enableWebSQL: false,
+          contextIsolation: false
         });
         contents.loadURL(origin);
         const [, error] = await emittedOnce(ipcMain, 'web-sql-response');
@@ -1167,7 +1178,8 @@ describe('chromium features', () => {
         contents = (webContents as any).create({
           session: sqlSession,
           nodeIntegration: true,
-          enableWebSQL: false
+          enableWebSQL: false,
+          contextIsolation: false
         });
         contents.loadURL(origin);
         const [, error] = await emittedOnce(ipcMain, 'web-sql-response');
@@ -1196,7 +1208,8 @@ describe('chromium features', () => {
           webPreferences: {
             nodeIntegration: true,
             webviewTag: true,
-            session: sqlSession
+            session: sqlSession,
+            contextIsolation: false
           }
         });
         w.webContents.loadURL(origin);
@@ -1207,7 +1220,7 @@ describe('chromium features', () => {
           new Promise((resolve, reject) => {
             const webview = new WebView();
             webview.setAttribute('src', '${origin}');
-            webview.setAttribute('webpreferences', 'enableWebSQL=0');
+            webview.setAttribute('webpreferences', 'enableWebSQL=0,contextIsolation=no');
             webview.setAttribute('partition', '${sqlPartition}');
             webview.setAttribute('nodeIntegration', 'on');
             document.body.appendChild(webview);
@@ -1225,7 +1238,8 @@ describe('chromium features', () => {
             nodeIntegration: true,
             enableWebSQL: false,
             webviewTag: true,
-            session: sqlSession
+            session: sqlSession,
+            contextIsolation: false
           }
         });
         w.webContents.loadURL('data:text/html,<html></html>');
@@ -1234,7 +1248,7 @@ describe('chromium features', () => {
           new Promise((resolve, reject) => {
             const webview = new WebView();
             webview.setAttribute('src', '${origin}');
-            webview.setAttribute('webpreferences', 'enableWebSQL=1');
+            webview.setAttribute('webpreferences', 'enableWebSQL=1,contextIsolation=no');
             webview.setAttribute('partition', '${sqlPartition}');
             webview.setAttribute('nodeIntegration', 'on');
             document.body.appendChild(webview);
@@ -1251,7 +1265,8 @@ describe('chromium features', () => {
           webPreferences: {
             nodeIntegration: true,
             webviewTag: true,
-            session: sqlSession
+            session: sqlSession,
+            contextIsolation: false
           }
         });
         w.webContents.loadURL(origin);
@@ -1262,7 +1277,7 @@ describe('chromium features', () => {
           new Promise((resolve, reject) => {
             const webview = new WebView();
             webview.setAttribute('src', '${origin}');
-            webview.setAttribute('webpreferences', 'enableWebSQL=1');
+            webview.setAttribute('webpreferences', 'enableWebSQL=1,contextIsolation=no');
             webview.setAttribute('partition', '${sqlPartition}');
             webview.setAttribute('nodeIntegration', 'on');
             document.body.appendChild(webview);
@@ -1406,7 +1421,8 @@ describe('iframe using HTML fullscreen API while window is OS-fullscreened', ()
       fullscreen: true,
       webPreferences: {
         nodeIntegration: true,
-        nodeIntegrationInSubFrames: true
+        nodeIntegrationInSubFrames: true,
+        contextIsolation: false
       }
     });
   });

+ 5 - 5
spec-main/extensions-spec.ts

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

+ 3 - 2
spec-main/fixtures/apps/crash/main.js

@@ -28,7 +28,7 @@ app.whenReady().then(() => {
   if (crashType === 'main') {
     process.crash();
   } 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');
     if (setExtraParameters) {
       w.webContents.executeJavaScript(`
@@ -44,7 +44,8 @@ app.whenReady().then(() => {
       show: false,
       webPreferences: {
         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}`);

+ 6 - 1
spec-main/fixtures/snapshots/native-window-open.snapshot.txt

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

+ 5 - 0
spec-main/fixtures/snapshots/proxy-window-open.snapshot.txt

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

+ 1 - 1
spec-main/fixtures/sub-frames/frame-container-webview.html

@@ -8,6 +8,6 @@
 </head>
 <body>
   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>
 </html>

+ 1 - 0
spec-main/fixtures/sub-frames/webview-iframe-preload.js

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

+ 3 - 3
spec-main/modules-spec.ts

@@ -19,7 +19,7 @@ describe('modules support', () => {
     ifdescribe(nativeModulesEnabled)('echo', () => {
       afterEach(closeAllWindows);
       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');
         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', () => {
       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');
         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', () => {
       afterEach(closeAllWindows);
       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');
         const result = await w.webContents.executeJavaScript('typeof require("q").when');
         expect(result).to.equal('function');

+ 4 - 3
spec-main/security-warnings-spec.ts

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

+ 2 - 1
spec-main/spellchecker-spec.ts

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

+ 2 - 1
spec-main/visibility-state-spec.ts

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

+ 34 - 21
spec-main/webview-spec.ts

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

+ 2 - 1
spec/chromium-spec.js

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

+ 1 - 1
spec/fixtures/api/loaded-from-dataurl.js

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

+ 2 - 1
spec/fixtures/no-proprietary-codecs.js

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

+ 1 - 1
spec/fixtures/pages/tab-focus-loop-elements.html

@@ -20,7 +20,7 @@
     <div>
       <button id="element-1">Button 1</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>
     </div>
   </body>

+ 1 - 1
spec/fixtures/pages/webview-no-script.html

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

+ 1 - 1
spec/fixtures/pages/webview-zoom-factor.html

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

+ 2 - 1
spec/static/main.js

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

+ 15 - 3
spec/webview-spec.js

@@ -112,6 +112,7 @@ describe('<webview> tag', function () {
     it('inserts node symbols when set', async () => {
       const message = await startLoadingWebViewAndWaitForMessage(webview, {
         nodeintegration: 'on',
+        webpreferences: 'contextIsolation=no',
         src: `file://${fixtures}/pages/d.html`
       });
 
@@ -132,6 +133,7 @@ describe('<webview> tag', function () {
 
       const message = await startLoadingWebViewAndWaitForMessage(webview, {
         nodeintegration: 'on',
+        webpreferences: 'contextIsolation=no',
         src: `file://${fixtures}/pages/post.html`
       });
 
@@ -154,6 +156,7 @@ describe('<webview> tag', function () {
       });
       loadWebView(webview, {
         allowpopups: 'on',
+        webpreferences: 'contextIsolation=no',
         src
       });
       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 () {
       await loadWebView(webview, {
         nodeintegration: 'on',
+        webpreferences: 'contextIsolation=no',
         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 () => {
       const message = await startLoadingWebViewAndWaitForMessage(webview, {
         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');
@@ -343,6 +348,7 @@ describe('<webview> tag', function () {
       const message = await startLoadingWebViewAndWaitForMessage(webview, {
         disablewebsecurity: '',
         nodeintegration: 'on',
+        webpreferences: 'contextIsolation=no',
         src: `file://${fixtures}/pages/d.html`
       });
 
@@ -391,6 +397,7 @@ describe('<webview> tag', function () {
       const message = await startLoadingWebViewAndWaitForMessage(webview, {
         nodeintegration: 'on',
         partition: 'test2',
+        webpreferences: 'contextIsolation=no',
         src: `file://${fixtures}/pages/d.html`
       });
 
@@ -464,7 +471,7 @@ describe('<webview> tag', function () {
     it('can enable nodeintegration', async () => {
       const message = await startLoadingWebViewAndWaitForMessage(webview, {
         src: `file://${fixtures}/pages/d.html`,
-        webpreferences: 'nodeIntegration'
+        webpreferences: 'nodeIntegration,contextIsolation=no'
       });
 
       const types = JSON.parse(message);
@@ -493,7 +500,7 @@ describe('<webview> tag', function () {
 
       const message = await startLoadingWebViewAndWaitForMessage(webview, {
         src: `data:text/html;base64,${encoded}`,
-        webpreferences: 'webSecurity=no, nodeIntegration=yes'
+        webpreferences: 'webSecurity=no, nodeIntegration=yes, contextIsolation=no'
       });
 
       expect(message).to.equal('function');
@@ -526,6 +533,7 @@ describe('<webview> tag', function () {
     it('emits when guest sends an ipc message to browser', async () => {
       loadWebView(webview, {
         nodeintegration: 'on',
+        webpreferences: 'contextIsolation=no',
         src: `file://${fixtures}/pages/ipc-message.html`
       });
       const { channel, args } = await waitForEvent(webview, 'ipc-message');
@@ -710,6 +718,7 @@ describe('<webview> tag', function () {
     it('should emit beforeunload handler', async () => {
       await loadWebView(webview, {
         nodeintegration: 'on',
+        webpreferences: 'contextIsolation=no',
         src: `file://${fixtures}/pages/beforeunload-false.html`
       });
 
@@ -821,6 +830,7 @@ describe('<webview> tag', function () {
         });
         loadWebView(webview, {
           nodeintegration: 'on',
+          webpreferences: 'contextIsolation=no',
           src: `file://${fixtures}/pages/basic-auth.html?port=${port}`
         });
       });
@@ -896,6 +906,7 @@ describe('<webview> tag', function () {
     it('can send keyboard event', async () => {
       loadWebView(webview, {
         nodeintegration: 'on',
+        webpreferences: 'contextIsolation=no',
         src: `file://${fixtures}/pages/onkeyup.html`
       });
       await waitForEvent(webview, 'dom-ready');
@@ -915,6 +926,7 @@ describe('<webview> tag', function () {
     it('can send mouse event', async () => {
       loadWebView(webview, {
         nodeintegration: 'on',
+        webpreferences: 'contextIsolation=no',
         src: `file://${fixtures}/pages/onmouseup.html`
       });
       await waitForEvent(webview, 'dom-ready');