【问题标题】:CHROME-EXTENSION: chrome.runtime.lastError no tab with id errorCHROME-EXTENSION: chrome.runtime.lastError no tab with id error
【发布时间】:2022-01-19 07:50:27
【问题描述】:

我正在开发一个创建 google chrome 扩展程序的项目,并且我正在其中使用 chrome API。现在,我正在尝试在更新选项卡时使用我的 handleTabUpdate 函数。但是,我收到了Unchecked runtime.lastError: No tab with id: 60

我该如何解决这个问题?这是我的代码:

chrome.tabs.onUpdated.addListener(handleTabUpdate)
function handleTabUpdate(tabId, info) {
  if (info.status === 'loading') {
    store.dispatch({ type: 'RESET_TABHOSTS' })
    chrome.tabs.get(tabId, (activeTab) => {
      if (tabId === store.getState().currentTab['id']) {
        store.dispatch({ type: 'ACTIVE_TAB', payload: activeTab })
      }
    })
  }
}

【问题讨论】:

    标签: javascript typescript google-chrome-extension chrome-extension-manifest-v3


    【解决方案1】:

    我的猜测是您要查找的选项卡已关闭,因此当您尝试通过id 获取它时,操作失败。
    为避免该错误,我的建议是首先query 所有选项卡,然后查看结果中是否存在具有特定id 的选项卡。如果是,请按照您的逻辑运行 chrome.tabs.get()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-27
      • 2019-01-19
      • 2023-02-12
      • 2018-07-05
      • 1970-01-01
      • 1970-01-01
      • 2015-12-06
      相关资源
      最近更新 更多