Skip to content

Commit 85f3177

Browse files
authored
feat(roll): roll Playwright to 1.13.0-next-1625812834000 (#799)
1 parent 42e1283 commit 85f3177

File tree

17 files changed

+349
-97
lines changed

17 files changed

+349
-97
lines changed

playwright/_impl/_artifact.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ async def failure(self) -> Optional[str]:
4646

4747
async def delete(self) -> None:
4848
await self._channel.send("delete")
49+
50+
async def cancel(self) -> None:
51+
await self._channel.send("cancel")

playwright/_impl/_browser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ async def new_context(
105105
recordVideoDir: Union[Path, str] = None,
106106
recordVideoSize: ViewportSize = None,
107107
storageState: Union[StorageState, str, Path] = None,
108+
baseURL: str = None,
108109
) -> BrowserContext:
109110
params = locals_to_params(locals())
110111
await normalize_context_params(self._connection._is_sync, params)
@@ -145,6 +146,7 @@ async def new_page(
145146
recordVideoDir: Union[Path, str] = None,
146147
recordVideoSize: ViewportSize = None,
147148
storageState: Union[StorageState, str, Path] = None,
149+
baseURL: str = None,
148150
) -> Page:
149151
params = locals_to_params(locals())
150152
context = await self.new_context(**params)

playwright/_impl/_browser_context.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ async def expose_function(self, name: str, callback: Callable) -> None:
240240
await self.expose_binding(name, lambda source, *args: callback(*args))
241241

242242
async def route(self, url: URLMatch, handler: RouteHandler) -> None:
243-
self._routes.append(RouteHandlerEntry(URLMatcher(url), handler))
243+
self._routes.append(
244+
RouteHandlerEntry(URLMatcher(self._options.get("baseURL"), url), handler)
245+
)
244246
if len(self._routes) == 1:
245247
await self._channel.send(
246248
"setNetworkInterceptionEnabled", dict(enabled=True)

playwright/_impl/_browser_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ async def launch_persistent_context(
132132
recordHarOmitContent: bool = None,
133133
recordVideoDir: Union[Path, str] = None,
134134
recordVideoSize: ViewportSize = None,
135+
baseURL: str = None,
135136
) -> BrowserContext:
136137
userDataDir = str(Path(userDataDir))
137138
params = locals_to_params(locals())

playwright/_impl/_download.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ async def path(self) -> Optional[pathlib.Path]:
5959

6060
async def save_as(self, path: Union[str, Path]) -> None:
6161
await self._artifact.save_as(path)
62+
63+
async def cancel(self) -> None:
64+
return await self._artifact.cancel()

playwright/_impl/_frame.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ def expect_navigation(
153153
timeout = self._page._timeout_settings.navigation_timeout()
154154
deadline = monotonic_time() + timeout
155155
wait_helper = self._setup_navigation_wait_helper("expect_navigation", timeout)
156-
matcher = URLMatcher(url) if url else None
156+
matcher = (
157+
URLMatcher(self._page._browser_context._options.get("baseURL"), url)
158+
if url
159+
else None
160+
)
157161

158162
def predicate(event: Any) -> bool:
159163
# Any failed navigation results in a rejection.
@@ -188,7 +192,7 @@ async def wait_for_url(
188192
wait_until: DocumentLoadState = None,
189193
timeout: float = None,
190194
) -> None:
191-
matcher = URLMatcher(url)
195+
matcher = URLMatcher(self._page._browser_context._options.get("baseURL"), url)
192196
if matcher.matches(self.url):
193197
await self.wait_for_load_state(state=wait_until, timeout=timeout)
194198
return
@@ -274,10 +278,10 @@ async def is_editable(self, selector: str, timeout: float = None) -> bool:
274278
async def is_enabled(self, selector: str, timeout: float = None) -> bool:
275279
return await self._channel.send("isEnabled", locals_to_params(locals()))
276280

277-
async def is_hidden(self, selector: str, timeout: float = None) -> bool:
281+
async def is_hidden(self, selector: str) -> bool:
278282
return await self._channel.send("isHidden", locals_to_params(locals()))
279283

280-
async def is_visible(self, selector: str, timeout: float = None) -> bool:
284+
async def is_visible(self, selector: str) -> bool:
281285
return await self._channel.send("isVisible", locals_to_params(locals()))
282286

283287
async def dispatch_event(

playwright/_impl/_helper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
Union,
3333
cast,
3434
)
35+
from urllib.parse import urljoin
3536

3637
from playwright._impl._api_types import Error, TimeoutError
3738

@@ -105,10 +106,12 @@ class FrameNavigatedEvent(TypedDict):
105106

106107

107108
class URLMatcher:
108-
def __init__(self, match: URLMatch) -> None:
109+
def __init__(self, base_url: Union[str, None], match: URLMatch) -> None:
109110
self._callback: Optional[Callable[[str], bool]] = None
110111
self._regex_obj: Optional[Pattern] = None
111112
if isinstance(match, str):
113+
if base_url and not match.startswith("*"):
114+
match = urljoin(base_url, match)
112115
regex = fnmatch.translate(match)
113116
self._regex_obj = re.compile(regex)
114117
elif isinstance(match, Pattern):

playwright/_impl/_page.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,11 @@ def main_frame(self) -> Frame:
287287
return self._main_frame
288288

289289
def frame(self, name: str = None, url: URLMatch = None) -> Optional[Frame]:
290-
matcher = URLMatcher(url) if url else None
290+
matcher = (
291+
URLMatcher(self._browser_context._options.get("baseURL"), url)
292+
if url
293+
else None
294+
)
291295
for frame in self._frames:
292296
if name and frame.name == name:
293297
return frame
@@ -335,10 +339,10 @@ async def is_editable(self, selector: str, timeout: float = None) -> bool:
335339
async def is_enabled(self, selector: str, timeout: float = None) -> bool:
336340
return await self._main_frame.is_enabled(**locals_to_params(locals()))
337341

338-
async def is_hidden(self, selector: str, timeout: float = None) -> bool:
342+
async def is_hidden(self, selector: str) -> bool:
339343
return await self._main_frame.is_hidden(**locals_to_params(locals()))
340344

341-
async def is_visible(self, selector: str, timeout: float = None) -> bool:
345+
async def is_visible(self, selector: str) -> bool:
342346
return await self._main_frame.is_visible(**locals_to_params(locals()))
343347

344348
async def dispatch_event(
@@ -506,7 +510,11 @@ async def add_init_script(
506510
await self._channel.send("addInitScript", dict(source=script))
507511

508512
async def route(self, url: URLMatch, handler: RouteHandler) -> None:
509-
self._routes.append(RouteHandlerEntry(URLMatcher(url), handler))
513+
self._routes.append(
514+
RouteHandlerEntry(
515+
URLMatcher(self._browser_context._options.get("baseURL"), url), handler
516+
)
517+
)
510518
if len(self._routes) == 1:
511519
await self._channel.send(
512520
"setNetworkInterceptionEnabled", dict(enabled=True)
@@ -822,7 +830,13 @@ def expect_request(
822830
url_or_predicate: URLMatchRequest,
823831
timeout: float = None,
824832
) -> EventContextManagerImpl[Request]:
825-
matcher = None if callable(url_or_predicate) else URLMatcher(url_or_predicate)
833+
matcher = (
834+
None
835+
if callable(url_or_predicate)
836+
else URLMatcher(
837+
self._browser_context._options.get("baseURL"), url_or_predicate
838+
)
839+
)
826840
predicate = url_or_predicate if callable(url_or_predicate) else None
827841

828842
def my_predicate(request: Request) -> bool:
@@ -850,7 +864,13 @@ def expect_response(
850864
url_or_predicate: URLMatchResponse,
851865
timeout: float = None,
852866
) -> EventContextManagerImpl[Response]:
853-
matcher = None if callable(url_or_predicate) else URLMatcher(url_or_predicate)
867+
matcher = (
868+
None
869+
if callable(url_or_predicate)
870+
else URLMatcher(
871+
self._browser_context._options.get("baseURL"), url_or_predicate
872+
)
873+
)
854874
predicate = url_or_predicate if callable(url_or_predicate) else None
855875

856876
def my_predicate(response: Response) -> bool:

0 commit comments

Comments
 (0)