Skip to content

Commit 90def29

Browse files
committed
fix sync variant
1 parent 90f2c9c commit 90def29

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

playwright/_impl/_browser_type.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ async def connect(
172172
slow_mo: float = None,
173173
headers: Dict[str, str] = None,
174174
) -> Browser:
175-
transport = WebSocketTransport(self._connection._loop, ws_endpoint, timeout, headers)
175+
transport = WebSocketTransport(
176+
self._connection._loop, ws_endpoint, timeout, headers
177+
)
176178

177179
connection = Connection(
178180
self._connection._dispatcher_fiber,
@@ -182,7 +184,7 @@ async def connect(
182184
connection._is_sync = self._connection._is_sync
183185
connection._loop = self._connection._loop
184186
connection._loop.create_task(connection.run())
185-
await connection.wait_until_started()
187+
await connection.initialize()
186188
playwright = await connection.wait_for_object_with_known_name("Playwright")
187189
self._connection._child_ws_connections.append(connection)
188190
pre_launched_browser = playwright._initializer.get("preLaunchedBrowser")

playwright/_impl/_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ def __init__(
169169
async def run_as_sync(self) -> None:
170170
self._is_sync = True
171171
await self.run()
172-
await self.wait_until_started()
172+
await self.initialize()
173173

174174
async def run(self) -> None:
175175
self._loop = asyncio.get_running_loop()
176176
self._root_object = RootChannelOwner(self)
177177
await self._transport.run()
178178

179-
async def wait_until_started(self) -> None:
179+
async def initialize(self) -> None:
180180
await self._transport.wait_until_started
181181

182182
def stop_sync(self) -> None:

playwright/_impl/_transport.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ def deserialize_message(self, data: bytes) -> Any:
8787

8888

8989
class PipeTransport(Transport):
90-
def __init__(self, loop: asyncio.AbstractEventLoop, driver_executable: Path) -> None:
90+
def __init__(
91+
self, loop: asyncio.AbstractEventLoop, driver_executable: Path
92+
) -> None:
9193
super().__init__(loop)
9294
self._stopped = False
9395
self._driver_executable = driver_executable
@@ -114,14 +116,8 @@ async def run(self) -> None:
114116
stderr=_get_stderr_fileno(),
115117
limit=32768,
116118
)
117-
except FileNotFoundError:
118-
self._wait_until_started_set_exception(
119-
Error(
120-
"playwright's driver is not found, You can read the contributing guide "
121-
"for some guidance on how to get everything setup for working on the code "
122-
"https://github.com/microsoft/playwright-python/blob/master/CONTRIBUTING.md"
123-
)
124-
)
119+
except Exception as exc:
120+
self._wait_until_started_set_exception(exc)
125121
return
126122

127123
self._wait_until_started_set_success()
@@ -160,16 +156,19 @@ def send(self, message: Dict) -> None:
160156

161157
class WebSocketTransport(AsyncIOEventEmitter, Transport):
162158
def __init__(
163-
self, loop: asyncio.AbstractEventLoop, ws_endpoint: str, timeout: float = None, headers: Dict[str, str] = None
159+
self,
160+
loop: asyncio.AbstractEventLoop,
161+
ws_endpoint: str,
162+
timeout: float = None,
163+
headers: Dict[str, str] = None,
164164
) -> None:
165-
super().__init__()
165+
super().__init__(loop)
166166
Transport.__init__(self, loop)
167167

168168
self._stopped = False
169169
self.ws_endpoint = ws_endpoint
170-
self.timeout = timeout
170+
self.timeout = timeout or 30000
171171
self.headers = headers
172-
self._loop: asyncio.AbstractEventLoop
173172

174173
def request_stop(self) -> None:
175174
self._stopped = True
@@ -189,7 +188,7 @@ async def run(self) -> None:
189188
options["close_timeout"] = self.timeout / 1000
190189
options["ping_timeout"] = self.timeout / 1000
191190

192-
if self.headers is not None:
191+
if self.headers:
193192
options["extra_headers"] = self.headers
194193
try:
195194
self._connection = await websockets.connect(self.ws_endpoint, **options)

playwright/async_api/_context_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ def __init__(self) -> None:
2828

2929
async def __aenter__(self) -> AsyncPlaywright:
3030
self._connection = Connection(
31-
None, create_remote_object, PipeTransport(asyncio.get_event_loop(), compute_driver_executable())
31+
None,
32+
create_remote_object,
33+
PipeTransport(asyncio.get_event_loop(), compute_driver_executable()),
3234
)
3335
loop = asyncio.get_running_loop()
3436
self._connection._loop = loop
3537
loop.create_task(self._connection.run())
36-
await self._connection.wait_until_started()
38+
await self._connection.initialize()
3739
playwright = AsyncPlaywright(
3840
await self._connection.wait_for_object_with_known_name("Playwright")
3941
)

0 commit comments

Comments
 (0)