-
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
Different way of checking if browser is defined? #68
Comments
@fstanis That's really unfortunate :-( but also: Thank you for letting us know! we are going to evaluate if we should workaround it in the polyfill itself. |
By checking window.browser the webpack.ProvidePlugin won’t be confused.
Hi, I just came across the same problem, and it seems that the problem has been fixed. However the last release on npm was 6 months ago, which doesn't include the fix yet. Any idea when the next release will happen? Thanks |
if (!("browser" in window)) {
// [...]
}
Edit: Turns out that that causes the tests to fail because of webextension-polyfill/test/setup.js Lines 44 to 50 in 6f9cfdf
const isDefined = (obj, key) => {
if (typeof obj !== "object" || obj === null) {
return false;
}
return key in obj && typeof obj[key] !== "undefined";
}; Edit 2: Turns out that that doesn’t work either because of #114 (comment) and #115 (comment) |
Currently this polyfill can be trivially disabled by adding a DOM element with id This is possible because browsers create implicit global variables for such elements and of course their type is not See https://crbug.com/865881 |
@tophf Thanks for linking the bug here. I was just about to make a new issue. It's a really annoying problem. At first I feared that you could extend the element prototype and override the browser.runtime for some nasty code but luckily that didn't work. Many pages can have an element ID'd as |
Note: version 0.9.0 supports plugins: [
new ProvidePlugin({
browser: "webextension-polyfill"
})
] |
I found a peculiar bug with using webextension-polyfill in webpack: issue 5828.
Long story short, the polyfill guard confuses webpack in certain circumstances:
webextension-polyfill/src/browser-polyfill.js
Line 9 in 8914541
This got me thinking, any reason why something simpler like
if (!window.browser) {
is not used here instead?The text was updated successfully, but these errors were encountered: