Safari Web Extension Sign in With Google

340 views Asked by At

Safari now can use web extensions.

But browser.identity or chrome.identity is not supported. So launchWebAuthFlow is not working.

In the docs they just say.

identity Not supported. Initiate an OAuth flow in a new tab.

How can I do it? Is there any example?

1

There are 1 answers

0
emma ray On

It currently seems not possible to implement a OAuth flow in a safari web extension.

There's an Apple Developer thread with a workaround involving redirecting to a random URL and intercepting this in webRequest.onBeforeRedirect, but it appears to be broken as of Safari 15.4: https://developer.apple.com/forums/thread/670165

2021:

As a workaround, you may use whatever reachable URL as an OAuth redirect URL and use webRequest.onBeforeRedirect to capture the redirect attempt and 'force redirect' e.g. by tabs.update.

2023:

The webRequest API is not available from non-persistent background pages (or service workers) and v3 forbids persistent background pages. The declarativeNetRequest allows redirecting to a path in your extension, but via this route the original request is not available. A workaround for this is to redirect using a regexSubstitution. This works fine in Chrome, but not in Safari, because redirects to safari-web-extension:// are blocked.

The OP has created a webkit bug report you may find useful: https://bugs.webkit.org/show_bug.cgi?id=256054

Error: Redirection to URL with a scheme that is not HTTP(S)