首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >chrome.runtime.sendMessage返回参数为undefined?

chrome.runtime.sendMessage返回参数为undefined?

提问于 2019-04-12 18:08:47
回答 0关注 0查看 1.4K

我想做一款能录屏并生成视频文件的插件,现在进度到chrome.runtime.sendMessage调用的时候卡住了我的代码是这样的:

代码语言:js
复制
//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"
    ]
  }
}

找了两天了有没有大佬知道的,在线等,急。。。谢谢!

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档