Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on Download a PDF file in Playwright instead of opening it in a new tab when clicking on its link

Post

Download a PDF file in Playwright instead of opening it in a new tab when clicking on its link

+1
−0

My organisation uses Moodle as their online e-learning system on which teachers share resources, and oftentimes numerous documents that we need to view/download are posted there. The default way of attaching documents (which is what everyone ends up using) requires the recipient to ctrl-click on the link, move to the tab just opened and ctrl+S for every PDF shared, which isn't exactly a 'git clone-experience'.

To get over this I tried using Playwright, famous for being able to automatically perform practically any useful action a human would, but everything I've tried has always caused a download promise to hang after the PDF opened in a new tab.

History

1 comment thread

I appreciate the self-answer, but this question isn't easily answerable by any other users. In your q... (2 comments)
I appreciate the self-answer, but this question isn't easily answerable by any other users. In your q...
ggorlen‭ wrote 3 months ago · edited 3 months ago

I appreciate the self-answer, but this question isn't easily answerable by any other users. In your questions and answers, I don't see any URLs, so it's not even clear to me what page you're automating or how I could begin to reproduce the issue.

"everything I've tried has always caused a download promise to hang after the PDF opened in a new tab" -- can you share the non-working code?

Please provide enough context that someone besides you could provide an answer. Without that, I'm dubious whether this thread will provide value to the community beyond you. Thanks.

Elefy‭ wrote 2 months ago

Hi ggorlen‭, the main reason for this answer was simply to say 'use headless mode to force a download of the PDF', but you're right about the example not being very useful (I couldn't really share it unfortunately as it involved logging into an intranet).

If I find myself using this again for publicly-available content, I'd be more than happy to show how I did that, in a way easy to reproduce.