从Safari应用程序扩展中关闭标签页

时间:2018-10-25 07:02:48

标签: safari tabs safari-extension safari-app-extension

我很难找到一种方法来关闭Safari App Extension中的标签页。

我可以使用

打开标签页
close()

但是返回的SFSafariTab和SFSafariWindow都没有performClose()(或window.close();)。

我可以向扩展的JS端发送友好消息并运行target="_blank",但这仅限于也通过Javascript创建的标签。用户打开的任何标签或public class IndexTest { public static void main(String[] args) throws Exception { StopWatch stopwatch = new StopWatch(); stopwatch.start(); File folder = new File("D:\\PDF1"); File[] listOfFiles = folder.listFiles(); for (File file : listOfFiles) { if (file.isFile()) { HashSet<String> uniqueWords = new HashSet<>(); String path = "D:\\PDF1\\" + file.getName(); try (PDDocument document = PDDocument.load(new File(path))) { if (!document.isEncrypted()) { PDFTextStripper tStripper = new PDFTextStripper(); String pdfFileInText = tStripper.getText(document); String lines[] = pdfFileInText.split("\\r?\\n"); for (String line : lines) { String[] words = line.split(" "); for (String word : words) { uniqueWords.add(word); } } // System.out.println(uniqueWords); } } catch (IOException e) { System.err.println("Exception while trying to read pdf document - " + e); } Object[] words = uniqueWords.toArray(); String unique = uniqueWords.toString(); // System.out.println(words[1].toString()); for(int i = 1 ; i <= words.length - 1 ; i++ ) { MysqlAccessIndex connection = new MysqlAccessIndex(); connection.readDataBase(path, words[i].toString()); } System.out.println("Completed"); } } stopwatch.stop(); long timeTaken = stopwatch.getTime(); System.out.println(timeTaken); 都将被阻止。

第三个选项似乎是不推荐使用的Safari JS扩展API。我尚未成功完成这项工作,将时间花在这样的死胡同上感觉很棘手。

1 个答案:

答案 0 :(得分:1)

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);