fix: crash when focusing WebView webContents (#43932)

fix: crash when focusing WebView

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:
trop[bot] 2024-09-25 06:16:49 -05:00 committed by GitHub
parent 1af736bc15
commit d2bd4cf91c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View file

@ -1206,6 +1206,22 @@ describe('webContents module', () => {
expect(currentFocused).to.be.true();
expect(childFocused).to.be.false();
});
it('does not crash when focusing a WebView webContents', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
webviewTag: true
}
});
w.show();
await w.loadURL('data:text/html,<webview src="data:text/html,hi"></webview>');
const wc = webContents.getAllWebContents().find((wc) => wc.getType() === 'webview')!;
expect(() => wc.focus()).to.not.throw();
});
});
const moveFocusToDevTools = async (win: BrowserWindow) => {