user3851593
user3851593

Reputation: 27

Chrome Extension Resources must be listed in the web_accessible_resources manifest key

I'm trying to send a httpget request in chrome but I get this error Resources must be listed in the web_accessible_resources manifest key

here's my button code

contentInput.onclick = function(){
    var assetid = $('.thumbnail-span').attr("data-3d-url")
    var baseurl = 'http://www.roblox.com'
    var xhr = new XMLHttpRequest();
    xhr.open("GET", chrome.extension.getURL(baseurl + assetid), true);
    var result = xhr.responseText;
    xhr.send();
    console.log(result)
        chrome.extension.sendRequest({
            action: "EditContent",
            type: assetType,
            name: assetName, 
            content: contentData
        })

and my manifest file

{

        "name": "ROBLOX Object Downloader .obj",
        "short_name": "OBJDownloader",
        "description": "Allows you to quickly download assets from the browser as a .obj ",
        "version": "1.0.0",
        "icons": {"128":"icon.png"},
        "permissions": [
            "http://*.roblox.com/*",
            "http://*.rbxcdn.com/*",
            "downloads",
            "downloads.open"
        ],
        "background": {"scripts":["background.js"]},
           "content_scripts": [
                    {
                            "matches": ["http://*.roblox.com/*-item?id=*"],
                            "js": ["item.js","jquery.js"]
                    },
                    {
                            "matches": ["http://*.roblox.com/*ser.aspx*"],
                            "js": ["user.js","jquery.js"]
                    },
                    {
                            "matches": ["http://*.roblox.com/*atalog/*"],
                            "js": ["cataloginsert.js","jquery.js"]
                    }
            ],
        "manifest_version": 2
    }

Upvotes: 0

Views: 3882

Answers (1)

apsillers
apsillers

Reputation: 116030

The chrome.extension.getURL function is used to get a file from your own computer located inside the extension's directory:

string chrome.extension.getURL(string path): Converts a relative path within an extension install directory to a fully-qualified URL.

This means your Ajax request is trying to access a URL like

chrome-extension://aaaaaabbbbbccccccdddddd/http://www.roblox.com/some-asset-id

In order to access files through chrome-extension://, you have to make them explicitly accessible to web pages through the web_accessible_resource manifest field.

However, you probably just want to get the web URL http://www.roblox.com/some-asset-id. In case, getURL is completely inappropriate. Simply do something like:

xhr.open("GET", baseurl + assetid, true);

Your code has an additional problem, which is that it doesn't wait for the asynchronous Ajax call to complete. You should wait for the load event and then read responseText:

contentInput.onclick = function(){
    ...
    var xhr = new XMLHttpRequest();
    xhr.open("GET", chrome.extension.getURL(baseurl + assetid), true);

    xhr.addEventListener("load", function() {
        var result = xhr.responseText;
        console.log(result);
        doSomethingElseWith(result);
        // all uses of `result` must be inside this function
    });

    xhr.send();

    ...

Upvotes: 5

Related Questions