-
Notifications
You must be signed in to change notification settings - Fork 215
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
Does not work when imported as a module. #202
Comments
A quick attempt to submit a PR shows that the problem is that the build scripts appear to be turning the script into a UMD module, and the output of that script is the problem. Fixing this will likely require either upgrading the build script tooling, or getting the bug fixed in the build script tooling. |
It appears the issue is coming from this buildscript step: webextension-polyfill/Gruntfile.js Lines 75 to 80 in 04a9e3a
|
I have filed an issue with Babel about this, TBD whether anything will come from that. |
@MicahZoltu We (@Rob--W and I) discussed about this and we are open to fix this on the polyfill side by building a separate .mjs version that is going to be a pure ES6 module (and make it part of the npm package release). |
FWIW babel/babel#10477 has been merged. I believe it will be available in Babel 7.7.0, whenever that release gets cut. |
@MicahZoltu that's great (also thanks for filing it upstream). we should definitely look into updating this repo to use a more recent version of babel (which was going to be necessary even besides this issue), I just filed #211 to keep track on it. |
We have just landed a fix for this in #214 I'm not closing this yet because we should also add some details about how to use the polyfill by loading as a JS module in the README.md file (and I just added a "needs: docs" label to make it visible that this is pending a pull request to do that). |
If you attempt to load the
webextension-polyfill
as a module, you get a runtime failure in both Chrome and Firefox due to the utilization ofthis
as theglobal
parameter.this
is undefined in the context of an ES module, so when the root UMD module function is called andthis
is passed to theglobal
parameter, it ends up passingundefined
. Then whenglobal.browser
is referenced you get a type error.The same problem occurs with the minified source.
Error message in Firefox:
Recommendation
Use
globalThis || window || this
instead ofthis
as the first parameter. I believe any browser that supports ES modules also supports eitherglobalThis
orwindow
, sothis
will only be hit in the rare case.Repro Case
The text was updated successfully, but these errors were encountered: