Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions playwright/_impl/_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ async def failure(self) -> Optional[str]:

async def delete(self) -> None:
await self._channel.send("delete")

async def cancel(self) -> None:
await self._channel.send("cancel")
2 changes: 2 additions & 0 deletions playwright/_impl/_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ async def new_context(
recordVideoDir: Union[Path, str] = None,
recordVideoSize: ViewportSize = None,
storageState: Union[StorageState, str, Path] = None,
baseURL: str = None,
) -> BrowserContext:
params = locals_to_params(locals())
await normalize_context_params(self._connection._is_sync, params)
Expand Down Expand Up @@ -145,6 +146,7 @@ async def new_page(
recordVideoDir: Union[Path, str] = None,
recordVideoSize: ViewportSize = None,
storageState: Union[StorageState, str, Path] = None,
baseURL: str = None,
) -> Page:
params = locals_to_params(locals())
context = await self.new_context(**params)
Expand Down
4 changes: 3 additions & 1 deletion playwright/_impl/_browser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ async def expose_function(self, name: str, callback: Callable) -> None:
await self.expose_binding(name, lambda source, *args: callback(*args))

async def route(self, url: URLMatch, handler: RouteHandler) -> None:
self._routes.append(RouteHandlerEntry(URLMatcher(url), handler))
self._routes.append(
RouteHandlerEntry(URLMatcher(self._options.get("baseURL"), url), handler)
)
if len(self._routes) == 1:
await self._channel.send(
"setNetworkInterceptionEnabled", dict(enabled=True)
Expand Down
1 change: 1 addition & 0 deletions playwright/_impl/_browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ async def launch_persistent_context(
recordHarOmitContent: bool = None,
recordVideoDir: Union[Path, str] = None,
recordVideoSize: ViewportSize = None,
baseURL: str = None,
) -> BrowserContext:
userDataDir = str(Path(userDataDir))
params = locals_to_params(locals())
Expand Down
3 changes: 3 additions & 0 deletions playwright/_impl/_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ async def path(self) -> Optional[pathlib.Path]:

async def save_as(self, path: Union[str, Path]) -> None:
await self._artifact.save_as(path)

async def cancel(self) -> None:
return await self._artifact.cancel()
12 changes: 8 additions & 4 deletions playwright/_impl/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ def expect_navigation(
timeout = self._page._timeout_settings.navigation_timeout()
deadline = monotonic_time() + timeout
wait_helper = self._setup_navigation_wait_helper("expect_navigation", timeout)
matcher = URLMatcher(url) if url else None
matcher = (
URLMatcher(self._page._browser_context._options.get("baseURL"), url)
if url
else None
)

def predicate(event: Any) -> bool:
# Any failed navigation results in a rejection.
Expand Down Expand Up @@ -188,7 +192,7 @@ async def wait_for_url(
wait_until: DocumentLoadState = None,
timeout: float = None,
) -> None:
matcher = URLMatcher(url)
matcher = URLMatcher(self._page._browser_context._options.get("baseURL"), url)
if matcher.matches(self.url):
await self.wait_for_load_state(state=wait_until, timeout=timeout)
return
Expand Down Expand Up @@ -274,10 +278,10 @@ async def is_editable(self, selector: str, timeout: float = None) -> bool:
async def is_enabled(self, selector: str, timeout: float = None) -> bool:
return await self._channel.send("isEnabled", locals_to_params(locals()))

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

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

async def dispatch_event(
Expand Down
5 changes: 4 additions & 1 deletion playwright/_impl/_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
Union,
cast,
)
from urllib.parse import urljoin

from playwright._impl._api_types import Error, TimeoutError

Expand Down Expand Up @@ -105,10 +106,12 @@ class FrameNavigatedEvent(TypedDict):


class URLMatcher:
def __init__(self, match: URLMatch) -> None:
def __init__(self, base_url: Union[str, None], match: URLMatch) -> None:
self._callback: Optional[Callable[[str], bool]] = None
self._regex_obj: Optional[Pattern] = None
if isinstance(match, str):
if base_url and not match.startswith("*"):
match = urljoin(base_url, match)
regex = fnmatch.translate(match)
self._regex_obj = re.compile(regex)
elif isinstance(match, Pattern):
Expand Down
32 changes: 26 additions & 6 deletions playwright/_impl/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,11 @@ def main_frame(self) -> Frame:
return self._main_frame

def frame(self, name: str = None, url: URLMatch = None) -> Optional[Frame]:
matcher = URLMatcher(url) if url else None
matcher = (
URLMatcher(self._browser_context._options.get("baseURL"), url)
if url
else None
)
for frame in self._frames:
if name and frame.name == name:
return frame
Expand Down Expand Up @@ -335,10 +339,10 @@ async def is_editable(self, selector: str, timeout: float = None) -> bool:
async def is_enabled(self, selector: str, timeout: float = None) -> bool:
return await self._main_frame.is_enabled(**locals_to_params(locals()))

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

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

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

async def route(self, url: URLMatch, handler: RouteHandler) -> None:
self._routes.append(RouteHandlerEntry(URLMatcher(url), handler))
self._routes.append(
RouteHandlerEntry(
URLMatcher(self._browser_context._options.get("baseURL"), url), handler
)
)
if len(self._routes) == 1:
await self._channel.send(
"setNetworkInterceptionEnabled", dict(enabled=True)
Expand Down Expand Up @@ -822,7 +830,13 @@ def expect_request(
url_or_predicate: URLMatchRequest,
timeout: float = None,
) -> EventContextManagerImpl[Request]:
matcher = None if callable(url_or_predicate) else URLMatcher(url_or_predicate)
matcher = (
None
if callable(url_or_predicate)
else URLMatcher(
self._browser_context._options.get("baseURL"), url_or_predicate
)
)
predicate = url_or_predicate if callable(url_or_predicate) else None

def my_predicate(request: Request) -> bool:
Expand Down Expand Up @@ -850,7 +864,13 @@ def expect_response(
url_or_predicate: URLMatchResponse,
timeout: float = None,
) -> EventContextManagerImpl[Response]:
matcher = None if callable(url_or_predicate) else URLMatcher(url_or_predicate)
matcher = (
None
if callable(url_or_predicate)
else URLMatcher(
self._browser_context._options.get("baseURL"), url_or_predicate
)
)
predicate = url_or_predicate if callable(url_or_predicate) else None

def my_predicate(response: Response) -> bool:
Expand Down
Loading