go-rod / rod

A Chrome DevTools Protocol driver for web automation and scraping.
https://go-rod.github.io
MIT License
5.01k stars 328 forks source link

Added context to WaitDownload and MustWaitDownload #1021

Closed lpongetti closed 3 months ago

lpongetti commented 3 months ago

Pass a context to MustWaitDownload and MustWait to not block everything in case of file not downloaded

ysmood commented 3 months ago

With rod you can do:

page.Context(ctx).MustWaitDownload(...)

Please check the doc: https://go-rod.github.io/#/context-and-timeout

lpongetti commented 3 months ago

I already tryed this solution but it's not the same thing. I wanna a context only for the file download and not for the browser. If i wanna downalod file i can wait only 30 seconds for example. If the download fails i can do other things or try again.

ysmood commented 3 months ago

I think you have misunderstood what I mean, for example, the code below, those 2 lines don't share the same context:

// if first one fails
page.Timeout(30 * time.Second).MustWaitDownload(...)

// try again
page.Timeout(20 * time.Second).MustWaitDownload(...)

It's a clone of the page, page.Context never modifies the origin page.