Chrome 缺少必需的属性“tabId”

vuktfyat  于 2023-01-28  发布在  Go
关注(0)|答案(1)|浏览(293)

在 * background. js * 中,我有一个侦听器,它应该检查页面是否完全加载,然后运行一个内容脚本:

console.log('background.js started');
chrome.webNavigation.onCompleted.addListener(function(tab) {
  chrome.scripting.executeScript({
        target: { tabId: tab.Id, allFrames: true },
        files: ['findname.js'],
      });
    console.log('script execution started')
});

但它返回一个错误:
参数"进样"错误:属性“target”处的错误:缺少必需的属性"tabId"
我尝试过通过创建一个变量"tabId"并将活动选项卡的id赋给它来解决这个问题。

const tabId = chrome.tabs.get(tabId);

但也不管用。
我会感激你的帮助!

np8igboo

np8igboo1#

查看对象的所有字段,字段实际上是tabId。

target: {
            tabId: tab.tabId,
            allFrames: true,
        },

相关问题