首页 > 解决方案 > 我想在执行 chrome.tabs.executeScript(...) 时避免 chrome.runtime.lastError

问题描述

我正在开发 chrome 扩展。我尝试使用 注入脚本标签chrome.tabs.executeScript,但它在特定 URL 中发生了一些错误。

我使用此页面作为参考,但控制台中有很多错误日志...

我知道我的扩展程序无法在 Chrome 网上商店或 Chrome 内部页面上运行,我对此表示满意,但该显示让用户看起来就像扩展程序已损坏一样。我想以某种方式避免错误(例如,URL 访问过滤器??),但我不知道该怎么做。

谁能给我一些建议??

chrome.tabs.executeScript(e.tabId, {"allFrames": false, "matchAboutBlank": true, "runAt": 'document_start', "frameId": e.frameId, "file": "/inject.js"}, function(){
  if(chrome.runtime.lastError){
    console.error(chrome.runtime.lastError.message)
  }       
})

在此处输入图像描述

标签: javascriptgoogle-chrome-extensioncontent-scriptexecute-script

解决方案


推荐阅读