I am making an extension for Google Chrome which uses the Downloads API. I want to download a .jpg file from a website.
I have used these permissions in the manifest:
"permissions": ["downloads", "*://www.thatsite.com/*"]
and the command i am using is:
chrome.downloads.download({"url":"https://www.thatsite.com/images/image1.jpg"});
This gives the following error
"Error during downloads.download: Invalid URL."
Any ideas how to solve this??
I tried with following code, and it is working as expected. I hope you are not on Stable Channel.
Put your complete code, the problem is entirely with URL.
You can refer following code as a reference
Registered browser action and permissions with manifest file.
{
"name": "Download Demo",
"description": "http://stackoverflow.com/questions/14560465/chrome-downloads-download-gives-error-during-downloads-download-invalid-url",
"manifest_version": 2,
"version": "1",
"browser_action": {
"default_popup": "popup.html"
},
"permissions": [
"downloads",
"*://www.google.co.in/*"
]
}
Added <script>
file to comply with CSP .
<html>
<head>
<script src="popup.js"></script>
</head>
<body>
<button id="download">Download</button>
</body>
</html>
Simply passed URL to download API
.
document.addEventListener("DOMContentLoaded", function () {
document.getElementById("download").addEventListener("click", function () {
chrome.downloads.download({
"url": "http://www.google.co.in/images/srpr/logo3w.png"
}, function () {
console.log("downloaded");
});
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.