How to wait for all downloads to complete with Puppeteer?












1















node.js 8.10
puppeteer 1.10.0



I have a small web scraping application that downloads multiple files from a Java Server Faces based web application. The downloads are triggered by clicking the link for each file. Unfortunately there is no direct url for the download and I have to do it this way.



It works fine if I keep the browser instance alive in between runs. For stability reasons I want to close the instance in between runs though.
When I call browser.close() my downloads are stopped because the chrome instance is closed before the downloads have finished.



Does puppeteer provide a way to check if downloads are still active, and wait for them to complete? I've tried page.waitForNavigation({ waitUntil: "networkidle0" }) and "networkidle2", but those seem to wait indefinitely.



Thanks!










share|improve this question























  • I remember doing this once with nightmarejs, I don't know if that's helpful or not. The core team decided it wasn't worth including so someone made an extra called nightmare-download-manager

    – pguardiario
    Nov 26 '18 at 8:06











  • Thanks @pguardiario, but that does not help me much, unfortunately. I don't want to switch to nightmare.js.

    – Jiri
    Nov 26 '18 at 11:27


















1















node.js 8.10
puppeteer 1.10.0



I have a small web scraping application that downloads multiple files from a Java Server Faces based web application. The downloads are triggered by clicking the link for each file. Unfortunately there is no direct url for the download and I have to do it this way.



It works fine if I keep the browser instance alive in between runs. For stability reasons I want to close the instance in between runs though.
When I call browser.close() my downloads are stopped because the chrome instance is closed before the downloads have finished.



Does puppeteer provide a way to check if downloads are still active, and wait for them to complete? I've tried page.waitForNavigation({ waitUntil: "networkidle0" }) and "networkidle2", but those seem to wait indefinitely.



Thanks!










share|improve this question























  • I remember doing this once with nightmarejs, I don't know if that's helpful or not. The core team decided it wasn't worth including so someone made an extra called nightmare-download-manager

    – pguardiario
    Nov 26 '18 at 8:06











  • Thanks @pguardiario, but that does not help me much, unfortunately. I don't want to switch to nightmare.js.

    – Jiri
    Nov 26 '18 at 11:27
















1












1








1








node.js 8.10
puppeteer 1.10.0



I have a small web scraping application that downloads multiple files from a Java Server Faces based web application. The downloads are triggered by clicking the link for each file. Unfortunately there is no direct url for the download and I have to do it this way.



It works fine if I keep the browser instance alive in between runs. For stability reasons I want to close the instance in between runs though.
When I call browser.close() my downloads are stopped because the chrome instance is closed before the downloads have finished.



Does puppeteer provide a way to check if downloads are still active, and wait for them to complete? I've tried page.waitForNavigation({ waitUntil: "networkidle0" }) and "networkidle2", but those seem to wait indefinitely.



Thanks!










share|improve this question














node.js 8.10
puppeteer 1.10.0



I have a small web scraping application that downloads multiple files from a Java Server Faces based web application. The downloads are triggered by clicking the link for each file. Unfortunately there is no direct url for the download and I have to do it this way.



It works fine if I keep the browser instance alive in between runs. For stability reasons I want to close the instance in between runs though.
When I call browser.close() my downloads are stopped because the chrome instance is closed before the downloads have finished.



Does puppeteer provide a way to check if downloads are still active, and wait for them to complete? I've tried page.waitForNavigation({ waitUntil: "networkidle0" }) and "networkidle2", but those seem to wait indefinitely.



Thanks!







node.js puppeteer






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 19:46









JiriJiri

153




153













  • I remember doing this once with nightmarejs, I don't know if that's helpful or not. The core team decided it wasn't worth including so someone made an extra called nightmare-download-manager

    – pguardiario
    Nov 26 '18 at 8:06











  • Thanks @pguardiario, but that does not help me much, unfortunately. I don't want to switch to nightmare.js.

    – Jiri
    Nov 26 '18 at 11:27





















  • I remember doing this once with nightmarejs, I don't know if that's helpful or not. The core team decided it wasn't worth including so someone made an extra called nightmare-download-manager

    – pguardiario
    Nov 26 '18 at 8:06











  • Thanks @pguardiario, but that does not help me much, unfortunately. I don't want to switch to nightmare.js.

    – Jiri
    Nov 26 '18 at 11:27



















I remember doing this once with nightmarejs, I don't know if that's helpful or not. The core team decided it wasn't worth including so someone made an extra called nightmare-download-manager

– pguardiario
Nov 26 '18 at 8:06





I remember doing this once with nightmarejs, I don't know if that's helpful or not. The core team decided it wasn't worth including so someone made an extra called nightmare-download-manager

– pguardiario
Nov 26 '18 at 8:06













Thanks @pguardiario, but that does not help me much, unfortunately. I don't want to switch to nightmare.js.

– Jiri
Nov 26 '18 at 11:27







Thanks @pguardiario, but that does not help me much, unfortunately. I don't want to switch to nightmare.js.

– Jiri
Nov 26 '18 at 11:27














1 Answer
1






active

oldest

votes


















1














Tried doing an await page.waitFor(50000); with a time as long as the download should take.



Or look at watching for file changes on complete file transfer






