sentry-electron icon indicating copy to clipboard operation
sentry-electron copied to clipboard

Crash in Web worker

Open oltreseba opened this issue 5 years ago • 3 comments

Versions + Platform

Description

Apparently this library does not work in web worker context:

The code i'm trying to run is:

Sentry = require('@sentry/electron')
Sentry.init({ dsn: CONST.SENTRY_DNS })

What I get is:

Uncaught Error: No such module was linked: atom_common_ipc
    at _linkedBinding (internal/bootstrap/loaders.js:118)
    at process.electronBinding (electron/js2c/worker_init.js:623)
    at Object.<anonymous> (electron/js2c/worker_init.js:1008)
    at Object../lib/renderer/api/ipc-renderer.ts (electron/js2c/worker_init.js:1034)
    at __webpack_require__ (electron/js2c/worker_init.js:20)
    at loader (electron/js2c/worker_init.js:1055)
    at Object.ipcRenderer (electron/js2c/worker_init.js:585)
    at /Users/oltreseba/Project/node_modules/@sentry/electron/dist/renderer/backend.js:95

In web worker ipc and almost all electron API are not available.

oltreseba avatar Apr 10 '20 09:04 oltreseba

@sentry/electron merges all events from the Electron main and renderer processes and it requires access to node.js and IPC to do this. This is possible securely in renderer processes because of Electron preload scripts but these are not available in Web Workers.

It may be possible to get in working in Web Workers using the nodeIntegrationInWorker option but this persistently enables full node.js in workers which has some security implications and so I haven't tested it.

However, @sentry/javascript just works in Web Workers so that is probably the best route for now.

timfish avatar Apr 14 '20 10:04 timfish

nodeIntegrationInWorker (which I already have enabled) unfortunately does not solve the problem.

This is because, even if enabled, all Electron's API are still not available in workers.

However none of Electron's built-in modules can be used in a multi-threaded environment.

Reference: https://www.electronjs.org/docs/tutorial/multithreading. So IPC keeps failing.

So far i've done something like: (since i'm initiating sentry in some shared code).

  if (process.type !== 'worker') {
   Sentry = require('@sentry/electron')
  } else {
   Sentry = require('@sentry/browser') // probably it's possible to replace it with '@sentry/javascript' 
  }

It works so far.

oltreseba avatar Apr 14 '20 10:04 oltreseba

@oltreseba you are correct. I meant @sentry/browser!

timfish avatar Apr 14 '20 10:04 timfish

Closing this issue for cleanup. Please re-open if this still applies. Thanks!

AbhiPrasad avatar Jul 27 '23 15:07 AbhiPrasad