我正在为使用下载API的Google做一个扩展。我想从一个网站下载一个.jpg文件。
我在清单中使用了这些权限:
"permissions": ["downloads", "*://www.thatsite.com/*"]
我使用的命令是:
chrome.downloads.download({"url":"https://www.thatsite.com/images/image1.jpg"});
这会产生以下错误
“downloads.download期间出错:无效的URL”
有什么办法解决这个问题吗?
发布于 2013-01-28 16:31:07
我试过使用下面的代码,它正在按预期工作。我希望你是,而不是在稳定频道。
将完整的代码放在一起,问题完全在于URL。
您可以引用以下代码作为引用
参考文献
manifest.json
已注册的浏览器操作和带有清单文件的权限。
{
"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/*"
]
}
popup.html
添加了<script>
文件以符合CSP。
<html>
<head>
<script src="popup.js"></script>
</head>
<body>
<button id="download">Download</button>
</body>
</html>
popup.js
只需将URL传递给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");
});
});
});
https://stackoverflow.com/questions/14560465
复制相似问题