fix: crash when using vm after window.open()
#37506
Backport Failed
This PR was checked and could not be automatically backported to "23-x-y" cleanly
Details
Failed Diff:
diff --cc spec/guest-window-manager-spec.ts
index d3d8f2b626,159771d18f..0000000000
--- a/spec/guest-window-manager-spec.ts
+++ b/spec/guest-window-manager-spec.ts
@@@ -173,20 -173,48 +173,53 @@@ describe('webContents.setWindowOpenHand
browserWindow.webContents.executeJavaScript("window.open('about:blank', '', 'show=no') && true");
});
- await once(browserWindow.webContents, 'did-create-window');
+ await emittedOnce(browserWindow.webContents, 'did-create-window');
});
++<<<<<<< HEAD
+ it('can change webPreferences of child windows', (done) => {
++=======
+ it('does not crash when used in conjunction with the vm module', async () => {
+ const w = new BrowserWindow({
+ show: false,
+ webPreferences: {
+ contextIsolation: false,
+ nodeIntegration: true
+ }
+ });
+
+ await w.loadURL('about:blank');
+
+ const didCreateWindow = once(w.webContents, 'did-create-window');
+ w.webContents.executeJavaScript("window.open('')");
+ await didCreateWindow;
+
+ const result = await w.webContents.executeJavaScript(`
+ const vm = require('node:vm')
+ const run = () => {
+ const context = { x: 2 }
+ vm.createContext(context)
+ vm.runInContext('x += 40', context)
+ return context.x
+ }
+ run()
+ `);
+
+ expect(result).to.equal(42);
+ });
+
+ it('can change webPreferences of child windows', async () => {
++>>>>>>> fix: crash when using vm after window.open()
browserWindow.webContents.setWindowOpenHandler(() => ({ action: 'allow', overrideBrowserWindowOptions: { webPreferences: { defaultFontSize: 30 } } }));
- const didCreateWindow = once(browserWindow.webContents, 'did-create-window');
- browserWindow.webContents.executeJavaScript("window.open('about:blank', '', 'show=no') && true");
- const [childWindow] = await didCreateWindow;
+ browserWindow.webContents.on('did-create-window', async (childWindow) => {
+ await childWindow.webContents.executeJavaScript("document.write('hello')");
+ const size = await childWindow.webContents.executeJavaScript("getComputedStyle(document.querySelector('body')).fontSize");
+ expect(size).to.equal('30px');
+ done();
+ });
- await childWindow.webContents.executeJavaScript("document.write('hello')");
- const size = await childWindow.webContents.executeJavaScript("getComputedStyle(document.querySelector('body')).fontSize");
- expect(size).to.equal('30px');
+ browserWindow.webContents.executeJavaScript("window.open('about:blank', '', 'show=no') && true");
});
it('does not hang parent window when denying window.open', async () => {
Annotations
Check failure on line 180 in spec/guest-window-manager-spec.ts
trop / Backportable? - 23-x-y
spec/guest-window-manager-spec.ts#L180
Patch Conflict
Raw output
++<<<<<<< HEAD
+ it('can change webPreferences of child windows', (done) => {
++=======
+ it('does not crash when used in conjunction with the vm module', async () => {
+ const w = new BrowserWindow({
+ show: false,
+ webPreferences: {
+ contextIsolation: false,
+ nodeIntegration: true
+ }
+ });
+
+ await w.loadURL('about:blank');
+
+ const didCreateWindow = once(w.webContents, 'did-create-window');
+ w.webContents.executeJavaScript("window.open('')");
+ await didCreateWindow;
+
+ const result = await w.webContents.executeJavaScript(`
+ const vm = require('node:vm')
+ const run = () => {
+ const context = { x: 2 }
+ vm.createContext(context)
+ vm.runInContext('x += 40', context)
+ return context.x
+ }
+ run()
+ `);
+
+ expect(result).to.equal(42);
+ });
+
+ it('can change webPreferences of child windows', async () => {
++>>>>>>> fix: crash when using vm after window.open()
Check failure on line 180 in spec/guest-window-manager-spec.ts
trop / Backportable? - 23-x-y
spec/guest-window-manager-spec.ts#L180
Patch Conflict
Raw output
++<<<<<<< HEAD
+ it('can change webPreferences of child windows', (done) => {
++=======
+ it('does not crash when used in conjunction with the vm module', async () => {
+ const w = new BrowserWindow({
+ show: false,
+ webPreferences: {
+ contextIsolation: false,
+ nodeIntegration: true
+ }
+ });
+
+ await w.loadURL('about:blank');
+
+ const didCreateWindow = once(w.webContents, 'did-create-window');
+ w.webContents.executeJavaScript("window.open('')");
+ await didCreateWindow;
+
+ const result = await w.webContents.executeJavaScript(`
+ const vm = require('node:vm')
+ const run = () => {
+ const context = { x: 2 }
+ vm.createContext(context)
+ vm.runInContext('x += 40', context)
+ return context.x
+ }
+ run()
+ `);
+
+ expect(result).to.equal(42);
+ });
+
+ it('can change webPreferences of child windows', async () => {
++>>>>>>> fix: crash when using vm after window.open()
Check failure on line 180 in spec/guest-window-manager-spec.ts
trop / Backportable? - 23-x-y
spec/guest-window-manager-spec.ts#L180
Patch Conflict
Raw output
++<<<<<<< HEAD
+ it('can change webPreferences of child windows', (done) => {
++=======
+ it('does not crash when used in conjunction with the vm module', async () => {
+ const w = new BrowserWindow({
+ show: false,
+ webPreferences: {
+ contextIsolation: false,
+ nodeIntegration: true
+ }
+ });
+
+ await w.loadURL('about:blank');
+
+ const didCreateWindow = once(w.webContents, 'did-create-window');
+ w.webContents.executeJavaScript("window.open('')");
+ await didCreateWindow;
+
+ const result = await w.webContents.executeJavaScript(`
+ const vm = require('node:vm')
+ const run = () => {
+ const context = { x: 2 }
+ vm.createContext(context)
+ vm.runInContext('x += 40', context)
+ return context.x
+ }
+ run()
+ `);
+
+ expect(result).to.equal(42);
+ });
+
+ it('can change webPreferences of child windows', async () => {
++>>>>>>> fix: crash when using vm after window.open()
Check failure on line 180 in spec/guest-window-manager-spec.ts
trop / Backportable? - 23-x-y
spec/guest-window-manager-spec.ts#L180
Patch Conflict
Raw output
++<<<<<<< HEAD
+ it('can change webPreferences of child windows', (done) => {
++=======
+ it('does not crash when used in conjunction with the vm module', async () => {
+ const w = new BrowserWindow({
+ show: false,
+ webPreferences: {
+ contextIsolation: false,
+ nodeIntegration: true
+ }
+ });
+
+ await w.loadURL('about:blank');
+
+ const didCreateWindow = once(w.webContents, 'did-create-window');
+ w.webContents.executeJavaScript("window.open('')");
+ await didCreateWindow;
+
+ const result = await w.webContents.executeJavaScript(`
+ const vm = require('node:vm')
+ const run = () => {
+ const context = { x: 2 }
+ vm.createContext(context)
+ vm.runInContext('x += 40', context)
+ return context.x
+ }
+ run()
+ `);
+
+ expect(result).to.equal(42);
+ });
+
+ it('can change webPreferences of child windows', async () => {
++>>>>>>> fix: crash when using vm after window.open()