chrome.runtime undefined

3,075 阅读1分钟

在浏览器中读取cfca的ukey证书信息,完全相同的页面,一个可以正常使用,一个报错,错误信息是

TypeError: Cannot read property 'sendMessage' of undefined

at nmCryptoKit.js:19

at new Promise (<anonymous>)

at SendMessageforChrome (nmCryptoKit.js:18)

at SendMessage (nmCryptoKit.js:64)

at nmCryptoKit.js:121

报错是因为调用chrome.runtime.sendMessage时runtime未定义,中文资料没查到根本原因,终于在stackoverflow找到了,链接如下:
why chrome.runtime undefined by http but work fine by https

其实很简单,chrome插件默认https请求才能建立连接,此外插件中的manifest.json文件对于可以建立连接的url进行了定义,对插件的manifest.json进行修改就行。

"externally_connectable": {

"matches": [

  "http://test.yoursite.in:9090/*",

  "*://*.chromium.org/*"

]

},