简体   繁体   English

使用 chrome.windows.create 和 chrome.tabs.create 在隐身模式下打开多个链接

[英]Open multiple links in incognito with chrome.windows.create and chrome.tabs.create

I'm making a chrome extension for myself where i want to open multiple tabs in incognito for new sessions for my websites,我正在为自己制作一个 chrome 扩展,我想在隐身模式下为我的网站打开多个标签,

When the function is called it should open a new incognito window and open 4-5 tabs there, but currently the links are opened in the window where the chrome extension button has been clicked.当该函数被调用时,它应该打开一个新的隐身窗口并在那里打开 4-5 个选项卡,但目前链接是在单击 chrome 扩展按钮的窗口中打开的。

Current code:当前代码:

    chrome.windows.create({focused: true, incognito: true }, function(win) {
          for (var i = 0; i < links.length; i++) {
            array = links[i].href;
            chrome.tabs.create({ 
                url: array, 
                selected: true
            })
          }
    });

What should I change to make it open the new tabs in the incognito window?我应该更改什么以使其在隐身窗口中打开新选项卡?

Apparently the callback is invoked right after the window wascreated but before it was focused .显然,在创建窗口之后但在聚焦之前调用回调。

Specify the new window id in chrome.tabs.create options explicitly:chrome.tabs.create选项中明确指定新窗口 ID:

chrome.tabs.create({ 
    url: 'http://example.com', 
    windowId: win.id,
});

I also wanted to open several tabs in a newly created incognito window.我还想在新创建的隐身窗口中打开几个选项卡。 Using the object received from creating the window to open the tabs with.使用从创建窗口收到的对象来打开选项卡。

        chrome.windows.create({
            url: splashNodes[0].url,
            incognito: true,
        }, w => {
            console.log({w});
            for (let i = 1; i < splashNodes.length; i++) {
                chrome.tabs.create({
                    url: splashNodes[i].url,
                    windowId: w.id
                });
            }
        })

The window created as incognito didn't give anything back in the callback.创建为隐身的窗口在回调中没有返回任何内容。 chrome.windows.onCreated didn't fire either. chrome.windows.onCreated 也没有触发。 Adding permission {"incognito":"split"} to the manifest as suggested by someone didn't help.按照某人的建议向清单添加权限 {"incognito":"split"} 没有帮助。

What solved my problem was when the user granted incognito permission to my extension (extension manager, details) though, as explained on https://developer.chrome.com/extensions/permission_warnings .解决我的问题是当用户授予我的扩展程序(扩展程序管理器,详细信息)隐身权限时,如https://developer.chrome.com/extensions/permission_warnings 所述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM