Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

offscreen.js purpose and functionality? #586

Closed
toasted-nutbread opened this issue Jan 28, 2024 · 3 comments · Fixed by #675
Closed

offscreen.js purpose and functionality? #586

toasted-nutbread opened this issue Jan 28, 2024 · 3 comments · Fixed by #675
Assignees

Comments

@toasted-nutbread
Copy link

I've done a little bit of looking into this, but I don't fully understand why some components are in offscreen.js, specifically the Translator and DictionaryDatabase. As far as I can tell, this is supposed to address some sort of startup lag that would occur after the extension idles for a while and the service worker has to restart, but does anyone know how having these components in an offscreen document fix the issue? It seems like the additional indirection would make it slower in general.

Related:

@djahandarie
Copy link
Collaborator

Maybe @praschke might have some insight on this one

@praschke
Copy link
Collaborator

praschke commented Jan 30, 2024

an indirection is always slower in absolute terms but that doesn't mean it's perceptible.

even if it is perceptible, the capabilities of the service worker and the offscreen document are completely different, and the issue you mention is why the indirection was necessary.

the purpose of those components being kept in the offscreen document is that the offscreen document can be kept alive forever. the service worker was taking forever to initialize the database and become ready, so it had to be moved out of the service worker.

@toasted-nutbread
Copy link
Author

I see, so it's being treated as somewhat of a stand-in for the old background page where it seems to be always alive. Presumably this is because it is reading the clipboard, which is always running.

My only worry after reading some of the docs is this:

https://developer.chrome.com/blog/Offscreen-Documents-in-Manifest-v3

To reduce the likelihood of extensions using these as a "background page replacement", only the chrome.runtime messaging APIs are exposed to the offscreen document.

I.e. that chrome may break something by changing how this feature operates in the future.

In any matter, I don't think using the offscreen window is the wrong choice here, but the codebase could be more clear about what issue it is solving. I'll take this as an action for me to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants