XKit-Rewritten icon indicating copy to clipboard operation
XKit-Rewritten copied to clipboard

chore: Remove webextension polyfill

Open marcustyphoon opened this issue 1 year ago • 2 comments

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

Confirm extension functionality in Chromium and Firefox.

marcustyphoon avatar Jul 17 '24 22:07 marcustyphoon

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 (https://github.com/AprilSylph/Outbox-for-Tumblr/pull/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.

marcustyphoon avatar Jul 23 '24 10:07 marcustyphoon

Ugh, I guess putting this in the content scripts folder doesn't make sense, because it's referred to in action. But it probably shouldn't go in lib since it's not vendored, and it probably shouldn't go in util because it exists on a higher hierarchy level than everything in there. Uhh... I dunno, thoughts?

marcustyphoon avatar Nov 02 '24 05:11 marcustyphoon