Electron uses its own version of window.open, which always returns null (does not return a handle to the window). There's now an option (nativeWindowOpen) to use the native window.open, which gets external links to work (opening a new Electron window), but if you need to open external links in the default browser instead, there's no way to get the URL Monaco is attempting to open. The initial window.open() request will trigger new-window, but without the url in that call, it's a dead end.
The upshot is, if you're using the common pattern of hooking to the new-window event to trap external links and open them in the default browser, "Follow Link" will silently fail (or, on Windows, open a dialog saying you have to choose an app to open "this about link", presumably because it doesn't have a default handler registered for "about:blank").
I unfortunately found this extremely hard to work around, because there's just no way to get the requested URL if the Opener receives a null in response to window.open. At one point I resorted to adding a click event to the editor DOM and checking to see if the click took place on a detected-link-active. 😰 I also tried the hack of allowing the window to open and listening for will-navigate events on it, then closing it and going to the requested URL; but since there's no way to modify the options on the initial window.open, it can't be loaded as a hidden window, so the user would see it open and immediately close before opening the browser window.
Adding "Electron" to the user-agent / platform detection and another boolean here would fix the problem.
Alternatively, maybe we could use some kind of option to toggle this behavior back to the plain window.open(url).
n.b. there are apparently Electron changes in the pipeline that will make this easier to work around, but it would still be good not to have to hack around it. electron/electron#24517
monaco-editor version: 0.20.0 Browser: Electron 9.1.0 (tested in 10 and 11-beta as well) OS: OSX Catalina, also reproduced on Windows 10 Playground code that reproduces the issue:
( Any that contains a detectable link )
Electron external window setup:
mainWindow.webContents.on('new-window', function (event, linkUrl) {
event.preventDefault();
shell.openExternal(linkUrl);
});
The text was updated successfully, but these errors were encountered:
TL;DR: I just resorted to spoofing the User-Agent in Electron to get🤦♀️
window.openworking with external windows.Similar issue to: #628
Electron uses its own version of
window.open, which always returnsnull(does not return a handle to the window). There's now an option (nativeWindowOpen) to use the nativewindow.open, which gets external links to work (opening a new Electron window), but if you need to open external links in the default browser instead, there's no way to get the URL Monaco is attempting to open. The initialwindow.open()request will triggernew-window, but without theurlin that call, it's a dead end.The upshot is, if you're using the common pattern of hooking to the
new-windowevent to trap external links and open them in the default browser, "Follow Link" will silently fail (or, on Windows, open a dialog saying you have to choose an app to open "this about link", presumably because it doesn't have a default handler registered for "about:blank").I unfortunately found this extremely hard to work around, because there's just no way to get the requested URL if the Opener receives a😰 I also tried the hack of allowing the window to open and listening for
nullin response towindow.open. At one point I resorted to adding aclickevent to the editor DOM and checking to see if the click took place on adetected-link-active.will-navigateevents on it, then closing it and going to the requested URL; but since there's no way to modify the options on the initialwindow.open, it can't be loaded as a hidden window, so the user would see it open and immediately close before opening the browser window.Adding "Electron" to the user-agent / platform detection and another boolean here would fix the problem.
Alternatively, maybe we could use some kind of option to toggle this behavior back to the plain
window.open(url).My terrible hacks and eventual user-agent "fix" are here: Automattic/simplenote-electron#2470
n.b. there are apparently Electron changes in the pipeline that will make this easier to work around, but it would still be good not to have to hack around it. electron/electron#24517
monaco-editor version: 0.20.0
Browser: Electron 9.1.0 (tested in 10 and 11-beta as well)
OS: OSX Catalina, also reproduced on Windows 10
Playground code that reproduces the issue:
( Any that contains a detectable link )
Electron external window setup:
The text was updated successfully, but these errors were encountered: