8000 Add missing `_browser_type` instance variable · microsoft/playwright-python@b3e5199 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit b3e5199

Browse files
committed
Add missing _browser_type instance variable
1 parent 587355e commit b3e5199

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

playwright/_impl/_browser.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def __init__(
6565
self, parent: "BrowserType", type: str, guid: str, initializer: Dict
6666
) -> None:
6767
super().__init__(parent, type, guid, initializer)
68+
self._browser_type: Optional["BrowserType"] = None
6869
self._is_connected = True
6970
self._should_close_connection_on_close = False
7071
self._cr_tracing_path: Optional[str] = None
@@ -105,7 +106,10 @@ def _did_create_context(self, context: BrowserContext) -> None:
105106

106107
def _setup_browser_context(self, context: BrowserContext) -> None:
107108
context._tracing._traces_dir = self._traces_dir
108-
self._browser_type._playwright.selectors._contexts_for_selectors.add(context)
109+
if self._browser_type:
110+
self._browser_type._playwright.selectors._contexts_for_selectors.add(
111+
context
112+
)
109113

110114
def _on_close(self) -> None:
111115
self._is_connected = False
@@ -117,6 +121,10 @@ def contexts(self) -> List[BrowserContext]:
117121

118122
@property
119123
def browser_type(self) -> "BrowserType":
124+
if not self._browser_type:
125+
raise RuntimeError(
126+
"_browser_type is not set. Make sure _connect_to_browser_type() is called on initialization."
127+
)
120128
return self._browser_type
121129

122130
def is_connected(self) -> bool:
@@ -162,7 +170,8 @@ async def new_context(
162170
clientCertificates: List[ClientCertificate] = None,
163171
) -> BrowserContext:
164172
params = locals_to_params(locals())
165-
await self._browser_type._prepare_browser_context_params(params)
173+
if self._browser_type:
174+
await self._browser_type._prepare_browser_context_params(params)
166175

167176
channel = await self._channel.send("newContext", params)
168177
context = cast(BrowserContext, from_channel(channel))

playwright/_impl/_browser_context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ def _on_close(self) -> None:
571571
if self in self._browser._contexts:
572572
self._browser._contexts.remove(self)
573573
if (
574-
self
574+
self._browser._browser_type
575+
and self
575576
in self._browser._browser_type._playwright.selectors._contexts_for_selectors
576577
):
577578
self._browser._browser_type._playwright.selectors._contexts_for_selectors.remove(

0 commit comments

Comments
 (0)
0