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?"
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
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
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 [email protected].