fix: createWindow
shouldn't load URL for webContents
(#43816)
* fix: createWindow shouldn't load URL for webContents Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * chore: add non about blank test Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
parent
3232505c55
commit
45a7a5d22c
2 changed files with 30 additions and 8 deletions
|
@ -71,14 +71,6 @@ export function openGuestWindow ({ embedder, guest, referrer, disposition, postD
|
||||||
throw new Error('Invalid webContents. Created window should be connected to webContents passed with options object.');
|
throw new Error('Invalid webContents. Created window should be connected to webContents passed with options object.');
|
||||||
}
|
}
|
||||||
|
|
||||||
webContents.loadURL(url, {
|
|
||||||
httpReferrer: referrer,
|
|
||||||
...(postData && {
|
|
||||||
postData,
|
|
||||||
extraHeaders: formatPostDataHeaders(postData as Electron.UploadRawData[])
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
handleWindowLifecycleEvents({ embedder, frameName, guest, outlivesOpener });
|
handleWindowLifecycleEvents({ embedder, frameName, guest, outlivesOpener });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -231,6 +231,10 @@ describe('webContents.setWindowOpenHandler', () => {
|
||||||
response.statusCode = 200;
|
response.statusCode = 200;
|
||||||
response.end('<title>Child page</title>');
|
response.end('<title>Child page</title>');
|
||||||
break;
|
break;
|
||||||
|
case '/test':
|
||||||
|
response.statusCode = 200;
|
||||||
|
response.end('<title>Test page</title>');
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unsupported endpoint: ${request.url}`);
|
throw new Error(`Unsupported endpoint: ${request.url}`);
|
||||||
}
|
}
|
||||||
|
@ -303,6 +307,32 @@ describe('webContents.setWindowOpenHandler', () => {
|
||||||
expect(childWindow.title).to.equal(browserWindowTitle);
|
expect(childWindow.title).to.equal(browserWindowTitle);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be able to access the child window document when createWindow is provided', async () => {
|
||||||
|
browserWindow.webContents.setWindowOpenHandler(() => {
|
||||||
|
return {
|
||||||
|
action: 'allow',
|
||||||
|
createWindow: (options) => {
|
||||||
|
const child = new BrowserWindow(options);
|
||||||
|
return child.webContents;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const aboutBlankTitle = await browserWindow.webContents.executeJavaScript(`
|
||||||
|
const win1 = window.open('about:blank', '', 'show=no');
|
||||||
|
win1.document.title = 'about-blank-title';
|
||||||
|
win1.document.title;
|
||||||
|
`);
|
||||||
|
expect(aboutBlankTitle).to.equal('about-blank-title');
|
||||||
|
|
||||||
|
const serverPageTitle = await browserWindow.webContents.executeJavaScript(`
|
||||||
|
const win2 = window.open('${url}/child', '', 'show=no');
|
||||||
|
win2.document.title = 'server-page-title';
|
||||||
|
win2.document.title;
|
||||||
|
`);
|
||||||
|
expect(serverPageTitle).to.equal('server-page-title');
|
||||||
|
});
|
||||||
|
|
||||||
it('spawns browser window with overridden options', async () => {
|
it('spawns browser window with overridden options', async () => {
|
||||||
const childWindow = await new Promise<Electron.BrowserWindow>(resolve => {
|
const childWindow = await new Promise<Electron.BrowserWindow>(resolve => {
|
||||||
browserWindow.webContents.setWindowOpenHandler(() => {
|
browserWindow.webContents.setWindowOpenHandler(() => {
|
||||||
|
|
Loading…
Reference in a new issue