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
- Have a Manifest V3 browser (Chrome) extension
- Run
Sentry.init in the service worker (this used to be the "background script")
- 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.
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
Sentry.initin the service worker (this used to be the "background script")Expected Result
Sentry initializes without error.
Actual Result
An error is printed out:
Relevant PRs:
The problem is with the condition
WINDOW === WINDOW.top. In a service worker,WINDOWis resolved toglobalThisandglobalThis.topisundefined.However, AFAIK it still applies that service worker's context is not shared, i.e. it should be fine to initialize Sentry there.