Add support for browsers which don’t support Promises#114
Add support for browsers which don’t support Promises#114ExE-Boss wants to merge 10 commits intomozilla:masterfrom
Conversation
|
The build seems to be failing for reasons unrelated to the patch. needinfo?(@rpl) |
|
@ExE-Boss it is unfortunate that the integration tests are not currently able to show the actual reason for the failure in this case, but the failure is definitely related to the changes applied by this PR. Looking if |
445e7e9 to
73d5e4b
Compare
src/browser-polyfill.js
Outdated
| } | ||
| } | ||
| return supportsPromises; | ||
| })()) { |
There was a problem hiding this comment.
That's a bit wordy, how about this function instead?
function supportsPromises() {
if (typeof browser === "undefined") {
return false;
}
// If `browser.runtime.lastError` doesn’t exist, assume promises are supported.
if (browser.runtime && typeof browser.runtime.lastError !== "undefined") {
return true;
}
if (browser.extension && typeof browser.extension.lastError !== "undefined") {
return true;
}
try {
return isThenable(browser.runtime.getPlatformInfo());
} catch (error) {}
try {
return isThenable(browser.windows.get(browser.windows.WINDOW_ID_CURRENT));
} catch (error) {}
return false;
}
if (supportsPromises()) {There was a problem hiding this comment.
browser.runtime && typeof browser.runtime.lastError !== "undefined" returns true if browser.runtime.lastError exists and false if it doesn’t.
Also, the check needs to check for the case when browser.runtime doesn’t exist, but browser.extension does, and consider the check failed if browser.runtime.lastError exists, but browser.extension.lastError doesn’t for whatever reason.
There was a problem hiding this comment.
consider the check failed if browser.runtime.lastError exists, but browser.extension.lastError doesn’t for whatever reason.
That’s not what your code does. The ternary operator checks for one runtime and then discards extension
There was a problem hiding this comment.
Well, yours discards the one in extension if none exists in runtime.
Also, yours fails the following test:
webextension-polyfill/test/test-browser-global.js
Lines 29 to 59 in 73d5e4b
Edit: Turns out I forgot to change the !==s to ===.
There was a problem hiding this comment.
See #114 (comment):
Oh great, and now Firefox stopped working, again.
|
@bfred-it Oh great, and now Firefox stopped working, again. Honestly, your profile picture perfectly summarises my current reaction to this: |
src/browser-polyfill.js
Outdated
| return isThenable(browser.runtime.getPlatformInfo()); | ||
| } catch (error) { | ||
| // Microsoft Edge doesn’t support `browser.runtime.getPlatformInfo()` | ||
| try { |
There was a problem hiding this comment.
There’s not need to nest this. If there are no errors, the function will return before the second try/catch
It already does that by making |
yeah I did notice that, but I'm thinking (aloud) that I would kind of prefer if we don't use |
The reason why I didn’t rename |
|
Any updates? |
|
Please consider an alternative solution to support Microsoft Edge. |
leonid-shevtsov
left a comment
There was a problem hiding this comment.
This PR worked for our extension after removing the two checks for lastError. Polyfill established the correct API in Chrome and Edge (and Firefox, too).
|
Also, |
|
Is it okay to ask if there's still development on this, and if we can expect "unofficial support" for MS Edge in a foreseeable future? |
|
Edge is becoming a Chromium variant, so this might be pointless. |
This PR isn’t just for Microsoft Edge (even though that is the main reason why this PR got made). This PR is to support browsers which define the Also, even if Edge will switch to Chromium, there’s still the fact that if Microsoft wants to be backwards compatible, they’ll have to keep defining the In fact, Edge doesn’t support the |
|
Since the announcement of Microsoft that Edge switches to Chromium, the effort to support Edge is put on hold until the exact details become available. It is quite likely for Edge to behave identical to Chrome, in which case we don't need any more modifications to support Edge.
I'm not aware of such a browser. Let's keep the main library simple; if anyone wants to develop an extension for non-Chromium Edge browsers, then they could create a build based on this pull request. |
|
@Rob--W The latest Windows 1809 is supported till May 11, 2021. Current solution/workaround is to use 'chrome' object and not 'browser'. But this is not what people want. We want Promises API instead of callbacks which work in all browsers. |
Except that Chromium Edge will certainly include the Also, Opera supports both
Well, Edge matches that description, and Chromium Edge most certainly will too since normal Chromium doesn’t yet use |
"Microsoft Edge will now be delivered and updated for all supported versions of Windows" (source). This implies that supported versions of Windows (including 1809) will receive a Chromium-based Edge browser.
I'd like to see a reputable source that supports this claim.
By "I'm not aware of such a browser", I meant that there is no supported browser (Microsoft is discontinuing their current engine, so that doesn't count) that would get API support through this PR. The polyfill already supports Chromium-based browsers. |
|
As @Rob--W already mentioned in his last round of comments, with the Microsoft announcement related to the MSEdge future there are even less compelling reasons to officially include in the polyfill any workarounds specific to MSEdge (and then maintaining them over the time). There are no other browsers that exposes the MSEdge doesn't have a lot of extensions, and it is very likely that the extensions that they have are already been developed for Chrome, and so I'm not really sure that they need to define the For anyone that still have to work on MSEdge extensions before it is switched to the next Chromium-based version, a better bet may be to do the tweaks needed to make "MSEdge to look like Chromium (and allow the webextension-polyfill to load unmodified)" using the MSEdge specific I'm going to close this PR, #163 and #3 as wontfix, for the reasons described above and in the last round of @Rob--W comments (and I'm not say this lightly, from my point of view it is quite sad that we are losing an additional indipendent implementation of the Extension APIs, and I was really willing to add MSEdge support as much as I could, e.g. that was the reason why I've been working on applying all the changes needed to run all our integration tests on MSEdge in #163), and I'm going to update the 'Supported Browsers' section from the README.md file in this repo accordingly. |
Fixes #3
Closes #43 and closes #61
Alsofixes#68 andcloses#86Depends on
#139(merged)review?(@Rob--W, @rpl)