-
Notifications
You must be signed in to change notification settings - Fork 828
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
[Question]: how can I access async response's body in the predicate? #1545
Labels
Comments
Based on the impl, it looks like the predicate cannot be an async function today. As a workaround, you can create and await a Future instead of using the built in # set up your listener and future
matched_response_fut = asyncio.Future()
async def is_matching(response: Response):
body = await response.text()
if body == "some text you're looking for":
matched_response_fut.set_result(response)
page.on("response", is_matching)
# take your action(s) that will actually trigger the response
# e.g. navigation, clicking, etc.
# …
# await and use your matched response
response = await matched_response_fut |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your question
I can simply do this with sync api but I have no idea how to with async api;
I've tried code like:
but only got error said coroutine returned by response.text() needs await;
if I change check to async function I got another error said check needs await.
what is the correct way accessing response's body with async api?
The text was updated successfully, but these errors were encountered: