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

Sentry detects a NW.js app as a browser extension and refuses to load #12668

Closed
3 tasks done
skylarmt opened this issue Jun 27, 2024 · 4 comments · Fixed by #12846
Closed
3 tasks done

Sentry detects a NW.js app as a browser extension and refuses to load #12668

skylarmt opened this issue Jun 27, 2024 · 4 comments · Fixed by #12846
Assignees
Labels
Package: browser Issues related to the Sentry Browser SDK Type: Bug

Comments

@skylarmt
Copy link

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/browser

SDK Version

8.12.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

import * as Sentry from '@sentry/browser';
Sentry.init({
dsn: "[redacted]"
});

Steps to Reproduce

  1. Create a NW.js app.
  2. 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't
const isNWjs = (typeof nw !== "undefined");
return !!runtimeId && !isDedicatedExtensionPage && !isNWjs;
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jun 27, 2024
@github-actions github-actions bot added the Package: browser Issues related to the Sentry Browser SDK label Jun 27, 2024
@s1gr1d s1gr1d self-assigned this Jun 27, 2024
@s1gr1d
Copy link
Member

s1gr1d commented 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
Copy link
Author

skylarmt commented 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:

<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.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jul 9, 2024
@s1gr1d
Copy link
Member

s1gr1d commented Jul 10, 2024

Thanks for giving an overview over NW.js, much appreciated! :)
We will work on this.

Lms24 added a commit that referenced this issue Jul 10, 2024
Looks like our browser extension check that blocks SDK initalization via
`Sentry.init` also blocked initializing
the SDK in NW.js apps. This PR adds a check for the `window.nw` property
to handle this case.

fixes #12668
@Lms24
Copy link
Member

Lms24 commented Jul 15, 2024

Hi, this was released with version 8.17.0. Please let me know if this issue should be reopened!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: browser Issues related to the Sentry Browser SDK Type: Bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants