在Google Chrome中以编程方式固定标签

dluptydi  于 2023-06-19  发布在  Go
关注(0)|答案(1)|浏览(143)

我做了一个a small Chrome extension,它可以打开一个新的标签,并在其中显示你的书签。
我想这个新标签自动固定。代码如下:

chrome.tabs.create({
                    "url": chrome.extension.getURL("skwares.html")
                },
                function(tab) {
                    tab.highlighted = true;
                    tab.active = true;
                    tab.pinned = true;
                });

新选项卡打开正常,但未固定。我错过了什么?

iyfjxgzm

iyfjxgzm1#

你只需要将pinned选项移到create属性中,而不是回调:

chrome.tabs.create({
  url: "skwares.html",
  pinned: true
}, function(tab) {
  console.log('created', tab);
});

另外,在默认情况下,当你创建一个新标签时,“active”会被设置为true,所以你不需要再次设置它。

相关问题