Sorry, due to our recent research, the real issue lies in SFSafariPage.getPropertiesWithCompletionHandler method. This method returns nil for suspended tabs. To reproduce the bug:
- Open the attached sample project, hit run button, and activate the extension
- Open Safari and open two webpages
- Open Console.app and filter information with keyword “#debugtabs#”
- Click the extension button in the toolbar of Safari, the Console.app will print the URLs of the two webpages
- Create new Tab Group with the 2 tabs, then QUIT Safari (Cmd + Q, this will make tabs in tab group suspended when reopen Safari)
- Reopen Safari and go to the new tab group (stay in the default tab, do not click the other tab)
- Click the extension button in the toolbar of Safari, the Console.app will only print the URL of the active webpage, and the properties of the other webpage is now nil.
This behavior is unexpected. Since the webpages’ urls are visible when the tabs aren’t suspended, they should not be hidden just because the tabs are suspended due to memory management. Besides, the webpage urls are also visible by web extension API (browser.tabs.query) no matter the tabs are suspended or not. So, please fix the SFSafariPage.getPropertiesWithCompletionHandler method’s behavior. It is crucial for our tab management extension. Thanks!
Xcode Version: 15.1
I have filed a report, FB13463973, which is a default Safari App Extension with two modifications:
- set the extension permission for all URLs
- replace the method
toolbarItemClicked
with:
override func toolbarItemClicked(in window: SFSafariWindow) {
window.getAllTabs(completionHandler: { tabs in
NSLog("#debugtabs# \(String(tabs.count)) tab(s) detected.")
tabs.forEach { tab in
tab.getActivePage { page in
page?.getPropertiesWithCompletionHandler({ props in
guard let props = props else {
NSLog("#debugtabs# Props is nil.")
return
}
NSLog("#debugtabs# URL: \(String(describing: props.url?.absoluteURL))")
})
}
}
})
os_log(.default, "#debugtabs# The extension's toolbar item was clicked")
}