Uncaught TypeError: Cannot read properties of undefined (reading 'sendMessage')
微wx笑 2023-02-18【运维日志】 2 0关键字: Chrome 扩展程序 extensions
Chrome扩展程序错误:Uncaught TypeError: Cannot read properties of undefined (reading 'sendMessage')
Chrome扩展程序错误:Uncaught TypeError: Cannot read properties of undefined (reading 'sendMessage')
相关代码:
function GM_xmlhttpRequest(option){ chrome.runtime.sendMessage({event: "xhr", data:option }, function (res) { //option.onload(res); console.log(res); if (res.event == "xhr" && !res.err){ option.onload(res); } }); }
解决方法:
添加相关的判断
if (!chrome || !chrome.runtime || !chrome.runtime.sendMessage){ console.log("!chrome.runtime", chrome); return false; }
本文由 微wx笑 创作,采用 署名-非商业性使用-相同方式共享 4.0 许可协议,转载请附上原文出处链接及本声明。
原文链接:https://www.ivu4e.cn/blog/service/2023-02-18/1724.html