Skip to content

chore: follow-ups for #1897 connection changes #1906

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

Merged
merged 1 commit into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions playwright/_impl/_browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async def connect(

timeout_future = throw_on_timeout(timeout, Error("Connection timed out"))
done, pending = await asyncio.wait(
{playwright_future, timeout_future},
{transport.on_error_future, playwright_future, timeout_future},
return_when=asyncio.FIRST_COMPLETED,
)
if not playwright_future.done():
Expand All @@ -235,13 +235,13 @@ async def connect(
self._did_launch_browser(browser)
browser._should_close_connection_on_close = True

def handle_transport_close(transport_exception: str) -> None:
def handle_transport_close() -> None:
for context in browser.contexts:
for page in context.pages:
page._on_close()
context._on_close()
browser._on_close()
connection.cleanup(transport_exception or BROWSER_CLOSED_ERROR)
connection.cleanup(BROWSER_CLOSED_ERROR)

transport.once("close", handle_transport_close)

Expand Down
2 changes: 0 additions & 2 deletions playwright/_impl/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ def cleanup(self, error_message: str = None) -> None:
ws_connection._transport.dispose()
for callback in self._callbacks.values():
callback.future.set_exception(Error(error_message))
# Prevent 'Task exception was never retrieved'
callback.future.exception()
self._callbacks.clear()
self.emit("close")

Expand Down
18 changes: 8 additions & 10 deletions playwright/_impl/_json_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# limitations under the License.

import asyncio
from typing import Dict, Optional, cast
from typing import Dict, cast

from pyee.asyncio import AsyncIOEventEmitter

from playwright._impl._connection import Channel
from playwright._impl._helper import ParsedMessagePayload
from playwright._impl._helper import Error, ParsedMessagePayload
from playwright._impl._transport import Transport


Expand Down Expand Up @@ -48,17 +48,13 @@ async def wait_until_stopped(self) -> None:
async def connect(self) -> None:
self._stopped_future: asyncio.Future = asyncio.Future()

close_error: Optional[str] = None

def handle_message(message: Dict) -> None:
try:
self.on_message(cast(ParsedMessagePayload, message))
except Exception as e:
nonlocal close_error
close_error = str(e)
if self._stop_requested:
return
self.on_message(cast(ParsedMessagePayload, message))

def handle_closed() -> None:
self.emit("close", close_error)
self.emit("close")
self._stopped_future.set_result(None)

self._pipe_channel.on(
Expand All @@ -74,4 +70,6 @@ async def run(self) -> None:
await self._stopped_future

def send(self, message: Dict) -> None:
if self._stop_requested:
raise Error("Playwright connection closed")
self._pipe_channel.send_no_reply("send", {"message": message})