feat: enable context isolation by default (#26890)
* feat: enable context isolation by default * chore: set default in ctx iso getter * spec: make all specs work with the new contextIsolation default * spec: fix affinity specs * spec: update tests for new ctx iso default * spec: update tests for new ctx iso default * spec: update tests for new ctx iso default * spec: update tests for new ctx iso default * chore: move stray prod deps to dev deps * spec: update tests for new ctx iso default * turn off contextIsolation for visibility tests * turn off contextIsolation for <webview> tag nodeintegration attribute loads native modules when navigation happens Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
parent
2d0ad0b96a
commit
186301e126
37 changed files with 291 additions and 194 deletions
|
@ -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
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue