我正在尝试从网页到打包的应用程序进行通信.想法是让网页从串行设备读取数字.因为我想访问串行设备,我需要一个打包的应用程序,不能使用扩展.这与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并没有抱怨.
有什么想法吗?提前致谢.