I'm currently working on a Safari App Extension for specific site site (example.com for example) and configure toolbar item to show popover. But if safari have not tab with loaded site.com then this site must be loaded in new tab. Code in SafariExtensionHandler
override func popoverWillShow(in window: SFSafariWindow) {
if SafariExtensionHandler.thePage == nil {
let theURL = URL(string: "https://example.com")
window.openTab(with: theURL, makeActiveIfPossible: true)
}
}
static property thePage
get its value when handler receive first message from script, but there need some time for page loading and message from script will be send. While the page is loading second click on extensions toolbar item open new tab with example.com, next click open next tab... Block new tab opening I tried like this
override func popoverWillShow(in window: SFSafariWindow) {
if SafariExtensionHandler.thePage == nil && loadingInProgress != true {
loadingInProgress = true
let theURL = URL(string: "https://example.com")
window.openTab(with: theURL, makeActiveIfPossible: true)
}
}
Because all tabs in Safari lives in sandbox opning new tab reset all property of SafariExtensionHandler to it default value. How to prevent open multiply tabs. Thank you.