"Cannot read property 'sendMessage' of undefined"在一个调用中被抛出,但在另一个调用中没有被抛出(而且它们几乎彼此相邻)



我正在做一个chrome扩展,一个chrome.runtime.sendMessage((调用是有问题的,而其他调用是有问题的;这很奇怪,因为"problem"调用与另一个完全相同,并且调用距离它只有5行。有什么可能的解释吗?

这是我后台的 sendMessage(( 调用.js:

chrome.runtime.onMessage.addListener(function(msg)
{
    ...
    chrome.runtime.sendMessage(timeCount); //not problematic
  }
  else if(msg == "NEED WATCHLIST")
  {
    chrome.runTime.sendMessage(timeCount); //throws error
  }
});

这是我的弹出窗口中的消息.js在后台触发 .addListener.js :

chrome.runtime.sendMessage("NEED TIME");
document.getElementById("settings").onclick = function()
{
     ...   
    chrome.runtime.sendMessage("NEED WATCHLIST");
}

这是我的manifest.json,用于很好的衡量标准(可能根本不相关,哈哈(:

{
  "manifest_version": 2,
  "name": "Drill Sergeant",
  "description": "Regulates time spent on Facebook and YouTube",
  "version": "1.0.1",
  "browser_action": {"default_popup": "popup.html", "default_icon": "images/icon128.png"  },
  "background": {"scripts": ["background.js"]},
  "permissions": ["activeTab", "webNavigation", "notifications", "tabs", "background", "webRequest"],
  "web_accessible_resources": ["censor.html"]
}

谢谢大家,我真的不知道该怎么做...(什么甚至首先触发了"无法读取未定义的属性'sendMessage'"错误?

chrome.run T ime是你的问题。你想要 chrome.run t ime(小写的 't'(

最新更新