Rayrun
← Back to Discord Forum

How to force-download PDF(it just opens when clicked)

I have a PDF button, but it opens PDF in a new tab. I need to download it and verify. How can I force-download PDF file using Playwright? Looks like there is no Chrome Options like in selenium. Please help

This thread is trying to answer question "How can I force-download a PDF file using Playwright when it opens in a new tab or in a pdf viewer mode inside chromium?"

4 replies
timdeschryver
timdeschryver

Is the button by any chance an anchor tag? If so, I usually grab the href and use request to download the PDF, for an example see https://timdeschryver.dev/blog/include-attachments-to-your-playwright-report#add-an-external-file-to-the-report

@timdeschryver: thank you! unfortunately there is no href. trying to find how to change chromium settings to download upon click.

thank you! unfortunately there is no href. trying to find how to change chromium settings to download upon click.

What's the URL of the PDF that opens in a new tab? Can you create a route in the initial page or better, in the context, to grab that request and save it on disk or force some headers to download instead? Another way could be, to let the PDF open in the other tab, then get hold of that tab via page.context().pages(), grab the URL, add a route for it, and reload the page or make it goto that URL so you finally catch it n

I have the same problem, but the PDF opens in a pdf viewer mode inside chromium and I don't know how to access anything in it. Could you explain more on how to "force" download it ? @p01___ please?

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.