Convert Chrome/Firefox Extension to Safari

Hey everyone,


I have a Chrome and Firefox extension that I'm trying to port over to Safari however I'm running into a few issues.


I can't seem to find a way to run similar code to these two functions:

chrome.extension.connect (or browser.runtime.connect in Firefox)

chrome.tabs.query({active: true, currentWindow: true, url: ["http://*/*", "https://*/*"]}, function(tabs) (runs the same on firefox)

Anyone know a workaround in safari that might be useful? I've scoured the web and can't seem to find a good solution.

Answered by Frameworks Engineer in 613755022
There is a xcrun safari-web-extension-converter tool in Xcode 12 Beta to convert extensions. This is covered in Converting a Web Extension for Safari. It will also be covered later today in the Meet Safari Web Extensions WWDC session.

This is not working. I have Safari 14 installed on Catalina end even set it as default browser. Still getting:

Same here.
I'm running:

Code Block console
$ xcrun safari-web-extension-converter /path/to/extension-dir
safari-web-extension-converter requires at least Safari 14.0 to run.
Unable to parse manifest.json at file:///path/to/extension-dir


The manifest.json can be seen at: https://github.com/asciidoctor/asciidoctor-browser-extension/blob/master/app/manifest.json

Anyone has a solution or a way to troubleshoot this issue?

I found that Unable to parse manifest.json at file is thrown if manifest_version is not 2
Latest Chrome extensions use manifest version 3 and looks like Xcode can't handle it.
extension-project % xcrun safari-web-extension-converter ./src/extension
Unable to parse manifest.json at file:///Users/me/tinkering/extension-project/src/extension/

In my case, the extension had several comments in the manifest.json file (eg: // The following will be removed for Chrome during build.). Removing all comments from the JSON resolved the issue I was seeing.

Convert Chrome/Firefox Extension to Safari
 
 
Q