Does anyone know what the replacement for the following legacy extension code block to launch a MacOS app is in the new Safari Extensions?
safari.application.activeBrowserWindow.activeTab.url = "{app_url_scheme}://"
We are currently working on transitioning from a legacy extension to support the newer Safari Extensions framework. In the legacy extension we used the following piece code in the global.html file to launch our Mac OS app:
safari.application.activeBrowserWindow.activeTab.url = "{app_url_scheme}://......."
It seems that the comparable code in the new Safari Extension framework would be the following:
guard let url = URL(string: "{app_url_scheme}://") else {
return
}
SFSafariApplication.getActiveWindow {(activeWindow: SFSafariWindow?)in
activeWindow?.openTab(with: url, makeActiveIfPossible: false,
completionHandler: { (activeTab: SFSafariTab?) in
print("openTab completed")
})
}
However, while the tab will open just fine if it's something like " https://www.cnn.com ", it won't do anything if it's just "{app_url_scheme}://". Furthermore, I can type in "{app_url_scheme}://" to the Safari browser and it launches the app just fine, so I know it's not a registration problem.
For anyone stumbling across this in the future, it seems the code to launch a MacOS app would be the following:
guard let url = URL(string: "{app_url_scheme}") else {
return
}
NSWorkspace.shared.open(url)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.