Noticed some strange Electron <webview>
behavior while working on a proof-of-concept for the next version of Doctrine.
I have a simple page with a <webview>
tag displaying a local HTML file. If the local HTML file contains a link and the user clicks on it, the default browser should open the URL instead of the <webview>
.
The following code produces the expected results:
webview.addEventListener('will-navigate', (event) => {
// Order is important or URL will open in both external browser and webview!
shell.openExternal(event.url); // Must be first!
webview.stop(); // Must be second!
// event.preventDefault(); // Has no effect...
});
The following is odd about this code:
- The
event.preventDefault()
call seems to have no effect no matter where it is placed. Would think that this call should prevent the<webview>
from loading the URL but it does not. - The
webview.stop()
call must be after theshell.openExternal()
call. This seems weird; no mention of such behavior in the documentation.
Thinking this may warrant opening a bug report...
For context, here is the output of console.log(process.versions)
for my development environment:
ares : "1.10.1-DEV"
atom-shell : "1.3.0"
chrome : "52.0.2743.82"
electron : "1.3.0"
http_parser : "2.7.0"
modules : "49"
node : "6.3.0"
openssl : "1.0.2h"
uv : "1.9.1"
v8 : "5.2.361.43"
zlib : "1.2.8"