share|improve this answer
























  • thanks for that simple solution. await page.waitFor(timeout) works, but I'll try and build a more graceful solution inspired by your second suggestion.

    – Jiri
    Nov 26 '18 at 12:24













  • I've used your pointer to to file events and this answer on check if file exists, if not wait until it exists to implement a more graceful solution. I couldn't use the answer you pointed to directly, because I'm dealing with local files, not remote servers. But good inspiration nonetheless! If the download has finished, the file already exists. If not, it waits for the the temporary file used during download to be renamed to the target file name.

    – Jiri
    Nov 27 '18 at 8:39













  • Glad you worked out a functional solution.

    – Hellonearthis
    Nov 27 '18 at 11:18











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471235%2fhow-to-wait-for-all-downloads-to-complete-with-puppeteer%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Tried doing an await page.waitFor(50000); with a time as long as the download should take.



Or look at watching for file changes on complete file transfer






share|improve this answer
























  • thanks for that simple solution. await page.waitFor(timeout) works, but I'll try and build a more graceful solution inspired by your second suggestion.

    – Jiri
    Nov 26 '18 at 12:24













  • I've used your pointer to to file events and this answer on check if file exists, if not wait until it exists to implement a more graceful solution. I couldn't use the answer you pointed to directly, because I'm dealing with local files, not remote servers. But good inspiration nonetheless! If the download has finished, the file already exists. If not, it waits for the the temporary file used during download to be renamed to the target file name.

    – Jiri
    Nov 27 '18 at 8:39













  • Glad you worked out a functional solution.

    – Hellonearthis
    Nov 27 '18 at 11:18
















1














Tried doing an await page.waitFor(50000); with a time as long as the download should take.



Or look at watching for file changes on complete file transfer






share|improve this answer
























  • thanks for that simple solution. await page.waitFor(timeout) works, but I'll try and build a more graceful solution inspired by your second suggestion.

    – Jiri
    Nov 26 '18 at 12:24













  • I've used your pointer to to file events and this answer on check if file exists, if not wait until it exists to implement a more graceful solution. I couldn't use the answer you pointed to directly, because I'm dealing with local files, not remote servers. But good inspiration nonetheless! If the download has finished, the file already exists. If not, it waits for the the temporary file used during download to be renamed to the target file name.

    – Jiri
    Nov 27 '18 at 8:39













  • Glad you worked out a functional solution.

    – Hellonearthis
    Nov 27 '18 at 11:18














1












1








1







Tried doing an await page.waitFor(50000); with a time as long as the download should take.



Or look at watching for file changes on complete file transfer






share|improve this answer













Tried doing an await page.waitFor(50000); with a time as long as the download should take.



Or look at watching for file changes on complete file transfer







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 5:43









HellonearthisHellonearthis

6851718




6851718













  • thanks for that simple solution. await page.waitFor(timeout) works, but I'll try and build a more graceful solution inspired by your second suggestion.

    – Jiri
    Nov 26 '18 at 12:24













  • I've used your pointer to to file events and this answer on check if file exists, if not wait until it exists to implement a more graceful solution. I couldn't use the answer you pointed to directly, because I'm dealing with local files, not remote servers. But good inspiration nonetheless! If the download has finished, the file already exists. If not, it waits for the the temporary file used during download to be renamed to the target file name.

    – Jiri
    Nov 27 '18 at 8:39













  • Glad you worked out a functional solution.

    – Hellonearthis
    Nov 27 '18 at 11:18



















  • thanks for that simple solution. await page.waitFor(timeout) works, but I'll try and build a more graceful solution inspired by your second suggestion.

    – Jiri
    Nov 26 '18 at 12:24













  • I've used your pointer to to file events and this answer on check if file exists, if not wait until it exists to implement a more graceful solution. I couldn't use the answer you pointed to directly, because I'm dealing with local files, not remote servers. But good inspiration nonetheless! If the download has finished, the file already exists. If not, it waits for the the temporary file used during download to be renamed to the target file name.

    – Jiri
    Nov 27 '18 at 8:39













  • Glad you worked out a functional solution.

    – Hellonearthis
    Nov 27 '18 at 11:18

















thanks for that simple solution. await page.waitFor(timeout) works, but I'll try and build a more graceful solution inspired by your second suggestion.

– Jiri
Nov 26 '18 at 12:24







thanks for that simple solution. await page.waitFor(timeout) works, but I'll try and build a more graceful solution inspired by your second suggestion.

– Jiri
Nov 26 '18 at 12:24















I've used your pointer to to file events and this answer on check if file exists, if not wait until it exists to implement a more graceful solution. I couldn't use the answer you pointed to directly, because I'm dealing with local files, not remote servers. But good inspiration nonetheless! If the download has finished, the file already exists. If not, it waits for the the temporary file used during download to be renamed to the target file name.

– Jiri
Nov 27 '18 at 8:39







I've used your pointer to to file events and this answer on check if file exists, if not wait until it exists to implement a more graceful solution. I couldn't use the answer you pointed to directly, because I'm dealing with local files, not remote servers. But good inspiration nonetheless! If the download has finished, the file already exists. If not, it waits for the the temporary file used during download to be renamed to the target file name.

– Jiri
Nov 27 '18 at 8:39















Glad you worked out a functional solution.

– Hellonearthis
Nov 27 '18 at 11:18





Glad you worked out a functional solution.

– Hellonearthis
Nov 27 '18 at 11:18


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471235%2fhow-to-wait-for-all-downloads-to-complete-with-puppeteer%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks