我想做一款能录屏并生成视频文件的插件,现在进度到chrome.runtime.sendMessage调用的时候卡住了我的代码是这样的:
//background.js
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
setTimeout(function(){
if(message == "version"){
sendResponse('hi!');
}
},2000);
return true;
});
//content.js
var EXTENSION_ID = 'My_ExtensionID';
chrome.runtime.sendMessage(EXTENSION_ID, 'version', function (response) {
console.log(response); //undefined
}
//manifest.json
{
"manifest_version": 2,
"name": "My Cool Extension",
"version": "0.1",
"content_scripts": [ {
"all_frames": true,
"js": ["content.js" ],
"matches": [ "http://*/*", "https://*/*", "file://*/*" ]
} ],
"permissions": [ "http://*/*", "https://*/*", "storage" ],
"background": {
"scripts": [
"background.js"
]
}
}
找了两天了有没有大佬知道的,在线等,急。。。谢谢!
相似问题