Skip to content

Sentry does not init in browser extension's service worker #13152

Closed
@ddomonkos

Description

@ddomonkos

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

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

  1. Have a Manifest V3 browser (Chrome) extension
  2. Run Sentry.init in the service worker (this used to be the "background script")
  3. Observe an error

Expected Result

Sentry initializes without error.

Actual Result

An error is printed out:

[Sentry] You cannot run Sentry this way in a browser extension, check: https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/

Relevant PRs:

The problem is with the condition WINDOW === WINDOW.top. In a service worker, WINDOW is resolved to globalThis and globalThis.top is undefined.

However, AFAIK it still applies that service worker's context is not shared, i.e. it should be fine to initialize Sentry there.

Metadata

Metadata

Assignees

Labels

Package: browserIssues related to the Sentry Browser SDK

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions