Could I chain several downloads with chrome.downloads.download method?

63 views
Skip to first unread message

Victor Leo

unread,
Feb 10, 2022, 9:25:28 AM2/10/22
to Chromium Extensions
Hi, given the following backgrounds in MV3+:
  • In user's browser, "Ask where to save each file before downloading" is switched on.
  • There are 3 files which are supposed to be downloaded continueously: a.txt, b.json, c.md.
  • If possible, try not to use zip; it can be the final fallback though.
I'm stuck at this point and couldn't gurantee 3 file-choosers would always be shown; What I'm thinking about is: would it be possible to invoke 3 file-choosers and let the user confirm them one by one? I've done the following 2 attempts:

In an async function, given the input like:
const fileConfs = [
{ filename: "a.txt", url: "data:text/plain;base64,dGVzdCB0ZXh0" },
{ filename: "b.json", url: "data:application/json;base64,eyJ0ZXN0IjoidmFsdWUifQ==" },
{ filename: "c.md", url: "data:text/markdown;base64,I3Rlc3Q=" }
];
Attempt 1, not work, only 1st file a.txt is prompted with file-chooser:
for (let fileConf of fileConfs) {
const downloadId = await chrome.downloads.download({
saveAs: false,
...fileConf
});
console.log(downloadId);
}
Attempt 2, not work either:
const downloadIds = await Promise.all(
fileConfs.map(fileConf =>
chrome.downloads.download({
saveAs: false,
...fileConf
})
)
);
downloadIds.forEach(id => console.log(id));

Many times, I only got 1 file-chooser for the first file, but the other 2 vanished. Seems the user interaction will not block the execution of micro tasks? Not quite sure.
Thanks a lot for your time and ideas.

Best Regards
Magartroid
10th Feb 2022
Reply all
Reply to author
Forward
0 new messages