question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to manually download file (donwload dialog) ?

See original GitHub issue

scrn

const { chromium } = require("playwright");
const path = require("path");


(async () => {

    const browser = await chromium.launch({
        headless: false,
        // downloadsPath: path.join(__dirname, 'downloads')
    });

    const context = await browser.newContext({
        acceptDownloads: true,
    });

    const page = await context.newPage();

    await page.goto('https://file-examples.com/index.php/sample-documents-download/sample-xls-download/');

    // how to manually download file by User click ????




    // // Automatic Download
    // const handles = await page.$$("#table-files td.text-right.file-link");

    // for (let num of handles) {

    //     const [download] = await Promise.all([
    //         page.waitForEvent('download'),
    //         num.click("a.btn")
    //     ]);

    //     await download.saveAs(path.join(__dirname, 'downloads', download.suggestedFilename()));
    // }

    // await browser.close();
})();

How to manually download file (donwload dialog) ?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
tim-munncommented, Mar 5, 2021

I am experiencing the identical issue. My use case is I need to download a pdf file to be able to query the contents. In a similar way as ruslanx3m needed to use an xls file Some download options (such as save a pdf), when you open a pdf in a browser (Chrome), launch a native file dialog that needs accepting before the download can progress, rather than using the in browser download option, because the download hasn’t technically started at that point and an event hasn’t been created a ‘download’ object can’t be created, but one is needed to set the path for the download.

In my case I was able to awkwardly work round, by determining the URL of the file I needed to download and separately doing a fetch to that url and saving the Buffer from the response to a file. However it would have been much easier to be able to use a the ‘Download’ functionality.

1reaction
tim-munncommented, Apr 19, 2021

@Ciantic I used axios (https://www.npmjs.com/package/axios) to perform the request as it writes out to a stream I could buffer into a file

const DownloadFileFromURL = async (url,path) => { const writer = Fs.createWriteStream(path) const response = await axios({ url, method: ‘GET’, responseType: ‘stream’ })

response.data.pipe(writer)

return new Promise((resolve, reject) => {
  writer.on('finish', resolve)
  writer.on('error', reject)
})

}

Read more comments on GitHub >

github_iconTop Results From Across the Web

How does one get the file download dialog box back after you ...
Tools (IE Menu Bar) >View downloads, remove (X on the right) any downloads of the affected file type. Next time you encounter that...
Read more >
Download File Dialog - selenium - Stack Overflow
I am using a variety of browsers (ruling out the automatic downloads as some browsers do not support this). I am using a...
Read more >
Download a file from a search dialog and naming it from one ...
Is there a way to Automatically name a document while downloading it from one of the fields, like the Last_Name field? My customer...
Read more >
how do i add "save as" to download's dialog box
i would like to be able to specify the name of the file that i am downloading right as i am downloading it,...
Read more >
Download a file - Computer - Google Chrome Help
See a list of files you've downloaded · On your computer, open Chrome. · At the top right, click More More and then...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found