0

I am in the process of migrating a chrome extension to MV3 . Now we use a library called Segment Analytics. This is basically for capturing events that happen . Basically content scripts & popup script pass events based on what actions are happening in website & popup to our background script(which uses the object exposed by the library SegmentAnalytics to record actions).

Now the problem is there is usage of document object everywhere in the code of this Library. But now we cant use it as a background script anymore like in MV2 as we dont have a document there. However injecting it as content script everywhere(urls which are targeted) doesnt sound like a good idea. Is there a good solution to this?

//MV2 manifest
"background": {
  "scripts": [
    "./js/background.js",
    "./js/SegmentAnalytics.js" //exposes object which we use in background
  ],
  "persistent": true
},
  • 1
    There is absolutely no way to get `document` working in Manifest V3 service workers, since they're implemented exactly the same as normal service workers. Unfortunately you may just have to inject it with your content scripts, but that shouldn't cause any issues in theory. – 101arrowz Feb 28 '23 at 07:13
  • 1
    Use https://developer.chrome.com/docs/extensions/reference/offscreen/ – wOxxOm Feb 28 '23 at 10:52

0 Answers0