Skip to content
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

Electron crash on start #66

Open
gavinbenda opened this issue Mar 23, 2020 · 5 comments
Open

Electron crash on start #66

gavinbenda opened this issue Mar 23, 2020 · 5 comments

Comments

@gavinbenda
Copy link

Can't find much on this around the net, but including webusb within an electron app (just using the blank/quick-start guide to keep it simple), and installing webusb, then running the webusb example code from the docs, causes an immediate crash on attempting to start the app.

Unfortunately there doesn't seem to be much in the way of errors.

Node.js 12.13.0, Chromium 80.0.3987.141, and Electron 8.1.1 on OSX

@thegecko
Copy link
Owner

I've not tried this in electron, do you see an error when starting electron from the command line?

@gavinbenda
Copy link
Author

Unfortunately all of the debugging disconnects...
It's the same issue as this comment I believe which is the only other mention of it on the web!
electron/electron#14545 (comment)

@thegecko
Copy link
Owner

I assume you are using it in the backend process? The underlying usb package wont be available in the browser process.

@brandonros
Copy link

you can require('usb') from the renderer, you just need init in the non-renderer process to look a little bit like this

const electron = require('electron')

const createWindow = () => {
  const mainWindow = new electron.BrowserWindow({
    width: 1024,
    height: 768,
    title: 'OBD Flasher',
    webPreferences: {
      nodeIntegration: true,
      backgroundThrottling: false
    }
  })
  mainWindow.loadURL(`file://${__dirname}/index.html`)
}

const run = async () => {
  // power saver
  electron.powerSaveBlocker.start('prevent-display-sleep')
  // native modules
  electron.app.allowRendererProcessReuse = false
  // no backgrounding
  electron.app.commandLine.appendSwitch('disable-renderer-backgrounding')
  // init
  await electron.app.whenReady()
  createWindow()
  electron.app.on('activate', () => {
    if (electron.BrowserWindow.getAllWindows().length === 0) {
      createWindow()
    }
  })
  electron.app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
      electron.app.quit()
    }
  })
}

run()

@brandonros
Copy link

then from my renderer.js i call require('usb') and it works fine.

thegecko and i just whipped up a new release that fixes a segfault on windows during device opening, i bet you it will fix this electron issue too

see #68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants