-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Calling Sentry.init in Electron will result in an error. #14133
Comments
Hi, can you confirm that you're using @sentry/electron and you followed our electron docs? https://docs.sentry.io/platforms/javascript/guides/electron/ |
My page can run in both Electron and Chrome, so I believe I should use @sentry/browser. And I am collecting issues from web pages, not from Electron. |
@HaoZhouInRC can you give us more context on your setup? Does your app run inside of a browser extension? Please also share the config of your |
Sentry.init({
"environment": "develop",
"dsn": "xxxxxx",
"debug": false,
"release": "24.4.20",
"ignoreErrors": [],
"maxBreadcrumbs": 50,
"integrations": [Breadcrumbs],
"transportOptions": {},
"initialScope": {"tags": {"desktopRelease": "24.3.360"}}
}) My application is a React web page that can run in Electron or a browser. |
Add an additional question: How does Sentry capture web page crashes? |
I'm afraid I still don't fully understand why this is a problem in your case and not generally in Electron apps. Do you have a special electron configuration that sets the
Do you mean full crashes where the browser shows that the tab crashed? Short answer: We can't report these unfortunately. In case you mean, how do we catch errors? By listening to |
That being said, we previously already discussed if we should provide an escape hatch for the browser extension check because it already triggered falsely multiple times. This is probably more bundle-size efficient than adding yet another special case in this check. |
BackgroundFirst, let's describe the situation of our application. Our app is a web page developed using React, which can run directly in the browser. However, to expand the capabilities of the app, we have also developed an Electron client for it. This client directly loads our web page for users to use, and at the same time, we can provide more native system capabilities to the web page. Electron Supports Some Chrome Extension CapabilitiesAs described in this document https://www.electronjs.org/docs/latest/api/extensions#chromeruntime, web pages opened in Electron will have corresponding APIs injected into window.chrome. Reason for the Bugconst windowWithMaybeExtension =
typeof WINDOW.window !== 'undefined' && (WINDOW as typeof WINDOW & ExtensionProperties);
if (!windowWithMaybeExtension) {
// No need to show the error if we're not in a browser window environment (e.g. service workers)
return false;
}
const extensionKey = windowWithMaybeExtension.chrome ? 'chrome' : 'browser';
const extensionObject = windowWithMaybeExtension[extensionKey];
const runtimeId = extensionObject && extensionObject.runtime && extensionObject.runtime.id; // Can read runtimeId
const href = (WINDOW.location && WINDOW.location.href) || ''; // href is a web page starting with https://
const extensionProtocols = ['chrome-extension:', 'moz-extension:', 'ms-browser-extension:', 'safari-web-extension:'];
// Running the SDK in a dedicated extension page and calling Sentry.init is fine; no risk of data leakage
const isDedicatedExtensionPage = // This is also false
!!runtimeId && WINDOW === WINDOW.top && extensionProtocols.some(protocol => href.startsWith(`${protocol}//`));
// Running the SDK in NW.js, which appears like a browser extension but isn't, is also fine
// see: https://github.com/getsentry/sentry-javascript/issues/12668
const isNWjs = typeof windowWithMaybeExtension.nw !== 'undefined'; // This is false
return !!runtimeId && !isDedicatedExtensionPage && !isNWjs; // Overall is true |
This can be considered a solution, thank you. |
I'm still very surprised that Gonna tag @timfish - any ideas how this could happen? In other news, I opened and merged #14147 which will let you bypass the check so that you can call |
I haven't seen this before with the Electron SDK and it doesn't affect any of our tests and examples. @HaoZhouInRC are you using any chrome extensions? |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/browser
SDK Version
8.27.0
Framework Version
No response
Link to Sentry event
No response
Reproduction Example/SDK Setup
Steps to Reproduce
Expected Result
Can be initialized normally.
Actual Result
Cause by #12668
Electron chrome runtime https://www.electronjs.org/docs/latest/api/extensions#chromeruntime
The text was updated successfully, but these errors were encountered: