我正在使用一次性Chrome钱包付款为chrome商店开发打包应用程序.对于我的应用程序,我需要在运行时检查用户是否购买了应用程序,以决定它是演示功能还是完整功能.
根据chrome identity API文档:
要使应用程序ID保持不变,您需要将已安装的manifest.json中的密钥复制到源清单.
我有2个关于此程序的问题:
1)在什么条件下我的申请的ID可能会改变?我试图重新安装应用程序并进行更新,但应用程序ID保持不变..如果没有办法更改应用程序ID,为什么我需要此程序?
2)如何将带有manifest.json(包含"key"字段)的zip存档上传到chrome仪表板?问题是上传者向我抛出错误:
发生错误:无法处理您的商品.
清单中不允许使用关键字段.
google-chrome chromium google-chrome-extension google-chrome-devtools google-chrome-app
我有一个网页,里面有我自己需要执行的脚本和变量,并从我的扩展的Background.js中检索返回值.
我理解(我认为!)为了与网页进行交互,必须通过chrome.tabs.executeScript或ContentScript来完成,但因为代码必须在原始页面的上下文中执行(为了具有范围)对于脚本和变量),需要先将其注入页面.
在Rob W的这篇精彩文章之后,我能够调用页面级脚本/变量,但我很难理解如何以这种方式返回值.
这是我到目前为止所得到的......
网页代码(我想与之交互):
<html>
<head>
<script>
var favColor = "Blue";
function getURL() {
return window.location.href;
}
</script>
</head>
<body>
<p>Example web page with script content I want interact with...</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
manifest.json:
{
// Extension ID: behakphdmjpjhhbilolgcfgpnpcoamaa
"name": "MyExtension",
"version": "1.0",
"manifest_version": 2,
"description": "My Desc Here",
"background": {
"scripts": ["background.js"]
},
"icons": {
"128": "icon-128px.png"
},
"permissions": [
"background",
"tabs",
"http://*/",
"https://*/",
"file://*/", //### (DEBUG ONLY)
"nativeMessaging"
]
}
Run Code Online (Sandbox Code Playgroud)
background.js …
我正在创建Google Chrome扩展程序(我的第一个扩展程序),并且我希望将扩展程序中的邮件发送到当前选项卡.
我正在关注文档:
https://developer.chrome.com/apps/runtime#event-onMessage
该扩展将一个小的外部JS加载到选项卡的HTML中,该HTML包含以下代码:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(request)
}
);
Run Code Online (Sandbox Code Playgroud)
加载JS后,我收到以下错误:
Uncaught TypeError: Cannot read property 'onMessage' of undefined
.
打开控制台和键入chrome
,我可以看到运行时不是属性chrome
.
看起来我做错了什么,但是什么?我需要在manifest.json
文件中添加内容吗?
Chrome版本39.0.2171.71米
谢谢.