I am trying to download a file (image) from a URL via a Chrome Extension using chrome.downloads, but for some reason chrome.downloads
is undefined
(getting the warning: Cannot read property 'download' of undefined
). I am basing my attempt on example from Google.
My test-extension does not have any popup, just a basic manifest and an extremely simply JavaScript file.
manifest.json:
{
"manifest_version": 2,
"name": "Testing chrome.downloads.download",
"version": "0.0.1",
"permissions": [
"activeTab",
"downloads",
"<all_urls>"
],
"content_scripts": [{
"matches": [
"http://www.example.com/*"
],
"js": [
"jquery.js",
"index.js"
]
}]
}
index.js:
$(document).ready(function () {
link = 'http://example.com/image.jpg';
chrome.downloads.download({
url: link,
filename: './' + link.substr(link.lastIndexOf('/')+1),
saveAs: false
});
});
So, how can I make this work?