Closed alganzory closed 8 months ago
chrome.offscreen is the way to go. It's the closes thing to a persistent background script offered by Mv2, I have tried it out, it works fine, at least for images, sending video frames back and forth is a bit slow, so maybe a hybrid approach? images go to offscreen, videos processed on the content script? also chrome.offscreen is chrome 109+ so I am not sure if that's gonna be an issue, I assume most people use chrome versions above 109 but idk for sure
Manifest V3 is the main reason why this extension isn't as fast as some of the others out there that use manifest v2. Simply because in manifest v3 we don't have persistent background scripts, that means all the model initialization happens on EVERY single tab/reload, which is such a waste of time and resources. Even if somehow I manage to use background service of manifest v3 to run the detection, the process of sending images back and forth between them slows things down a lot, and won't easily work with videos, this is again because in Manifest v3, background service workers don't have direct access to DOM, so basically you have to convert the image data to be able to send them across and back, it's a hassle.
If we figure out a way to overcome this limitation -> we don't initiate and load models on every tab/page and ideally don't process things in content script -> speed increases significantly
I've looked into things like offscreen api, and others, but I quickly got confused and still haven't gotten the time to revisit them.
for references: example issue report offscreen api