Skip to content

chore: do not continue with no_reply messages#1905

Merged
mxschmitt merged 3 commits intomainfrom
do-not-process-no-reply-messages
May 9, 2023
Merged

chore: do not continue with no_reply messages#1905
mxschmitt merged 3 commits intomainfrom
do-not-process-no-reply-messages

Conversation

@mxschmitt
Copy link
Copy Markdown
Contributor

@mxschmitt mxschmitt commented May 9, 2023

Fixes #1903

Tricky to test that a warning does not get displayed. Before the following:

from playwright.sync_api import sync_playwright

with sync_playwright() as playwright:
    browser = playwright.chromium.launch()
    page = browser.new_page()
    page.goto('http://example.com/')
    with page.expect_popup() as popup_info:
        page.evaluate('window.open("http://example.com/")')
    popup = popup_info.value
    with popup.expect_event('close') as popup_info:
        popup.evaluate('window.close()')
    browser.close()

resulted in:

(env) ➜  playwright-python git:(main) ✗ python test.py
Future exception was never retrieved
future: <Future finished exception=Error('Target page, context or browser has been closed')>
playwright._impl._api_types.Error: Target page, context or browser has been closed

because the "after" "waitForEventInfo" call was returning an exception and in Python you need to await all the exceptions.

Ways thought about fixing it:
a) never add it to the self._callbacks
b) add a special no_reply flag to the callbacks - did this for now.

@mxschmitt mxschmitt requested a review from yury-s May 9, 2023 08:13
callback = self._callbacks.pop(id)
if callback.future.cancelled():
return
if callback.no_reply:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was bad about calling set_result on the callback future?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the PR description, that we received an error (waitForEventInfo after), were setting it on the protocol callback but never awaiting it, hence it was showing the warning in the console.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd do a), but b) also works. Please add a comment about it when you are assining no_reply to True

@mxschmitt mxschmitt merged commit 7405d65 into main May 9, 2023
@mxschmitt mxschmitt deleted the do-not-process-no-reply-messages branch May 9, 2023 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Question]: "The reaction to the self-closing of a window using JavaScript."

2 participants