I'm coding an extension that downloads items with specific names. Currently, I have two types of items to download:
chrome.downloads.download (type A)chrome.downloads.onDeterminingFilename.addListener (type B)The problem is chrome.downloads.onDeterminingFilename.addListener interfere with all downloads regardless of the parameters set. I want it only to change the filename when the type B item is downloaded.
Basic rundown of my code
chrome.downloads.download({ //type A items
url: item.imageLink, //set linkURL
filename: setName //set name
});
//item will be downloaded with *setName*
chrome.downloads.onDeterminingFilename.addListener((downloadItem, suggest) => { //type B items
//item will be intercepted, its name being its original filename
if (item != null && item.type == "B" && downloadItem.url == item.imageLink) { //check linkURL
suggest({filename: setName, conflictAction: "uniquify"}); //item's filename will be changed to *setName*
}
});
Unless I remove the chrome.downloads.onDeterminingFilename completely, the file downloaded will be its original filename regardless of what type it is.
I thought of 3 possible solutions:
chrome.downloads.onDeterminingFilename, make it change the name of every item downloaded.chrome.downloads.onDeterminingFilename when it's not type B items, and add it in when it is.chrome.downloads.onDeterminingFilenameAny other suggestions or am I doing this all wrong?