0

你好,我的扩展有问题。我阻止了一个脚本,webRequest.onBeforeRequest但是当我尝试使用chrome.storage控制台时返回此错误Uncaught TypeError: Cannot read property 'local' of undefined

我的代码:

背景.js

chrome.webRequest.onBeforeRequest.addListener(
    function(details) {
 if( details.url == "http://o1.t26.net/js/application.js?2.0.4" )
            return {redirectUrl: chrome.extension.getURL("load.js") };
    },
    {urls: ["http://o1.t26.net/*.js?2.0.4"]}, ["blocking"]);

加载.js

chrome.storage.local.get('test', function (h){
console.log(h.test);
});

清单.json

{
"content_scripts": [{
"matches": [ "http://www.agust.in/*", "http://agust.in/*" ],
"js": ["test.js"],
"run_at": "document_start",
"all_frames": true
}
],
"description": "TEST",
"icons": {
"16": "icon_one.png",
"48": "icon_two.png",
"128": "icon_three.png"
},
"name": "Test",
"permissions": ["storage", "webRequest", "webRequestBlocking", "http://www.agust.in/*", "http://agust.in/*",  "http://o1.t26.net/*",  "http://t26.net/*"],
"version": "1.4",
"manifest_version": 2,
"web_accessible_resources": [ "load.js"],
"background": {
"scripts": ["background.js"],
"persistent": true
}
}

顺便说一句,脚本(load.js)加载完美,对不起我的 BADDD 英语。

4

1 回答 1

1

You're redirecting a script loaded in a normal web page to load.js in your extension. Although load.js is from your extenison, it's loaded and executed in the web page's context, which has no access to chrome.storage API.

I'd recommend you cancel that request and inject load.js as a content script.

于 2013-08-13T03:46:54.777 回答