Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在新的Chrome窗口中打开几个选项卡_Javascript_Google Chrome Extension_Bookmarks - Fatal编程技术网

Javascript 在新的Chrome窗口中打开几个选项卡

Javascript 在新的Chrome窗口中打开几个选项卡,javascript,google-chrome-extension,bookmarks,Javascript,Google Chrome Extension,Bookmarks,我想模拟任何书签文件夹的Chrome书签管理器上下文菜单项“在新窗口中打开所有书签”。早上,当我启动Windows8.1和Chrome时,4个文件夹的书签应该出现在4个单独的Chrome窗口中 以下是我为打开一个新窗口所做的努力: manifest.json { "manifest_version": 2, "name": "MyChromeExtension", "description": "Description of my Chrome Extension.",

我想模拟任何书签文件夹的Chrome书签管理器上下文菜单项“在新窗口中打开所有书签”。早上,当我启动Windows8.1和Chrome时,4个文件夹的书签应该出现在4个单独的Chrome窗口中

以下是我为打开一个新窗口所做的努力:

manifest.json

{
    "manifest_version": 2,
    "name": "MyChromeExtension",
    "description": "Description of my Chrome Extension.",
    "version": "1.0",
    "background": {
        "scripts": [ "atExtensionLoad.js" ],
        "persistent": false
    },
    "permissions": [ "tabs", "bookmarks" ],
    "icons": {
        "16": "images/get_started16.png",
        "32": "images/get_started32.png",
        "48": "images/get_started48.png",
        "128": "images/get_started128.png"
    }
}
atExtensionLoad.js

'use strict';

chrome.runtime.onInstalled.addListener(function () {

    // Search the bookmarks for the folder with the name "Spotify"
    chrome.bookmarks.search("Spotify", function (bookmarkTreeNodes) {
        if (bookmarkTreeNodes.length > 0) {
            // Open all bookmarks of the folder
            openNewWindow(bookmarkTreeNodes[0]);
        }
    });

    // Should open all bookmarks of the given folder inside a new Chrome window
    function openNewWindow(bookmarkTreeNode) {
        // Get all bookmarks of the folder ...
        chrome.bookmarks.getChildren(bookmarkTreeNode.id, function (tabs) {
            // ... and open them as additional tabs inside the existing window
            for (var i = 0; i < tabs.length; i++) {
                // A
                chrome.tabs.create({
                    url: tabs[i].url
                });
                // B (has the same effect as A)
                //window.open(tabs[i].url);
            }
        });

        // One possibility: How can I push the opened tabs into a new Chrome window?
    };
});
“严格使用”;
chrome.runtime.onInstalled.addListener(函数(){
//在书签中搜索名为“Spotify”的文件夹
chrome.bookmarks.search(“Spotify”,函数(bookmarkTreeNodes){
如果(bookmarkTreeNodes.length>0){
//打开文件夹的所有书签
openNewWindow(书签树节点[0]);
}
});
//应该在新的Chrome窗口中打开给定文件夹的所有书签
函数openNewWindow(书签树节点){
//获取文件夹的所有书签。。。
chrome.bookmarks.getChildren(bookmarkTreeNode.id,函数(选项卡){
//…并将其作为现有窗口内的附加选项卡打开
对于(变量i=0;i
类似于:

chrome.bookmarks.getChildren(bookmarkTreeNode.id, function (tabs) {
    //create a new window with all the bookmarks, each on one tab
    chrome.windows.create({url: tabs.map(tab=>tab.url)});
});

onInstalled是非常罕见的事件。可能想使用onStartup或更好的chrome.alarms API。