我很难找到从Safari App Extension中关闭选项卡的方法。
我可以打开一个标签
SFSafariApplication.getActiveWindow(completionHandler: {
$0?.openTab(with: url, makeActiveIfPossible: true)
})
然而,返回的SFSafariTab和SFSafariWindow都没有close()
(或performClose()
)。
我可以向扩展的JS端发送友好消息并运行window.close();
,但这仅限于通过Javascript创建的选项卡。用户打开的任何标签或target="_blank"
都会被屏蔽掉。
第三个选项似乎是已弃用的Safari JS Extension API。我还没有成功完成这项工作,把时间投入到这样一个死胡同里感觉很蠢。
现在在safari 12.1中有关闭当前标签的功能。
/// 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);