Reputation: 23
Chrome keeps saying: "Cannot read property 'onBeforeRequest' of undefined". I can't figure out why.
background.html:
<html>
<head>
<script type="text/javascript">// <![CDATA[
try
{
chrome.webRequest.onBeforeRequest.addListener(function(e){alert("onBeforeRequest")},{urls: ["http://*/*", "https://*/*"]}, ["blocking"]) ;
}
catch (ErrorMessage)
{
alert('page:'+ErrorMessage) ;
}
// ]]></script>
</head>
</html>
manifest.json:
{
"name": "first extension",
"version": "1.0",
"description": "first extension",
"browser_action": {
"default_icon": "icon.gif",
"popup": "popup.html"
},
"permissions":
["tabs", "chrome.webRequest", "webNavigation", "management", "http://*/*", "https://*/*"],
"background_page": "background.html"
}
Upvotes: 2
Views: 7546
Reputation: 349042
The correct way to request permissions for the webRequest
API is webRequest
(without chrome.
).
"permissions": [
"tabs",
"webRequest",
"webNavigation",
"management",
"http://*/*",
"https://*/*"
],
Upvotes: 2