javascript - Chrome 扩展本机消息传递语法错误
问题描述
我有一个问题,我的 chrome 扩展在尝试与本机主机应用程序通信时返回此错误。特别是在传递 helo 消息以确保已安装主机应用程序时。
错误:在 chrome-extension://lafoonpfkflnebpoacdbcojcbdhebifh/background.js:35:20 处调用表单 runtime.sendNativeMessage(string, string, function) 与定义 runtime.sendNativeMessage(string application, object message, optional function responseCallback) 不匹配
我尝试传递一个预先存在的对象,一个在 sendNativeMessage 中定义的对象,例如 sendNativeMessage(string,{object:"object"},function) 和一个最近通过新对象定义的对象。
编辑:我也试过 var nativeMessageObject = {};
我觉得我一定是在这里吠错了树什么的。下面是我目前修剪到相关区域的代码。
console.log("Recieved helo host app. Attempting to contact host app.")
var nativeMessageObject = new Object();
nativeMessageObject.data = "helo";
chrome.runtime.sendNativeMessage('appName', nativeMessageObject, function(response) {
console.log("Host app responded: " + response)
switch (response) {
case "ehlo":
console.log("Host app responded with ehlo")
sendResponse({
data: "ehlo host app"
})
break;
default:
console.log("Error: " + Json.stringify(chrome.runtime.lastError))
sendResponse({
data: "Error: " + Json.stringify(chrome.runtime.lastError)
})
break;
}
})
任何援助将不胜感激。
编辑:现在已经尝试过 3 台不同的机器,所有情况下的错误都是相同的。
解决方案
推荐阅读
- python-3.2 - 我正在尝试将单选按钮连接到 listWidget
- python - Python蓝牙消息丢失?
- azure - 更新 azure 容器实例的镜像
- laravel-5 - Laravel 5 如何为 S3 文件存储配置添加前缀?
- model-view-controller - Dialogflow Webhook C# 集成
- php - php缓存旧脚本7.2
- java - 如何让我的个人服务器反复播放音乐并通过 Java 的 URL 收听?
- python - 异常:工作簿析构函数中捕获的异常。workbook.python 可能需要显式 close()
- powershell - 使用 powershell 通过 sftp 协议将多个本地文件夹及其内容移动到远程服务器
- python - 如何恢复预训练模型以初始化参数