I have simple electron.js application, electron-quick-start in which I am using <webview>.
By default links in which target=_blank is set does not open inside webview.
There is some workaround by listening to new-window event given at Can't open Electron webview links with target = blank
But this workaround does not work when nativeWindowOpen: true in webPreferences in parent window. Rather application get crashed when I am adding allowpopups on MacOS with error exited with signal SIGSEGV
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
webviewTag: true,
nativeWindowOpen: true // This flag is not letting recieve new-window event from webview
}
})
index.html is
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<webview id="foo" src="https://www.w3schools.com/tags/att_a_target.asp" style="display:inline-flex; width:640px; height:480px" allowpopups></webview>
<h1>click on Try it yuorself button in webview</h1>
<!-- You can also require other files to run in this process -->
<!-- <script src="./renderer.js"></script> -->
</body>
</html>
How can I get webview links where target=_blank working keeping nativeWindowOpen: true in parent window?
nativeWindowOpen is going to be set true by default according to Planned Breaking API Changes (15.0)
I've tried and write a gist with Electron fiddle. Perhaps I didn't catch your problem but for me it's working https://gist.github.com/deb6ed0fa37860fdfc0d51c6782f4152
This was a bug https://github.com/electron/electron/pull/29874 which got fixed.
electron version 12.0.14 or higher is working fine for this problem.