-
Notifications
You must be signed in to change notification settings - Fork 16.2k
fix: window.open doesn't work correctly in child window #25080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1156,6 +1156,10 @@ describe('webContents module', () => { | |
res.end(); | ||
} else if (req.url === '/redirected') { | ||
res.end('<html><script>window.localStorage</script></html>'); | ||
} else if (req.url === '/first-window-open') { | ||
res.end(`<html><script>window.open('${serverUrl}/second-window-open', 'first child');</script></html>`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this have to open another child window in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that and it didn't work (i.e. problem doesn't reproduce). It should reproduce if there would be redirection from http to https (first reproduction and the most probable in normal usage was on http://www.google.com which redirects to https://www.google.com) but to achieve it in the test it would be necessary to start https server with valid certificate next to http server. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the protocol doesn't matter here |
||
} else if (req.url === '/second-window-open') { | ||
res.end('<html><script>window.open(\'wrong://url\', \'second child\');</script></html>'); | ||
} else { | ||
res.end(); | ||
} | ||
|
@@ -1192,6 +1196,27 @@ describe('webContents module', () => { | |
expect(currentRenderViewDeletedEmitted).to.be.false('current-render-view-deleted was emitted'); | ||
}); | ||
|
||
it('does not emit current-render-view-deleted when speculative RVHs are deleted and nativeWindowOpen is set to true', async () => { | ||
const parentWindow = new BrowserWindow({ show: false, webPreferences: { nativeWindowOpen: true } }); | ||
let currentRenderViewDeletedEmitted = false; | ||
let childWindow:BrowserWindow; | ||
const destroyed = emittedOnce(parentWindow.webContents, 'destroyed'); | ||
const renderViewDeletedHandler = () => { | ||
currentRenderViewDeletedEmitted = true; | ||
}; | ||
app.once('browser-window-created', (event, window) => { | ||
childWindow = window; | ||
window.webContents.on('current-render-view-deleted' as any, renderViewDeletedHandler); | ||
}); | ||
parentWindow.loadURL(`${serverUrl}/first-window-open`); | ||
setTimeout(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we listen on navigation events on the childWindow before closing the parentWindow ? In this case it would be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've checked that There was a problem hiding t 7467 his comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @deepak1556 FWIW... it appears you are right as WOA is now failing on this test fairly regularly: |
||
childWindow.webContents.removeListener('current-render-view-deleted' as any, renderViewDeletedHandler); | ||
parentWindow.close(); | ||
}, 500); | ||
await destroyed; | ||
expect(currentRenderViewDeletedEmitted).to.be.false('child window was destroyed'); | ||
}); | ||
|
||
it('emits current-render-view-deleted if the current RVHs are deleted', async () => { | ||
const w = new BrowserWindow({ show: false }); | ||
let currentRenderViewDeletedEmitted = false; | ||
|
Uh oh!
There was an error while loading. Please reload this page.