So after some research i see content scripts dont directly support downloads, but you can pass message to your background page which supports download. The reason i included background page was to be able to see the console ;) you can try to directly goto background.js
manifest.json
{
"name": "Download static images",
"description": "Downloads images defined with tag from watched webpage(s) by injecting a script",
"version": "1.0",
"browser_action": {
"default_icon": "debuggerPause.png",
"default_title": "get page html"
},
"background": {
"page": "background.html"
},
"content_scripts": [
{
"matches": ["http://stackoverflow.com/*"],
"js": ["main.js"]
}
],
"permissions": [
"tabs",
"background","downloads"
],
"manifest_version": 2
}
main.js
function getHtml() {
var pagehtml = document.documentElement;
var imgs=pagehtml.getElementsByTagName( 'img' );
var pass_array=[];
for (i in imgs){
pass_array.push(imgs[i]["currentSrc"]);
}
console.log(pass_array);
var param = {collection : pass_array};
chrome.runtime.sendMessage(param);
};
getHtml();
background.js
chrome.runtime.onMessage.addListener(
function(arg, sender, sendResponse) {
var args=arg.collection;
for (i in args){
var img_url=args[i];
try{
saveas=img_url.replace(/[^a-zA-Z0-9]/g,'-');
}
catch (problem){
}
chrome.downloads.download({
url: img_url,
filename: saveas,
saveAs: false
});
}
});
function sendResponse(){
}
backgroundpage.html