【问题标题】:Error in invocation of runtime.sendMessage (Chrome API)调用 runtime.sendMessage 时出错(Chrome API)
【发布时间】:2022-07-20 07:17:46
【问题描述】:

目标是在 URL 更改后从后台脚本向内容脚本发送消息。

这是我的功能:

    chrome.tabs.onUpdated.addListener(
      function (tabId, changeInfo, tab){
        if(changeInfo.url && changeInfo.url.includes('https://example')){  
             chrome.runtime.sendMessage(tabId, {warn: 'message'}, function(resp){})
    }
});

但我收到一个错误:错误,在事件处理程序中:TypeError:调用 runtime.sendMessage 时出错(可选字符串 extensionId,任何消息,可选对象选项,可选函数回调):参数“选项”处出错:意外属性:'警告'。

我尝试按照documentation编码,但找不到错误

【问题讨论】:

  • runtime 替换为tabs
  • @wOxxOm 非常感谢您的帮助!我想我以后会有新的问题要问你:)

标签: google-chrome-extension


【解决方案1】:

在我做了类似的事情之前,我遇到了类似的错误

chrome.tabs.sendMessage(tabId, {warn: 'message'});

注意:选项卡,而不是运行时方法。不确定回调。

【讨论】:

    猜你喜欢
    • 2017-04-16
    • 1970-01-01
    • 2014-05-12
    • 2013-09-06
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多