You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
[Feature request] window.opener full support #1865
when opening a new window using window.open, we currently get a BrowserWindowProxy that only support posting messages.
Some websites, webapps and libraries uses window.opener to access properties and objects of the opener window. Thoose are broken in Electron.
That's the case for example of Chromium devtools, that use window.open / window.opener in dockable/undockable mode.
Reacted by Andrew Hutchings, Tzelon Machluf, Sandeep Reddy, vandalouze, strarsis, Jean-Baptiste Meunier, Vishwas Shashidhar and ganzhe
In Electron every page is forced to run in its own process, however current architecture requires the pages to run in the same process if you want to access one page's contentWindow from the other, so it is not possible to implement it for now.
Chrome is now working on implementing out of process iframe, when it is done we might be able to implement this.
So since Electron has a strong requirement that each page runs on a separate process, I'm afraid this is not something that we are able to fix under current architecture.
I'm still keeping this open in case someone has an idea on how to fix this.
Hi, I am working on a multi-windows application and I need to share a object instances from the main application process with the other windows of the application. Currently in browser you can reference window.opener to achieve this. In browser window.opener (in child window) will give you the instance of the Window object form which window.opent(myURL) was called.
In Electron when I open window via (window.opent(myURL)) window.opener is replaced with BrowserWindowProxy (Electron API) which does not expose the same window (Window object instance) from which the (window.open(myURL)) was called. Is there a way to access window.opener the same way it works in Browser. I need some hint do you plan to support this in the future and when ?
Using remote.sharedObject (Electron API) is not an option since it only serialize/deserialize data and can be used for passing data from one window to others but does not give access to same object instances across windows.
@Mossop I posted an minimal example at brave/browser-laptop#3270 (comment) of what needs to happen on the app side to use this brave/electron hack. Basically everything needs to be inside a <webview>, and these webviews are uniquely identified by their guest IDs, which allow them to be moved from one BrowserWindow to another.
This is now supported in electron through the sandbox flag passed to webPreferences when creating a new BrowserWindow.
I have not documented yet because I still need to push a some extra PRs(tracked by #6712) before the feature is fully complete(should be considered experimental), but it should already possible to use the native window.opener API as long as you can live with a few of limitations:
node.js/electron modules are not available in the renderer with one exception: require('electron').ipcRenderer still works on preload scripts. This means you can indirectly use all node.js/electron APIs as long as you set the proper IPC infrastructure in the browser process.
spell checking, plugins and <webview> and some extra functionality implemented in normal electron windows might not be available. This is because the sandboxed renderer inherits directly from chromium content renderer, so most of what was implemented by electron on renderer side is not available(this will be fixed in future PRs)
Another limitation about the sandbox flag: The preload script does not have a commonjs environment yet. Instead, the preload code is executed in the context of a function that has require in its scope, but only require('electron').ipcRenderer works for now.
You can still split your renderer code into multiple modules by using browserify to generate a preload bundle that delegates require('electron') to the enclosing funciton: browserify renderer.js -x electron -o preload.js
@davidrevmakx The window.opener is available in https://app.asana.com page, not the index.html one.
@davidrevmakx There's a spec for this scenario, but maybe it is not the correct behavior. Should window.opener be set in children from a different domain? If yes, then please file an issue.
In the spec the opener is null because that code runs in a separate page, and it is not possible to send a window proxy across IPC. Can you confirm that opener is null in the https://app.asan.com and not in index.html as @lijunle commented?
Activity
zcbenz commentedon Jun 9, 2015
In Electron every page is forced to run in its own process, however current architecture requires the pages to run in the same process if you want to access one page's contentWindow from the other, so it is not possible to implement it for now.
Chrome is now working on implementing out of process iframe, when it is done we might be able to implement this.
zcbenz commentedon Sep 10, 2015
Seems that windows opened by
window.opencan run in separated process in Chrome 45, having fullwindow.openersupport becomes possible now.felicienfrancois commentedon Sep 10, 2015
@zcbenz Good news !
zcbenz commentedon Sep 22, 2015
After a closer look into the problem, Chromium only allows certain operations to be sent across renderer processes, and from the issue tracking that (https://crbug.com/128768), they doesn't have plan to support all operations.
So since Electron has a strong requirement that each page runs on a separate process, I'm afraid this is not something that we are able to fix under current architecture.
I'm still keeping this open in case someone has an idea on how to fix this.
8 remaining items
hivaga commentedon Sep 13, 2016
Hi, I am working on a multi-windows application and I need to share a object instances from the main application process with the other windows of the application. Currently in browser you can reference window.opener to achieve this. In browser window.opener (in child window) will give you the instance of the Window object form which window.opent(myURL) was called.
In Electron when I open window via (window.opent(myURL)) window.opener is replaced with BrowserWindowProxy (Electron API) which does not expose the same window (Window object instance) from which the (window.open(myURL)) was called. Is there a way to access window.opener the same way it works in Browser. I need some hint do you plan to support this in the future and when ?
Using remote.sharedObject (Electron API) is not an option since it only serialize/deserialize data and can be used for passing data from one window to others but does not give access to same object instances across windows.
sltam commentedon Sep 22, 2016
@Mossop I posted an minimal example at brave/browser-laptop#3270 (comment) of what needs to happen on the app side to use this
brave/electronhack. Basically everything needs to be inside a<webview>, and these webviews are uniquely identified by their guest IDs, which allow them to be moved from oneBrowserWindowto another.tarruda commentedon Sep 27, 2016
This is now supported in electron through the
sandboxflag passed towebPreferenceswhen creating a newBrowserWindow.I have not documented yet because I still need to push a some extra PRs(tracked by #6712) before the feature is fully complete(should be considered experimental), but it should already possible to use the native
window.openerAPI as long as you can live with a few of limitations:require('electron').ipcRendererstill works on preload scripts. This means you can indirectly use all node.js/electron APIs as long as you set the proper IPC infrastructure in the browser process.<webview>and some extra functionality implemented in normal electron windows might not be available. This is because the sandboxed renderer inherits directly from chromium content renderer, so most of what was implemented by electron on renderer side is not available(this will be fixed in future PRs)Some examples of how to use it are available in https://github.com/electron/electron/blob/master/spec/api-browser-window-spec.js
So far the feature is only available master branch(no prebuilt binaries), but I think it will be on the next released version(cc @zcbenz)
Any help in testing this flag is appreciated, especially on OSX/windows which are not my native OSes.
tarruda commentedon Sep 27, 2016
Another limitation about the
sandboxflag: The preload script does not have a commonjs environment yet. Instead, the preload code is executed in the context of a function that hasrequirein its scope, but onlyrequire('electron').ipcRendererworks for now.You can still split your renderer code into multiple modules by using browserify to generate a preload bundle that delegates
require('electron')to the enclosing funciton:browserify renderer.js -x electron -o preload.jslijunle commentedon Nov 23, 2016
@zcbenz @tarruda It has passed 2 months after the feature is merged into master? Is it available in any version?
tarruda commentedon Nov 25, 2016
@lijunle it is available on electron 1.4.2 and up
davidrevmakx commentedon Nov 28, 2016
@tarruda I just tried to do a google auth on Asana.com / trello It doesn't seem to work. I used 1.4.8
davidrevmakx commentedon Nov 29, 2016
main.js
app.on('ready', () => { console.log("ready"); const win = new BrowserWindow({webPreferences: { sandbox: true }}) win.loadURL('http://localhost:8888/index.html'); })index.html
<a href="javascript:window.open('https://app.asana.com')">Click here</a>When I try accessing window.opener from index.html it says null. Am I doing anything wrong?
Platform: MacOS Sierra Electron: v1.4.10
lijunle commentedon Nov 29, 2016
@davidrevmakx The
window.openeris available inhttps://app.asana.compage, not theindex.htmlone.tarruda commentedon Nov 29, 2016
@davidrevmakx There's a spec for this scenario, but maybe it is not the correct behavior. Shouldwindow.openerbe set in children from a different domain? If yes, then please file an issue.In the spec the opener is null because that code runs in a separate page, and it is not possible to send a window proxy across IPC. Can you confirm that
openeris null in thehttps://app.asan.comand not inindex.htmlas @lijunle commented?davidrevmakx commentedon Nov 30, 2016
@lijunle @tarruda sorry for the confusion. Yes opener is null in https://app.asana.com page.
@tarruda You were right it isn't working when the children are from a different domain. When I changed my index.html to this
<a href="javascript:window.open('http://localhost:8888/test.html')">Click here</a>test.html has a window.opener object.
#8100 have created an issue here.
Gvozd commentedon Jul 4, 2018
To correct window.opener, and work facebook(and others) logins
You need use
webPreferences.nativeWindowOpen=true, and set samewebPreferences.affinityfor mainWindow, and opened windows(hook onmainWindow.webContents.on('new-window'))https://gist.github.com/Gvozd/2cec0c8c510a707854e439fb15c561b0