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.

Problems in renderer process with contextIsolation: true

See original GitHub issue

Versions + Platform

  • SDK version - @sentry/electron@v2.4.0
  • Electron version - electron@v12.0.2
  • Platform - Windows/macOS/Linux

Description

I’m facing two issues with exceptions occurring in a web page loaded in BrowserWindow started with contextIsolation: true and nodeIntegration: false (Sentry is initialized as the first thing in a preload script):

  • Unhandled exceptions are not sent to Sentry at all – maybe the 'error' event handler is not working when set up in the isolated context
  • To capture exceptions manually, I expose Sentry.captureException in window by contextBridge.exposeInMainWorld, but any exception passed to it goes through the context isolation machinery, which creates a new Error object that only has a message property – stacktrace and error type is lost.

How should we deal with this? Loading and initializing only @sentry/browser in the actual webpage instead of the preload script would work, but then we lose all Electron breadcrumbs etc.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:11

github_iconTop GitHub Comments

1reaction
rfriczcommented, Apr 27, 2021

Sorry, I guess I wasn‘t very clear. The problem is with errors occurring in the main process, your test case only tests an error in the isolated renderer. I am calling init in all three, as per your advice from before, so events get submitted. The issue is that I call

Sentry.configureScope(scope => {
    scope.setUser({ id });
});

in the isolated renderer, and then at some point in the future, if an exception is thrown in the main process and sent to Sentry, it doesn’t have the user info that was provided before.

If I call

Sentry.getCurrentHub().getClient()._backend._setupScopeListener();

in the isolated renderer right after calling init, then all errors that occur in main will have that user info, breadcrumbs etc.

Does that make sense?

0reactions
mjwvbcommented, Apr 29, 2021

WIth 2.4.1 I still have the same problem. I force the main process to crash, but it still doesn’t get the scope and events from my sentry (react) implementation in the html context.

It seems that sentry-electron and sentry-react don’t work together. I tested it with sentry-electron in the html context instead, and then the scope and events are indeed copied over. Now I have to enable nodeIntegration as a workaround, which I don’t like. Do I have to do something special to integrate sentry-react with sentry-electron?

Read more comments on GitHub >

github_iconTop Results From Across the Web

With contextIsolation = true, is it possible to use ipcRenderer?
You are still able to use ipcRenderer in a renderer process with contextIsolation set to true. The contextBridge is what you want to...
Read more >
Some ipc messages are not sent when contextIsolation and ...
Expected behavior. ipc messages from the main process should be sent to the renderer process when both sandbox and contextIsolation are set.
Read more >
Context Isolation - Electron
Exposing APIs from your preload script to a loaded website in the renderer process is a common use-case. With context isolation disabled, your...
Read more >
@lpfreelance/electron-bridge - npm
Safely expose main process modules of Electron to renderer ... nativeWindowOpen: true, nodeIntegration: false, contextIsolation: true, ...
Read more >
The ultimate Electron guide - Debug & Release
The property that allowed us to include Node in the renderer process is nodeIntegration: true. This made our code easy - our front...
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