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
},