I am having a surprisingly hard time finding a way to close a tab from a Safari App Extension.
I can open a tab with
SFSafariApplication.getActiveWindow(completionHandler: {
$0?.openTab(with: url, makeActiveIfPossible: true)
})
Yet neither the returned SFSafariTab, nor the SFSafariWindow have close()
(or performClose()
).
I can send a friendly message to the JS side of the extension and run window.close();
, but this is limited to tabs that were also created via Javascript. Any tabs opened by the user, or target="_blank"
are blocked off.
The third option seems to be the deprecated Safari JS Extension API. I have not yet succeeded in making this work, and it feels icky to invest time into such a dead end.
Now in safari 12.1 have facility to close current tab.
/// Closes this tab. If this is the last tab in its window, the window is also closed.
- (void)close SF_AVAILABLE_MAC_SAFARI(12_1);