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

Renderer Backend will not work without access to ipcRenderer #279

Closed
hibearpanda opened this issue Dec 9, 2020 · 9 comments · Fixed by #280
Closed

Renderer Backend will not work without access to ipcRenderer #279

hibearpanda opened this issue Dec 9, 2020 · 9 comments · Fixed by #280

Comments

@hibearpanda
Copy link

hibearpanda commented Dec 9, 2020

Electron's security documentation suggest setting:

The sentry client for the renderer directly requires ipcRenderer (https://github.com/getsentry/sentry-electron/blob/master/src/renderer/backend.ts#L5) as a way to send events to the main process, but with the suggested security settings, this would not be possible (ipcRenderer wouldn't be available in the renderer process).

Are there any plans to allow us to use sentry in the renderer process without exposing ipcRenderer directly?

If not, would it be possible for us to submit a PR for this?

@hibearpanda hibearpanda changed the title Renderer Backend will not work with contextIsolation and contextBridge Renderer Backend will not work without access to ipcRenderer Dec 9, 2020
@timfish
Copy link
Collaborator

timfish commented Dec 9, 2020

Last night I was working on a PR for exactly this which exposes IPC through contextBridge when context isolation is enabled.

It's not a simple change because @sentry/electron still needs to work with context isolation disabled and in versions of Electron before context isolation even existed.

With context isolation enabled, you'll need to call init in the main process, the renderer preload and in the renderer in the isolated context.

@hibearpanda
Copy link
Author

hibearpanda commented Dec 10, 2020

That's wonderful @timfish. Thank you very much. I took a look at your PR and can see where it is headed. Appreciate your efforts.

@ferretwithaberet
Copy link

ferretwithaberet commented Dec 15, 2020

With context isolation enabled, you'll need to call init in the main process, the renderer preload and in the renderer in the isolated context.

I am trying to do this, but it does not seem to capture unhandled errors.

My code is:

// Main process
...
const Sentry = require("@sentry/electron");
Sentry.init({
    dsn: "_DSN_",
});
...

// Preload script
...
const Sentry = require("@sentry/electron");
Sentry.init({
    dsn: "_DSN_",
});
contextBridge.exposeInMainWorld("electron", {
    // General
    Sentry: Sentry,
    ...
});

// Renderer
<script>
    electron.Sentry.init({
        dsn: "_DSN_",
    });
</script>

Not sure if related to this.

@timfish
Copy link
Collaborator

timfish commented Dec 16, 2020

contextIsoaltion will only work once #280 is merged.

Once this is merged you'll need to call init from the main process and both the preload and renderer. You cannot call init via contextBridge.

The test app shows what is required.

@bermanboris
Copy link

Thanks for merging #280!
@timfish @HazAT
Any idea when it'll be available on npm?

@timfish
Copy link
Collaborator

timfish commented Feb 16, 2021

@bermanboris Now!

@bermanboris
Copy link

Thanks for an update @timfish !

@hibearpanda
Copy link
Author

Hi @timfish, would it be possible to provide an example of preload.js? In the link to the test app, a preload.js file is provided but I don't see this available in the test app.

@bermanboris
Copy link

@hibearpanda Hey! According to webpack configuration, it uses src/sentry.js file as preload. I hope this helps.

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

Successfully merging a pull request may close this issue.

4 participants