SFSafariApplication.openWindow(with:) not working

I am trying to build a utility application on macOS to manage a number of Safari windows and/or tabs.

The first task that stumps me is opening a new window.

I went back to the basic, created a new "Safari Extension App" project in Xcode 13.2.1.

The sample code includes

SFSafariApplication.showPreferencesForExtension(withIdentifier:)

and that works fine. But when I add my call to :

SFSafariApplication.openWindow(with: URL(string: "https://www.apple.com")!)

then nothing happens.

I tried adjusting the content of NSExtension in the Info.plist of the web extension handler, and a number of other things in the manifest, I verified that my extension was well loaded and active, but without any success with openWindow.

Is there any obvious caveat I should be aware of when dealing with SFSafariApplication? Among other questions, should openWindow(...) be in the main app, in the native extension, or either?

Is your extension Web Extension format or Safari App Extension?

In the case of Web Extensions, ensure you have proper permissions in your manifest.

  • https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/create
  • https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/windows (window api docs if you really want to open a new window)

Create a new tab with Web Extension:

browser.tabs.create({url: "https://www.apple.com"}, response => {
    // ...
});

Create new tab with Safari App Extensions:

func openTab() {
    guard let url = URL(string: "https://apple.com/") else { return }
    SFSafariApplication.getActiveWindow { (window) in
        window?.openTab(with: url, makeActiveIfPossible: true) { (tab) in
            // ...
        }
    }
}
SFSafariApplication.openWindow(with:) not working
 
 
Q