-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Links with external protocol in "new-window" event becomes "about:blank" #1458
Comments
It looks like a bug to me. |
I think this came up again. Can anyone confirm? |
This happens to me. My app renders google drive inside an webview. When I click on the "print" button in the document preview, I get this as url: "about:blank" |
Same here. I get "about:blank" as the url. |
I'm also seeing this bug. Incidentally, if the user clicks the middle mouse button (linux at least) the new-window event issued from that action has the correct url listed. As a workaround for this issue, you can do the following: -
var clientX, clientY; // somewhere not local to the onmousedown handler
//...
// Inside the onmousedown handler
clientX = event.clientX; clientY = event.clientY;
// where 'event' is the parameter passed into the handler.
// inside (or called from) the new-window event handler.
var wv = document.getElementById('my-webview');
var bbox = wv.getBoundingClientRect();
var guestPageX = clientX - bbox.left;
var guestPageY = clientY - bbox.top;
wv.executeJavaScript
("document.elementFromPoint(".concat(guestPageX, ",", guestPageY, ")['href']",
false,
(realURL) => {
// do the normal thing with realURL, Hurray!
}); This approach is working reliably for me, but, I need to declare here that I'm actually working in clojurescript within the re-frame framework inside electron. So, the above is a translation of what I'm doing, and is not my actual code -- caveat emptor! |
This is actually still a problem. I tried to get with iohook the click coordinates and the anchor clicked but this doesn't work when the page is scrollable as iohook returns screenX and screenY but elementFromPoint needs pageX and pageY. Until now I couldn't find a solution for this problem. Edit: This was rubber duck style. I found a way better solution at least for my use case. As the window.open function works properly I added an event listener to call window open when clicking links. On the new-tab event I only call openExternal when url is not blank or about:blank. win.webContents.on('dom-ready', function() {
const script = `document.addEventListener('click', event => {
if (event.target.tagName === 'A') {
event.preventDefault();
window.open(event.target.href);
}
});`;
win.webContents.executeJavaScript(script, false);
});
win.webContents.on('new-window', (event, url) => {
event.preventDefault();
if (url && url !== 'about:blank') {
shell.openExternal(url);
}
}); |
I'm still seeing this. If i do something like: webview.addEventListener('new-window', (e) => console.log(e.url)) I get |
Really need to figure out how to resolve this issue. Any updates or workarounds? My specific case is a javascript triggered window.open() so i can't hijack the a link |
I have an embedded
webview
that contains a link, like this:And am trying to handle that link externally using the
new-window
event:Unfortunately,
e.url
in this case is just"about:blank"
and the source element is thewebview
. So I don't have a simple way to get at the originalhref
, and all of our protocol links are dead. Would it be reasonable to modify thenew-window
event to include more information (e.g., the source link)?The text was updated successfully, but these errors were encountered: