使用chrome.runtime.sendmessage从网页到打包的应用程序进行通信

 章小胭 发布于 2023-01-16 11:14

我正在尝试从网页到打包的应用程序进行通信.想法是让网页从串行设备读取数字.因为我想访问串行设备,我需要一个打包的应用程序,不能使用扩展.这与Keep Chrome Packaged App在后台运行非常相似?似乎Chrome文档说这是可能的.

如何从常规网页执行chrome.runtime.sendMessage?当我这样做时,我得到*Uncaught TypeError:无法读取未定义的属性'sendMessage'.我的简单功能是:

function doFunction(){
    chrome.runtime.sendMessage(editorExtensionId, {openUrlInEditor: url},
      function(response) {
        if (!response.success)
          handleError(url);
      });
}

我的打包应用程序加载并可以访问串行端口.但我的怀疑是清单不是"启用"常规网页的chrome.runtime.manifest.json的:

{
  "name": "Hello World!",
  "description": "My first Chrome App.",
  "version": "0.1",
  "app": {
    "background": {
      "scripts": ["background.js"]
    }
  },
  "icons": { "16": "calculator-16.png", "128": "calculator-128.png" },
  "permissions": [
    "serial",
    "*://localhost/*"
  ],
  "externally_connectable": {
  "matches": [
      "*://localhost/*"]
}
}

也许它是:// localhost /我正在用于测试.但Chrome并没有抱怨.

有什么想法吗?提前致谢.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有