Saturday, 13 May 2023

How to use Sentry in chrome extension

I am trying to use Sentry in a chrome extension project. Here is a workaround.

If I try this code in background.js file:

import * as Sentry from '@sentry/browser'

Sentry.WINDOW.document = {
  visibilityState: 'hidden',
  addEventListener: () => {},
}

I get an error: TypeError: Cannot set property document of #<Window> which has only a getter

I tried to update code to this:

Object.defineProperty(Sentry.WINDOW, 'document', {
  value: {
    visibilityState: 'hidden',
    addEventListener: () => {},
  },
  configurable: true,
  writable: true,
  enumerable: true,
})

but now I am getting error: TypeError: Cannot redefine property: document.

Any ideas how can I fix this and use Sentry in a browser extension?



from How to use Sentry in chrome extension

No comments:

Post a Comment