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

Remove webextension polyfill #1549

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

marcustyphoon
Copy link
Collaborator

Description

Included in Chrome's MV3 changes are, according to them, adding promise support to webextension APIs. So long as the major browser vendors do their standardization correctly, this means that https://github.com/mozilla/webextension-polyfill will serve only to fix the name mismatch between the chrome and browser namespaces. One could thus only do that.

Let's see if it works! Sure seems to.

Testing steps

@marcustyphoon
Copy link
Collaborator Author

marcustyphoon commented Jul 23, 2024

Notably, I'm not one hundred percent sure if

globalThis.browser ??= globalThis.chrome;

is precisely equivalent to

if (typeof browser === 'undefined') {
  globalThis.browser = chrome;
}

but I see no reason it wouldn't be and is a nicer oneliner if you need to use it in multiple places (AprilSylph/Outbox-for-Tumblr#96). I was conservative and copied MDN here.

There are, of course, a million ways to write this. One can just as easily use window.browser ??= window.chrome;, for example; maybe that makes the most sense here with the justification that it'd the most recognizable to any web extension developer. edit: You know what, that may be sort of incorrect, as the window global may bypass Firefox xray vision. Firefox's extension sandbox is Really Weird.

In any case, globalThis is good to know about, since it works in web workers, and I do try to make my code as applicable to other situations as I can.

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 this pull request may close these issues.

1 participant