Wednesday, 29 May 2019

Get window, document and body in Electron 5+ remote.BrowserWindow

Currently, electron 5.0 removed the ability to use nativeWindowOpen with nodeIntegration, so it's impossible to use ReactDOM.createPortal on the document.body returned by window.open. They didn't put any workaround, and I've tried everything found in other answers, like:

  • IPC back the DOM node to the new remote.BrowserWindow, it doesn't send back a valid DOM node to attach to
  • webContents.executeJavascript, with either (function(){ return window })() document or body, makes the process hang

I just don't seem to be able to do the equivalent using BrowserWindow:

// this is what works in Electron 4 with a warning see https://github.com/electron/electron/pull/15193
const container = window.open("about:blank", "someuniqueid"); // window = current main window

const stylesheet = document.createElement('link');
stylesheet.rel = 'stylesheet';
stylesheet.href = document.querySelector('link').href; // document = current main window

container.document.body.appendChild(stylesheet);
// [... edited for brevity]
return createPortal(
  props.children(container), // children = render props, pass the window to the children
  container.document.body
)

nothing is able to return a valid DOM node from the created window. require('electron') also doesn't work for obvious reasons (nodeIntegration is always disabled)



from Get window, document and body in Electron 5+ remote.BrowserWindow

No comments:

Post a Comment