Fixed in Safari 18.0.1
Post
Replies
Boosts
Views
Activity
Whatever best practice materials you found on Firefox / Chrome are mostly applicable for Safari Web Extension too as they share the similar APIs.
storage.managed is not supported in Safari as also stated in MDN.
Safari Web Extension does not fully implement the web extension APIs -- some implementation details deviate from the spec e.g.
no runtime.onMessageExternal https://developer.apple.com/forums/thread/681378
difficult to implement an OAuth flow due to no reachable extension-specific URL https://developer.apple.com/forums/thread/670165
Safari-specific implementation of runtime.sendNativeMessage
And APIs get broken from time to time e.g. :
storage.local.get behaves unexpectedly on Safari 18 https://developer.apple.com/forums/thread/765169
same for tabs.onRemoved on Safari 18 https://developer.apple.com/forums/thread/765343
Collectively, this makes it very difficult to develop JS web extensions for Safari.
for @rtolton, this is an example code:
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.url && changeInfo.url === 'your-reachable-redirect-url') {
// do your post sign-in ceremony
// e.g. take authCode from the query param, etc.
}
})
I have experienced a similar issue where a number of web extensions stop working on Safari 15.4. A deeper investigation shows that this is likely a Safari issue in breaking the web extension 'tabs' API:
chrome.tabs.create doesn't work when the url is a page that's packaged with an extension. It seems
to crash and ruin all chrome.tabs event handlers.
Reproducible scenario:
chrome.tabs.onActivated.addListener(()=> console.log('new active tab')) .. Note: I use onActivated just to test whether event listeners on tabs still works.
Switching between tabs.. You should see the 'new active tab' printed in the console.
chrome.tabs.create({url: chrome.runtime.getURL('/index.html')}) --> a new tab is created. Note: index.html is an html file packaged in your extension.
Switching between tabs..
Expect: 'new active tab' printed in the console as usual
Actual: no 'new active tab' printed in the console…
Note: this problem does not occur when the url is a public reachable URL, nor on Safari 15.3
Version
15.4 (17613.1.17.1.13)
Please fix.
This problem seems to be resolved in Safari Version 15.4 (17613.1.17.1.6).
As a workaround, you may use whatever reachable URL as an OAuth redirect URL and use webRequest.onBeforeRedirect - https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/onBeforeRedirect to capture the redirect attempt and 'force redirect' e.g. by tabs.update - https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/update.
Although this will work, it is far from being elegant. It could even be error-prone. While Firefox offers a decent solution for this, why safari can't / doesn't. So, if it is an intention for Safari not to support this workflow, I would like to submit my post as a change request because this is so common usecase. (or please suggest where I can submit a change request for this???)
Thank you bweinstein for your reply.
I already have "<allurls>" in the permissions key in the manifest.json. I hope <allurls> should cover everything, right?
For clarification, I am talking about
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {...})
The problem is that 'changeInfo' in safari has only one property - 'status'. The other properties are not there, e.g. changeInfo.url. The document states clearly that changeInfo should have url when the update is about url change --> "the tab's URL if it has changed".
Thank you bweinstein for your reply.
I can use chrome.runtime.getURL in safari. That will return a url like 'safari-web-extension://<random-per-xcode-build-id>/'.
I need such a URL in order to configure an oidc-client configuration in my backend such that after a successful login, the user will be redirected to this url -- hence the name redirect url.
The problem is when I use 'safari-web-extension://<random-per-xcode-build-id>/' as the redirect url and it gets redirected (302) by the oidc server, Safari does not allow a redirect to a custom scheme ('safari-web-extension') url. This is what I meant by 'blocking'. This causes a problem for an oidc code flow in general. And I cannot believe I am the only one having this issue. Please help.
Thanks.