You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sentry detects a NW.js app as a browser extension and refuses to loadΒ #12668
import * as Sentry from '@sentry/browser';
Sentry.init({
dsn: "[redacted]"
});
Steps to Reproduce
Create a NW.js app.
Install Sentry in it.
Expected Result
Sentry loads and functions normally.
Actual Result
Chromium devtools console shows error "You cannot run Sentry this way in a browser extension". Sentry doesn't load. Modifying the function shouldShowBrowserExtensionError() in sdk.js causes Sentry to function normally.
For example, replacing the last line in that function with this code causes Sentry to work:
// Running in NW.js, which appears like a browser extension but isn'tconstisNWjs=(typeofnw!=="undefined");return!!runtimeId&&!isDedicatedExtensionPage&&!isNWjs;
Thank you for reporting this! Could it be that your application is running inside a shared environment like a VSCode extension, a Third-Party Widget or a library? I am not super familiar with NW.js but it seems to be running in a shared environment. If this is the case you can setup a client manually like described in the docs.
NW.js is an Electron alternative that's a lot simpler and easier to get started with. However, due to the way it works internally, it treats applications sort of like they're Chrome extensions, which is triggering the shared environment code. Each NW.js application runs in its own process, there's no shared environment. One app can open multiple windows, but each one will function like a new browser tab, meaning they're mostly isolated from each other. NW.js is basically a web browser, without any of the browser chrome (tabs, url bar, etc), and with the ability to run Node.JS code alongside browser code for accessing system resources like the filesystem.
Here's a minimal NW.js application:
path/to/app/package.json:
{
"name": "helloworld",
"main": "index.html"
}
path/to/app/index.html:
<title>Window Title</title><h1>Hello world</h1>
To run it, download NW.js (use the SDK build, it has Chromium's DevTools built in), unzip it, and run ./nw path/to/app. You'll see a new application window open, saying "Hello world". Now install Sentry into index.html like it's a website (which it is, just with extra features), and it will refuse to work. Right-click your window and click "Inspect" and look in the console logs.
Fortunately, the NW.js runtime provides a global nw object, so checking for its presence will let Sentry know it's running as a standalone desktop application and not in a shared environment.
There is another way to run NW.js, using "main": "script.js" and having that script potentially do other things besides open a window to a URL. However, my (lazy) attempts to import the Node version of Sentry failed and I used the browser version instead, which captures well over 99% of errors.
It's worth noting that it is possible to open regular websites in an NW.js app (most simply, by setting main to a URL instead of a file, but there are other methods too). It stands to reason that if that website is running Sentry, and someone uses NW.js to view it, that Sentry will refuse to run, which is likely undesirable.
Activity
s1gr1d commentedon Jun 27, 2024
Thank you for reporting this! Could it be that your application is running inside a shared environment like a VSCode extension, a Third-Party Widget or a library? I am not super familiar with NW.js but it seems to be running in a shared environment. If this is the case you can setup a client manually like described in the docs.
skylarmt commentedon Jul 9, 2024
NW.js is an Electron alternative that's a lot simpler and easier to get started with. However, due to the way it works internally, it treats applications sort of like they're Chrome extensions, which is triggering the shared environment code. Each NW.js application runs in its own process, there's no shared environment. One app can open multiple windows, but each one will function like a new browser tab, meaning they're mostly isolated from each other. NW.js is basically a web browser, without any of the browser chrome (tabs, url bar, etc), and with the ability to run Node.JS code alongside browser code for accessing system resources like the filesystem.
Here's a minimal NW.js application:
path/to/app/package.json:{ "name": "helloworld", "main": "index.html" }path/to/app/index.html:To run it, download NW.js (use the SDK build, it has Chromium's DevTools built in), unzip it, and run
./nw path/to/app. You'll see a new application window open, saying "Hello world". Now install Sentry intoindex.htmllike it's a website (which it is, just with extra features), and it will refuse to work. Right-click your window and click "Inspect" and look in the console logs.Fortunately, the NW.js runtime provides a global
nwobject, so checking for its presence will let Sentry know it's running as a standalone desktop application and not in a shared environment.There is another way to run NW.js, using
"main": "script.js"and having that script potentially do other things besides open a window to a URL. However, my (lazy) attempts to import the Node version of Sentry failed and I used the browser version instead, which captures well over 99% of errors.It's worth noting that it is possible to open regular websites in an NW.js app (most simply, by setting
mainto a URL instead of a file, but there are other methods too). It stands to reason that if that website is running Sentry, and someone uses NW.js to view it, that Sentry will refuse to run, which is likely undesirable.s1gr1d commentedon Jul 10, 2024
Thanks for giving an overview over NW.js, much appreciated! :)
We will work on this.
fix(browser): Allow SDK initialization in NW.js apps (#12846)
Lms24 commentedon Jul 15, 2024
Hi, this was released with version 8.17.0. Please let me know if this issue should be reopened!