Skip to content

Commit 7b9ac37

Browse files
authored
chore: expose local_utils (microsoft#1383)
This is part 4/n of the 1.23 port. Relates microsoft#1308, microsoft#1374, microsoft#1376, microsoft#1382 Ports: - [x] microsoft/playwright@176ab7e (chore: make LocalUtils easily available on the client (#14717))
1 parent 0e3a502 commit 7b9ac37

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

playwright/_impl/_browser.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ async def new_context(
125125
self._contexts.append(context)
126126
context._browser = self
127127
context._options = params
128-
context._tracing._local_utils = self._local_utils
129128
return context
130129

131130
async def new_page(

playwright/_impl/_browser_type.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ async def launch(
9090
browser = cast(
9191
Browser, from_channel(await self._channel.send("launch", params))
9292
)
93-
browser._local_utils = self._playwright._utils
9493
return browser
9594

9695
async def launch_persistent_context(
@@ -150,7 +149,6 @@ async def launch_persistent_context(
150149
from_channel(await self._channel.send("launchPersistentContext", params)),
151150
)
152151
context._options = params
153-
context.tracing._local_utils = self._playwright._utils
154152
return context
155153

156154
async def connect_over_cdp(
@@ -163,7 +161,6 @@ async def connect_over_cdp(
163161
params = locals_to_params(locals())
164162
response = await self._channel.send_return_as_dict("connectOverCDP", params)
165163
browser = cast(Browser, from_channel(response["browser"]))
166-
browser._local_utils = self._playwright._utils
167164

168165
default_context = cast(
169166
Optional[BrowserContext],
@@ -194,6 +191,7 @@ async def connect(
194191
self._connection._object_factory,
195192
transport,
196193
self._connection._loop,
194+
local_utils=self._connection.local_utils,
197195
)
198196
connection.mark_as_remote()
199197
connection._is_sync = self._connection._is_sync
@@ -216,7 +214,6 @@ async def connect(
216214
assert pre_launched_browser
217215
browser = cast(Browser, from_channel(pre_launched_browser))
218216
browser._should_close_connection_on_close = True
219-
browser._local_utils = self._playwright._utils
220217

221218
def handle_transport_close() -> None:
222219
for context in browser.contexts:

playwright/_impl/_connection.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from playwright._impl._transport import Transport
2929

3030
if TYPE_CHECKING:
31+
from playwright._impl._local_utils import LocalUtils
3132
from playwright._impl._playwright import Playwright
3233

3334

@@ -109,7 +110,7 @@ def __init__(
109110
parent if isinstance(parent, ChannelOwner) else None
110111
)
111112
self._objects: Dict[str, "ChannelOwner"] = {}
112-
self._channel = Channel(self._connection, guid)
113+
self._channel: Channel = Channel(self._connection, guid)
113114
self._channel._object = self
114115
self._initializer = initializer
115116

@@ -173,6 +174,7 @@ def __init__(
173174
object_factory: Callable[[ChannelOwner, str, str, Dict], ChannelOwner],
174175
transport: Transport,
175176
loop: asyncio.AbstractEventLoop,
177+
local_utils: Optional["LocalUtils"] = None,
176178
) -> None:
177179
super().__init__()
178180
self._dispatcher_fiber = dispatcher_fiber
@@ -193,6 +195,12 @@ def __init__(
193195
self._api_zone: contextvars.ContextVar[Optional[Dict]] = contextvars.ContextVar(
194196
"ApiZone", default=None
195197
)
198+
self._local_utils: Optional["LocalUtils"] = local_utils
199+
200+
@property
201+
def local_utils(self) -> "LocalUtils":
202+
assert self._local_utils
203+
return self._local_utils
196204

197205
def mark_as_remote(self) -> None:
198206
self.is_remote = True

playwright/_impl/_fetch.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ async def new_context(
7878
APIRequestContext,
7979
from_channel(await self.playwright._channel.send("newRequest", params)),
8080
)
81-
context._tracing._local_utils = self.playwright._utils
8281
return context
8382

8483

playwright/_impl/_object_factory.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ def create_remote_object(
7171
if type == "JSHandle":
7272
return JSHandle(parent, type, guid, initializer)
7373
if type == "LocalUtils":
74-
return LocalUtils(parent, type, guid, initializer)
74+
local_utils = LocalUtils(parent, type, guid, initializer)
75+
if not local_utils._connection._local_utils:
76+
local_utils._connection._local_utils = local_utils
77+
return local_utils
7578
if type == "Page":
7679
return Page(parent, type, guid, initializer)
7780
if type == "Playwright":

playwright/_impl/_tracing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818
from playwright._impl._artifact import Artifact
1919
from playwright._impl._connection import ChannelOwner, from_nullable_channel
2020
from playwright._impl._helper import locals_to_params
21-
from playwright._impl._local_utils import LocalUtils
2221

2322

2423
class Tracing(ChannelOwner):
2524
def __init__(
2625
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
2726
) -> None:
2827
super().__init__(parent, type, guid, initializer)
29-
_local_utils: LocalUtils
3028

3129
async def start(
3230
self,
@@ -86,4 +84,6 @@ async def _do_stop_chunk(self, file_path: Union[pathlib.Path, str] = None) -> No
8684

8785
# Add local sources to the remote trace if necessary.
8886
if result.get("sourceEntries", []):
89-
await self._local_utils.zip(file_path, result["sourceEntries"])
87+
await self._connection.local_utils.zip(
88+
str(file_path), result["sourceEntries"]
89+
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy