SFSafariWindow.getAllTabs method will not get suspended tabs

To reproduce this bug:

  • Create a simple Safari App Extension using the SFSafariWindow.getAllTabs method
  • Open a few tabs in Safari and save them to a named tab group
  • Quit Safari with Command + Q
  • Open Safari and navigate to the saved named tab group (do not navigate to other tabs, those non-active tabs will be suspended until we navigate to them)
  • Trigger the SFSafariWindow.getAllTabs method in our Safari App Extension
  • Ideally we should get all tabs in the tab group of the window, but instead we only get the active tab

Did I miss anything to make it work as expected?

Thank you for your message. Please file a report at http://feedbackassistant.apple.com/ and include a sample project. When complete, please share your Feedback ID here.

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:

  1. set the extension permission for all URLs
  2. 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")
    }
SFSafariWindow.getAllTabs method will not get suspended tabs
 
 
Q