Skip to content

Commit d693da4

Browse files
committed
Placeholder commit for microsoft#1383
1 parent 4b2d991 commit d693da4

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
@@ -131,7 +131,6 @@ async def new_context(
131131
self._contexts.append(context)
132132
context._browser = self
133133
context._options = params
134-
context._tracing._local_utils = self._local_utils
135134
return context
136135

137136
async def new_page(

playwright/_impl/_browser_type.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ async def launch(
9292
browser = cast(
9393
Browser, from_channel(await self._channel.send("launch", params))
9494
)
95-
browser._local_utils = self._playwright._utils
9695
return browser
9796

9897
async def launch_persistent_context(
@@ -155,7 +154,6 @@ async def launch_persistent_context(
155154
from_channel(await self._channel.send("launchPersistentContext", params)),
156155
)
157156
context._options = params
158-
context.tracing._local_utils = self._playwright._utils
159157
return context
160158

161159
async def connect_over_cdp(
@@ -168,7 +166,6 @@ async def connect_over_cdp(
168166
params = locals_to_params(locals())
169167
response = await self._channel.send_return_as_dict("connectOverCDP", params)
170168
browser = cast(Browser, from_channel(response["browser"]))
171-
browser._local_utils = self._playwright._utils
172169

173170
default_context = cast(
174171
Optional[BrowserContext],
@@ -199,6 +196,7 @@ async def connect(
199196
self._connection._object_factory,
200197
transport,
201198
self._connection._loop,
199+
local_utils=self._connection.local_utils,
202200
)
203201
connection.mark_as_remote()
204202
connection._is_sync = self._connection._is_sync
@@ -221,7 +219,6 @@ async def connect(
221219
assert pre_launched_browser
222220
browser = cast(Browser, from_channel(pre_launched_browser))
223221
browser._should_close_connection_on_close = True
224-
browser._local_utils = self._playwright._utils
225222

226223
def handle_transport_close() -> None:
227224
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)