For every attachment downloaded by the page,
"download" event is emitted. If you create a browser context with the
acceptDownloads: true, all these attachments are going to be downloaded into a temporary folder. You can obtain the download url, file system path and payload stream using the
Download object from the event.
If you have no idea what initiates the download, you can still handle the event:
Note that handling the event forks the control flow and makes script harder to follow. Your scenario might end while you are downloading a file since your main control flow is not awaiting for this operation to resolve.
You can monitor all the requests and responses:
Or wait for a network response after the button click:
- page.waitForRequest(urlOrPredicate[, options])
- page.waitForResponse(urlOrPredicate[, options])
You can mock API endpoints via handling the network quests in your Playwright script.
- browserContext.route(url, handler)
- browserContext.unroute(url[, handler])
- page.route(url, handler)
- page.unroute(url[, handler])
You can continue requests with modifications. Example above removes an HTTP header from the outgoing requests.