In a request handler, can I open a new browser tab & run code concurrently?
I'm currently using playwright and my request is on the page
/results
. My defaultHandler
is running and I'd like to:
1. open a new tab and navigate: page.goto(/docs)
2. Concurrently, perform some browser navigation with playwright in both tabs /results
& /docs
3. Then, perform an action on the first tab (/results
) (waiting for it to finish)
4. Then, perform an action on the second tab (/docs
)
Note: I'm indifferent if this opens in a new tab or an entire new browser with the same session (sharing session is required though).
However, I do need to be able to finish task 2 in both tabs before I can run 3 & 4 synchronously in this order.
Would that work with Promise.all()
?4 Replies
fascinating-indigo•2y ago
You can open as many tabs as needed in the
requestHandler
but I'm interested in learning what exactly it is you're trying to do, because if you do everything in a single handler, you'll be responsible for managing state and knowing where to restart from when something goes wrong, whereas if you do this with the request queue, it will manage state for you. Can you elaborate a bit more please? Thanks!fair-roseOP•2y ago
I decided it was best to simply record the behavior i'd like to automate:
https://share.cleanshot.com/fs34GrYv
CleanShot 2023-07-22 at 18.49.10
Video uploaded to CleanShot Cloud
fair-roseOP•2y ago
there are basically two processes which can't really run in parallel as the cookies store the web view's state.
The main caveat for this website is how the server manages the cookie (which determines the view's state).
The cookies are updates as follows:
- ==> on
/search
: type in some input (search query) and hit "submit". Now:
1. The server persists the search query in the serverOnly cookie
2. The client initiates a client-side navigation to /results
- ==> on /results
: I want to perform two file downloads (see the video):
1. [downloadDoc]
- I click on a client-side navigation (no url change)
- I click on "initiate download" to submit a form
- the form submit triggers a cookie update (server) & a url navigation to /download
- on /download
I can click "download" and get the file that's defined in the cookie
2. [downloadOther]
- this is the same process as above only that i need to submit some additional infos in the form
The caveat here is that by clicking "initiate download", the server updates my cookie which means i cannot run it in parallel with the same cookie.
I could run this in two separate instances though -- but I would have to track which request handler to apply: the downloadDoc
OR the downloadOther
.
does that make sense? 😅@p6l.richard just advanced to level 3! Thanks for your contributions! 🎉