question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New BrowserWindow isn't loading in prod

See original GitHub issue

I’m trying to open a new BrowserWindow, it works fine in yarn dev, but in full release it just comes up as a white window that never does anything. I’ve tried using #/paths with the default router, and the solution here using react-router-dom with search props: https://github.com/electron-react-boilerplate/electron-react-boilerplate/issues/623

Presumably some Webpack config issue, which I have very little experience with, or I’m just flat out loading the wrong file path because of prod bundle wizardry.

Prerequisites

  • [x ] Using yarn
  • [x ] Using node 10.x
  • [x ] Using an up-to-date master branch
  • [x ] Using latest version of devtools. See wiki for howto update
  • For issue in production release, devtools output of DEBUG_PROD=true yarn build && yarn start - no output is given

Expected Behavior

Opening a new BrowserWindow from within a component in prod should work properly, as it does in dev.

Current Behavior

New BrowserWindow opens, but seems not to load any renderer process. Debug prod output shows console logs firing the event, but no logs from the process afterwards.

Possible Solution

Some prod Webpack config alterations I guess 🤷‍♂️

Steps to Reproduce (for bugs)

The code suggested here for the router: https://github.com/electron-react-boilerplate/electron-react-boilerplate/issues/623#issuecomment-333750155

Being called from a component like; this.windowObject = window.open(file://${__dirname}/app.html?gallery);

Works in yarn dev, but not yarn start.

Alternatively, with no changes to the original router window.open(file://${__dirname}/app.html#/counter); would also have the same effect.

Output of that file path in dev is: file://E:\Github\xx\app/app.html?counter Vs in prod: file:////app.html?counter

If that would effect anything when bundled.

Context

Trying to open a new child window from a component, ended up here. This still launches a whole new React app which seems undesirable, but oh well. No intelligent changes to the core boilerplate.

Your Environment

  • Node version : v10.15.2
  • Version or Branch used : master/latest
  • Operating System and version : Windows 7

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
hot-grilcommented, Aug 11, 2020

The default is Electron 8 now, but I have the same issue. Console says “Not allowed to load local resource,” which is essentially a 404 (I get that on dev if I load some nonexistent path).

Complete code, works on dev but not prod:

  async joinRoom(code) {
    try {
      var win = new BrowserWindow({
        width: 400, height: 400,
        webPreferences: { nodeIntegration: true }
      } )
      win.invitationCode = code
      win.on('close', function () { win = null })
      win.loadURL(`file://${__dirname}/app.html#/room?invitationCode=${encodeURIComponent(code)}`)
      win.show()
    } catch(e) {
      alert(e)
    }
  }

I’ve tried with nodeIntegration false and true. Peeked at the packaged renderer.prod.js, no clues there. Frankly the docs should simply tell you how to open a local component page; just the above took me a lot of sifting through StackOverflow.

0reactions
leohxjcommented, Jul 21, 2020

when after build, __dirname is /, whatever I set nodeIntegration:true…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Options not working on new browser window in electron
whenever a new window is opened, I want a new window to be created by Electron. This works fine and occurs at "app.on('new-window',..."....
Read more >
Process Model | Electron
Each instance of the BrowserWindow class creates an application window that loads a web page in a separate renderer process. You can interact...
Read more >
"This tool needs to be loaded in new browser window" not ...
Im a student and usually when the teachers put a new tool, there is a button that you press to load the tool....
Read more >
Creating an Electron application from scratch
Create a new BrowserWindow. Unfortunately, the above code does not work, as BrowserWindows are only able to be created once the Electron ...
Read more >
Chapter 5. Working with multiple windows - Electron in Action
We also explore solutions to problems that occur when taking a main process that ... createWindow = () => { let newWindow =...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found