Reputation: 27
My last and final question. I cannot seem to use the .downloads function in the extension. I get the error
Cannot read property 'download' of undefined
Beware I removed some of the code so it can fit here My code is
var contentInput = document.createElement("div")
contentInput.innerHTML = '<div style="position:relative; width: 145px;height: 30px;right: 0px;left: 14px;padding-top: 0px;top: 0px;"><div class="btn-primary btn-medium" style="position: absolute;left: 0px;" draggable="true">Download .OBJ</div><p style="position:relative; top: 33px; font-size:15px">Click to download the OBJ version of this asset.</p> </div>'
contentInput = contentInput.children[0].children[0]
localStorage.setItem("OBJURL", jsonObject.Url); //It's saved!
});
var objurl = localStorage.getItem("OBJURL");
SendRequest(objurl, function (objfinal) {
});
chrome.downloads.download({url:objurl,filename:"wat23333.obj",conflictAction:"overwrite"})
chrome.extension.sendRequest({
action: "EditContent",
type: assetType,
name: assetName,
content: contentData
})
}
Manifest file
Permissions
"permissions": [
"http://*.roblox.com/*",
"http://*.rbxcdn.com/*",
"downloads",
"downloads.open"
],
Upvotes: 1
Views: 2406
Reputation: 2319
For me Xan's solution also didn't work. What worked for me was to go to chrome://extensions and remove the extension from chrome. Afterwards, I re-added the extension. Then it worked.
Upvotes: 0
Reputation: 77571
Devlin's guess was almost correct.
It happens when either of those conditions hold:
You have the second case, apparently. You'll need to pass a message to the background page and handle the action from there.
Upvotes: 5
Reputation: 21
The error "Cannot read property 'download' of undefined" means that the chrome object doesn't have the downloads property on it. This is usually indicative of not having permission to access the API - do you request the "downloads" permission in your manifest?
Upvotes: 2