-
Notifications
You must be signed in to change notification settings - Fork 209
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
Will this project get support for Safari? #234
Comments
it's only for macOS and not iOS fyi |
If the company is making efforts to make this available on macOS then it might lead to it later being ported to iOS. |
I've been looking into porting my addons to Safari but there is one crucial feature missing - the Would implementing this feature for Safari be outside of scope for this polyfill? |
I didn't spent yet enough time on tracking down all the differences in the Safari implementation to answer that question in a way as complete and final as I would like, but the following are some initial thoughts:
About the support for the webextension-polyfill/src/browser-polyfill.js Lines 377 to 386 in b0596ad
And so as a short term workaround, sendResponse should work fine across the 3 implementation (Firefox, Safari and Chrome). |
Thanks @rpl for the info! But I guess I could write my own simple polyfill, something like this should work: // if (IS_SAFARI) do this:
browser.runtime.onMessage.addListener = new Proxy(browser.runtime.onMessage.addListener, {
apply: (addListener, thisArg, [handler]) => addListener.call(thisArg, (message, sender, sendResponse) => {
const result = handler(message, sender, sendResponse);
if (result instanceof Promise) {
result.then(sendResponse);
return true;
}
if (result === true) return true;
})
}); EDIT: I've just tested it and it works. But I've edit it a bit to still support |
I ran into this issue this weekend. Also, I noticed that safari did not fire events for |
Wonder why there is no cross-browser extension framework yet on the market. |
Years ago there was no cross-browser compatible API. These days we do, and the compatibility is going to improve even further by the recent launch of the WebExtensions Community Group - https://www.w3.org/community/webextensions/2021/06/04/forming-the-wecg/ |
+1000 on that. I went to https://github.com/fregante/Awesome-WebExtensions hoping to find something new... and nope. At least Chrome has now shiny new docs on Extensions: https://developer.chrome.com/docs/extensions/ |
Do you have a consistent way of checking whether or not it is running in Safari in the code, for |
Nope, but you can probably parse the value from the |
@Juraj-Masiar I also have a setup which is using webpack to make a build for each browser, any chance you could elaborate on how you added it using that? I'm using webextension-toolbox and I tried to write a custom webpack script for the safari build using it but couldn't quite get it working right. |
Just look at the DefinePlugin for Webpack. It will replace all global variables with the specified name. For example this is what I use in the new webpack.DefinePlugin({
$IS_FIREFOX: IS_FIREFOX || IS_THUNDERBIRD,
$NOT_FIREFOX: !IS_FIREFOX,
$IS_THUNDERBIRD: IS_THUNDERBIRD,
$IS_CHROME: IS_CHROME || IS_SAFARI, // to make it simple, Safari will inherit existing Chrome codebase
$IS_SAFARI: IS_SAFARI,
$IS_EDGE: IS_EDGE,
$IS_DEV: IS_DEV,
$IS_PROD: IS_PROD,
$IS_WEB: IS_WEB,
$IS_EXT: !IS_WEB,
$IS_NODE: IS_NODE,
$IS_TEST: false,
}), But again, terrible testing, terrible inter-project integration. |
Do environment variables get loaded in a live browser extension? |
I have no idea :). I use them only in the backend, but that's integrated in the Nestjs framework I use. |
This is a generic StackOverflow question, let's not notify everyone for unrelated requests 😅 |
Returning to topic, I've been using This issue probably is just about official support and testing in the repo, but you don't necessarily have to wait for it, as a user. |
Sorry about that 😓 the user agent checking works find for the popup but I still haven't been able to find a consistent way to determine which browser a background script is running in (besides the custom webpack scripts @Juraj-Masiar mentioned). That's the only reason I asked here. |
FYI, Safari does support Promise replies in I think this issue can be closed. |
Thanks for checking. It is also listed in the BCD: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/Runtime/onMessage#browser_compatibility (to those interested, Chrome also expressed interest in implementing Promise support in onMessage) |
In a WWDC session, Apple announced support for Web extensions on macOS and has provided conversion tools to port extensions.
The official documentation is at the link: https://developer.apple.com/documentation/safariservices/safari_web_extensions
The text was updated successfully, but these errors were encountered: