Skip to content

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

Closed

Description

@skylarmt

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;

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with πŸ‘€ 3on Jun 27, 2024
  2. self-assigned this
    on Jun 27, 2024
  3. s1gr1d commented on Jun 27, 2024

    @s1gr1d
    Member

    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.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with πŸ‘€ 3on Jun 27, 2024
  5. skylarmt commented on Jul 9, 2024

    @skylarmt
    Author

    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.

  6. moved this to Waiting for: Product Owner in GitHub Issues with πŸ‘€ 3on Jul 9, 2024
  7. s1gr1d commented on Jul 10, 2024

    @s1gr1d
    Member

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

  8. moved this from Waiting for: Product Owner to No status in GitHub Issues with πŸ‘€ 3on Jul 10, 2024
  9. Lms24 commented on Jul 15, 2024

    @Lms24
    Member

    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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions