Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs]: Is there a way to cancel response.finished() promise? #31474

Open
himat opened this issue Jun 28, 2024 · 2 comments
Open

[Docs]: Is there a way to cancel response.finished() promise? #31474

himat opened this issue Jun 28, 2024 · 2 comments
Labels

Comments

@himat
Copy link

himat commented Jun 28, 2024

Page(s)

https://playwright.dev/docs/api/class-response#response-finished

Description

I noticed that when I do await response.finished() // wait for response to finish (inside the callback for page.on('response", onResponse)) that if the browser is closed, then this line throws an error "Target page, context or browser has been closed".
It throws even after the callback is unregistered with page.off("response", onResponse), but that makes sense since any prior response is still in flight.

So is there a way though to cancel any inflight pending response.finished() promises so that they don't throw when the page is closed?

  page.on("response", onResponse)

  disposableStack.defer(() => {
    page.off("response", onResponse)
    page.off("close", onBrowserViewDestroyed)
  })

@himat
Copy link
Author

himat commented Jun 28, 2024

I actually mainly want to cancel them because I may open multiple pages over time, and I don't want a request from an old page to be waiting forever if that response never finished.
So if I know that I am "done" with a page even though I am keeping the page tab open, it would be nice if I can manually cancel any still in flight pending response.finished() responses.

@pavelfeldman
Copy link
Member

There isn't much we can offer at this point. You can catch that finished() call or you can add it to a list of promises that you await / mute in the end of your test manually. We are thinking about joining the event handlers in the end of the test though, so I'll leave this open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants