diff --git a/README.md b/README.md index d12581952..51314fa06 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H | | Linux | macOS | Windows | | :--- | :---: | :---: | :---: | -| Chromium 90.0.4396.0 | ✅ | ✅ | ✅ | +| Chromium 90.0.4412.0 | ✅ | ✅ | ✅ | | WebKit 14.1 | ✅ | ✅ | ✅ | -| Firefox 85.0b10 | ✅ | ✅ | ✅ | +| Firefox 86.0b9 | ✅ | ✅ | ✅ | Headless execution is supported for all browsers on all platforms. diff --git a/playwright/_impl/_browser.py b/playwright/_impl/_browser.py index 92936e8ee..6d41352a8 100644 --- a/playwright/_impl/_browser.py +++ b/playwright/_impl/_browser.py @@ -92,7 +92,7 @@ async def new_context( storageState: Union[StorageState, str, Path] = None, ) -> BrowserContext: params = locals_to_params(locals()) - normalize_context_params(params) + normalize_context_params(self._connection._is_sync, params) channel = await self._channel.send("newContext", params) context = from_channel(channel) @@ -151,7 +151,8 @@ def version(self) -> str: return self._initializer["version"] -def normalize_context_params(params: Dict) -> None: +def normalize_context_params(is_sync: bool, params: Dict) -> None: + params["sdkLanguage"] = "python" if is_sync else "python-async" if params.get("noViewport"): del params["noViewport"] params["noDefaultViewport"] = True diff --git a/playwright/_impl/_browser_context.py b/playwright/_impl/_browser_context.py index e89195b56..8c487adc3 100644 --- a/playwright/_impl/_browser_context.py +++ b/playwright/_impl/_browser_context.py @@ -207,7 +207,7 @@ def expect_event( ) -> EventContextManagerImpl: if timeout is None: timeout = self._timeout_settings.timeout() - wait_helper = WaitHelper(self._loop) + wait_helper = WaitHelper(self, f"expect_event({event})") wait_helper.reject_on_timeout( timeout, f'Timeout while waiting for event "{event}"' ) diff --git a/playwright/_impl/_browser_type.py b/playwright/_impl/_browser_type.py index f8d35e0a2..db4cb1b53 100644 --- a/playwright/_impl/_browser_type.py +++ b/playwright/_impl/_browser_type.py @@ -115,7 +115,7 @@ async def launch_persistent_context( ) -> BrowserContext: userDataDir = str(Path(userDataDir)) params = locals_to_params(locals()) - normalize_context_params(params) + normalize_context_params(self._connection._is_sync, params) normalize_launch_params(params) try: context = from_channel( diff --git a/playwright/_impl/_connection.py b/playwright/_impl/_connection.py index 230ef3981..3c0cd6da4 100644 --- a/playwright/_impl/_connection.py +++ b/playwright/_impl/_connection.py @@ -16,7 +16,7 @@ import sys import traceback from pathlib import Path -from typing import Any, Callable, Dict, Optional, Union +from typing import Any, Callable, Dict, List, Optional, Union from greenlet import greenlet from pyee import AsyncIOEventEmitter @@ -92,6 +92,32 @@ def __init__( if self._parent: self._parent._objects[guid] = self + def _wait_for_event_info_before(self, wait_id: str, name: str) -> None: + self._connection._send_message_to_server( + self._guid, + "waitForEventInfo", + { + "info": { + "name": name, + "waitId": wait_id, + "phase": "before", + "stack": capture_call_stack(), + } + }, + ) + + def _wait_for_event_info_after( + self, wait_id: str, exception: Exception = None + ) -> None: + info = {"waitId": wait_id, "phase": "after"} + if exception: + info["error"] = str(exception) + self._connection._send_message_to_server( + self._guid, + "waitForEventInfo", + {"info": info}, + ) + def _dispose(self) -> None: # Clean up from parent and connection. if self._parent: @@ -106,7 +132,7 @@ def _dispose(self) -> None: class ProtocolCallback: def __init__(self, loop: asyncio.AbstractEventLoop) -> None: - self.stack_trace = "".join(traceback.format_stack()[-10:]) + self.stack_trace: traceback.StackSummary = traceback.StackSummary() self.future = loop.create_future() @@ -166,14 +192,23 @@ def _send_message_to_server( ) -> ProtocolCallback: self._last_id += 1 id = self._last_id + callback = ProtocolCallback(self._loop) + if self._is_sync: + task = asyncio.current_task(self._loop) + callback.stack_trace = ( + getattr(task, "__pw_stack_trace__", None) if task else None + ) + if not callback.stack_trace: + callback.stack_trace = traceback.extract_stack() + message = dict( id=id, guid=guid, method=method, params=self._replace_channels_with_guids(params, "params"), + metadata={"stack": serialize_call_stack(callback.stack_trace)}, ) self._transport.send(message) - callback = ProtocolCallback(self._loop) self._callbacks[id] = callback return callback @@ -184,7 +219,9 @@ def _dispatch(self, msg: ParsedMessagePayload) -> None: error = msg.get("error") if error: parsed_error = parse_error(error["error"]) # type: ignore - parsed_error.stack = callback.stack_trace + parsed_error.stack = "".join( + traceback.format_list(callback.stack_trace)[-10:] + ) callback.future.set_exception(parsed_error) else: result = self._replace_guids_with_channels(msg.get("result")) @@ -267,3 +304,19 @@ def from_channel(channel: Channel) -> Any: def from_nullable_channel(channel: Optional[Channel]) -> Optional[Any]: return channel._object if channel else None + + +def serialize_call_stack(stack_trace: traceback.StackSummary) -> List[Dict]: + stack: List[Dict] = [] + for frame in stack_trace: + if "_generated.py" in frame.filename: + break + stack.append( + {"file": frame.filename, "line": frame.lineno, "function": frame.name} + ) + stack.reverse() + return stack + + +def capture_call_stack() -> List[Dict]: + return serialize_call_stack(traceback.extract_stack()) diff --git a/playwright/_impl/_driver.py b/playwright/_impl/_driver.py index 87778055d..307e0c291 100644 --- a/playwright/_impl/_driver.py +++ b/playwright/_impl/_driver.py @@ -18,7 +18,6 @@ from pathlib import Path import playwright -from playwright._impl._logger import init_logger def compute_driver_executable() -> Path: @@ -38,5 +37,3 @@ def compute_driver_executable() -> Path: # RuntimeError: Cannot add child handler, the child watcher does not have a loop attached asyncio.get_event_loop() asyncio.get_child_watcher() - -init_logger() diff --git a/playwright/_impl/_frame.py b/playwright/_impl/_frame.py index 77de350c4..f123d6ad7 100644 --- a/playwright/_impl/_frame.py +++ b/playwright/_impl/_frame.py @@ -115,8 +115,10 @@ async def goto( ), ) - def _setup_navigation_wait_helper(self, timeout: float = None) -> WaitHelper: - wait_helper = WaitHelper(self._loop) + def _setup_navigation_wait_helper( + self, wait_name: str, timeout: float = None + ) -> WaitHelper: + wait_helper = WaitHelper(self, wait_name) wait_helper.reject_on_event( self._page, "close", Error("Navigation failed because page was closed!") ) @@ -146,7 +148,7 @@ def expect_navigation( if timeout is None: timeout = self._page._timeout_settings.navigation_timeout() deadline = monotonic_time() + timeout - wait_helper = self._setup_navigation_wait_helper(timeout) + wait_helper = self._setup_navigation_wait_helper("expect_navigation", timeout) matcher = URLMatcher(url) if url else None def predicate(event: Any) -> bool: @@ -185,7 +187,7 @@ async def wait_for_load_state( raise Error("state: expected one of (load|domcontentloaded|networkidle)") if state in self._load_states: return - wait_helper = self._setup_navigation_wait_helper(timeout) + wait_helper = self._setup_navigation_wait_helper("wait_for_load_state", timeout) wait_helper.wait_for_event( self._event_emitter, "loadstate", lambda s: s == state ) diff --git a/playwright/_impl/_logger.py b/playwright/_impl/_logger.py deleted file mode 100644 index b1e6e6ca9..000000000 --- a/playwright/_impl/_logger.py +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys - -debug_enabled = os.environ.get("PWDEBUG") or ( - "DEBUG" in os.environ and "pw:api" in os.environ["DEBUG"] -) - - -def init_logger() -> None: - if os.environ.get("PWDEBUG"): - os.environ["DEBUG"] = ( - os.environ["DEBUG"] + ",pw:api" if "DEBUG" in os.environ else "pw:api" - ) - - -def log_api(text: str) -> None: - if debug_enabled: - print(f" \033[1m\033[96mpw:api\033[0m {text}", file=sys.stderr) diff --git a/playwright/_impl/_network.py b/playwright/_impl/_network.py index 81a5c0e3b..4a69104be 100644 --- a/playwright/_impl/_network.py +++ b/playwright/_impl/_network.py @@ -301,7 +301,7 @@ def expect_event( ) -> EventContextManagerImpl: if timeout is None: timeout = cast(Any, self._parent)._timeout_settings.timeout() - wait_helper = WaitHelper(self._loop) + wait_helper = WaitHelper(self, f"expect_event({event})") wait_helper.reject_on_timeout( timeout, f'Timeout while waiting for event "{event}"' ) diff --git a/playwright/_impl/_page.py b/playwright/_impl/_page.py index e7c19cce4..1d8708f48 100644 --- a/playwright/_impl/_page.py +++ b/playwright/_impl/_page.py @@ -779,7 +779,7 @@ def expect_event( ) -> EventContextManagerImpl: if timeout is None: timeout = self._timeout_settings.timeout() - wait_helper = WaitHelper(self._loop) + wait_helper = WaitHelper(self, f"expect_event({event})") wait_helper.reject_on_timeout( timeout, f'Timeout while waiting for event "{event}"' ) diff --git a/playwright/_impl/_sync_base.py b/playwright/_impl/_sync_base.py index c0cded590..0e0986797 100644 --- a/playwright/_impl/_sync_base.py +++ b/playwright/_impl/_sync_base.py @@ -13,7 +13,18 @@ # limitations under the License. import asyncio -from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar, cast +import traceback +from typing import ( + Any, + Awaitable, + Callable, + Dict, + Generic, + List, + Optional, + TypeVar, + cast, +) import greenlet @@ -70,24 +81,26 @@ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: class SyncBase(ImplWrapper): def __init__(self, impl_obj: Any) -> None: super().__init__(impl_obj) - self._loop = impl_obj._loop + self._loop: asyncio.BaseEventLoop = impl_obj._loop self._dispatcher_fiber = impl_obj._dispatcher_fiber def __str__(self) -> str: return self._impl_obj.__str__() - def _sync(self, task: asyncio.Future) -> Any: + def _sync(self, coro: Awaitable) -> Any: + stack_trace = traceback.extract_stack() g_self = greenlet.getcurrent() - future = self._loop.create_task(task) + task = self._loop.create_task(coro) + setattr(task, "__pw_stack_trace__", stack_trace) def callback(result: Any) -> None: g_self.switch() - future.add_done_callback(callback) - while not future.done(): + task.add_done_callback(callback) + while not task.done(): self._dispatcher_fiber.switch() asyncio._set_running_loop(self._loop) - return future.result() + return task.result() def _wrap_handler(self, handler: Any) -> Callable[..., None]: if callable(handler): diff --git a/playwright/_impl/_wait_helper.py b/playwright/_impl/_wait_helper.py index 0a89f880b..bf8134d54 100644 --- a/playwright/_impl/_wait_helper.py +++ b/playwright/_impl/_wait_helper.py @@ -13,22 +13,27 @@ # limitations under the License. import asyncio +import uuid from asyncio.tasks import Task from typing import Any, Callable, Generic, List, Tuple, TypeVar from pyee import EventEmitter from playwright._impl._api_types import Error, TimeoutError +from playwright._impl._connection import ChannelOwner T = TypeVar("T") class WaitHelper(Generic[T]): - def __init__(self, loop: asyncio.AbstractEventLoop) -> None: + def __init__(self, channel_owner: ChannelOwner, name: str) -> None: self._result: asyncio.Future = asyncio.Future() - self._loop = loop + self._wait_id = uuid.uuid4().hex + self._loop = channel_owner._loop self._pending_tasks: List[Task] = [] + self._channel_owner = channel_owner self._registered_listeners: List[Tuple[EventEmitter, str, Callable]] = [] + channel_owner._wait_for_event_info_before(self._wait_id, name) def reject_on_event( self, @@ -65,11 +70,13 @@ def _fulfill(self, result: Any) -> None: self._cleanup() if not self._result.done(): self._result.set_result(result) + self._channel_owner._wait_for_event_info_after(self._wait_id) def _reject(self, exception: Exception) -> None: self._cleanup() if not self._result.done(): self._result.set_exception(exception) + self._channel_owner._wait_for_event_info_after(self._wait_id, exception) def wait_for_event( self, diff --git a/playwright/async_api/_generated.py b/playwright/async_api/_generated.py index fe5a7cf5c..b8357d2a9 100644 --- a/playwright/async_api/_generated.py +++ b/playwright/async_api/_generated.py @@ -55,7 +55,6 @@ from playwright._impl._input import Mouse as MouseImpl from playwright._impl._input import Touchscreen as TouchscreenImpl from playwright._impl._js_handle import JSHandle as JSHandleImpl -from playwright._impl._logger import log_api from playwright._impl._network import Request as RequestImpl from playwright._impl._network import Response as ResponseImpl from playwright._impl._network import Route as RouteImpl @@ -271,14 +270,7 @@ async def response(self) -> typing.Union["Response", NoneType]: Union[Response, NoneType] """ - try: - log_api("=> request.response started") - result = mapping.from_impl_nullable(await self._impl_obj.response()) - log_api("<= request.response succeded") - return result - except Exception as e: - log_api("<= request.response failed") - raise e + return mapping.from_impl_nullable(await self._impl_obj.response()) def is_navigation_request(self) -> bool: """Request.is_navigation_request @@ -290,14 +282,7 @@ def is_navigation_request(self) -> bool: bool """ - try: - log_api("=> request.is_navigation_request started") - result = mapping.from_maybe_impl(self._impl_obj.is_navigation_request()) - log_api("<= request.is_navigation_request succeded") - return result - except Exception as e: - log_api("<= request.is_navigation_request failed") - raise e + return mapping.from_maybe_impl(self._impl_obj.is_navigation_request()) mapping.register(RequestImpl, Request) @@ -401,14 +386,7 @@ async def finished(self) -> typing.Union[str, NoneType]: Union[str, NoneType] """ - try: - log_api("=> response.finished started") - result = mapping.from_maybe_impl(await self._impl_obj.finished()) - log_api("<= response.finished succeded") - return result - except Exception as e: - log_api("<= response.finished failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.finished()) async def body(self) -> bytes: """Response.body @@ -420,14 +398,7 @@ async def body(self) -> bytes: bytes """ - try: - log_api("=> response.body started") - result = mapping.from_maybe_impl(await self._impl_obj.body()) - log_api("<= response.body succeded") - return result - except Exception as e: - log_api("<= response.body failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.body()) async def text(self) -> str: """Response.text @@ -439,14 +410,7 @@ async def text(self) -> str: str """ - try: - log_api("=> response.text started") - result = mapping.from_maybe_impl(await self._impl_obj.text()) - log_api("<= response.text succeded") - return result - except Exception as e: - log_api("<= response.text failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.text()) async def json(self) -> typing.Any: """Response.json @@ -460,14 +424,7 @@ async def json(self) -> typing.Any: Any """ - try: - log_api("=> response.json started") - result = mapping.from_maybe_impl(await self._impl_obj.json()) - log_api("<= response.json succeded") - return result - except Exception as e: - log_api("<= response.json failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.json()) mapping.register(ResponseImpl, Response) @@ -516,16 +473,7 @@ async def abort(self, error_code: str = None) -> NoneType: - `'failed'` - A generic failure occurred. """ - try: - log_api("=> route.abort started") - result = mapping.from_maybe_impl( - await self._impl_obj.abort(errorCode=error_code) - ) - log_api("<= route.abort succeded") - return result - except Exception as e: - log_api("<= route.abort failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.abort(errorCode=error_code)) async def fulfill( self, @@ -570,22 +518,15 @@ async def fulfill( If set, equals to setting `Content-Type` response header. """ - try: - log_api("=> route.fulfill started") - result = mapping.from_maybe_impl( - await self._impl_obj.fulfill( - status=status, - headers=mapping.to_impl(headers), - body=body, - path=path, - contentType=content_type, - ) + return mapping.from_maybe_impl( + await self._impl_obj.fulfill( + status=status, + headers=mapping.to_impl(headers), + body=body, + path=path, + contentType=content_type, ) - log_api("<= route.fulfill succeded") - return result - except Exception as e: - log_api("<= route.fulfill failed") - raise e + ) async def continue_( self, @@ -624,21 +565,14 @@ async def handle(route, request): If set changes the post data of request """ - try: - log_api("=> route.continue_ started") - result = mapping.from_maybe_impl( - await self._impl_obj.continue_( - url=url, - method=method, - headers=mapping.to_impl(headers), - postData=post_data, - ) + return mapping.from_maybe_impl( + await self._impl_obj.continue_( + url=url, + method=method, + headers=mapping.to_impl(headers), + postData=post_data, ) - log_api("<= route.continue_ succeded") - return result - except Exception as e: - log_api("<= route.continue_ failed") - raise e + ) mapping.register(RouteImpl, Route) @@ -715,20 +649,11 @@ async def wait_for_event( Any """ - try: - log_api("=> web_socket.wait_for_event started") - result = mapping.from_maybe_impl( - await self._impl_obj.wait_for_event( - event=event, - predicate=self._wrap_handler(predicate), - timeout=timeout, - ) + return mapping.from_maybe_impl( + await self._impl_obj.wait_for_event( + event=event, predicate=self._wrap_handler(predicate), timeout=timeout ) - log_api("<= web_socket.wait_for_event succeded") - return result - except Exception as e: - log_api("<= web_socket.wait_for_event failed") - raise e + ) def is_closed(self) -> bool: """WebSocket.is_closed @@ -740,14 +665,7 @@ def is_closed(self) -> bool: bool """ - try: - log_api("=> web_socket.is_closed started") - result = mapping.from_maybe_impl(self._impl_obj.is_closed()) - log_api("<= web_socket.is_closed succeded") - return result - except Exception as e: - log_api("<= web_socket.is_closed failed") - raise e + return mapping.from_maybe_impl(self._impl_obj.is_closed()) mapping.register(WebSocketImpl, WebSocket) @@ -791,14 +709,7 @@ async def down(self, key: str) -> NoneType: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. """ - try: - log_api("=> keyboard.down started") - result = mapping.from_maybe_impl(await self._impl_obj.down(key=key)) - log_api("<= keyboard.down succeded") - return result - except Exception as e: - log_api("<= keyboard.down failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.down(key=key)) async def up(self, key: str) -> NoneType: """Keyboard.up @@ -811,14 +722,7 @@ async def up(self, key: str) -> NoneType: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. """ - try: - log_api("=> keyboard.up started") - result = mapping.from_maybe_impl(await self._impl_obj.up(key=key)) - log_api("<= keyboard.up succeded") - return result - except Exception as e: - log_api("<= keyboard.up failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.up(key=key)) async def insert_text(self, text: str) -> NoneType: """Keyboard.insert_text @@ -837,16 +741,7 @@ async def insert_text(self, text: str) -> NoneType: Sets input to the specified text value. """ - try: - log_api("=> keyboard.insert_text started") - result = mapping.from_maybe_impl( - await self._impl_obj.insert_text(text=text) - ) - log_api("<= keyboard.insert_text succeded") - return result - except Exception as e: - log_api("<= keyboard.insert_text failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.insert_text(text=text)) async def type(self, text: str, *, delay: float = None) -> NoneType: """Keyboard.type @@ -870,16 +765,9 @@ async def type(self, text: str, *, delay: float = None) -> NoneType: Time to wait between key presses in milliseconds. Defaults to 0. """ - try: - log_api("=> keyboard.type started") - result = mapping.from_maybe_impl( - await self._impl_obj.type(text=text, delay=delay) - ) - log_api("<= keyboard.type succeded") - return result - except Exception as e: - log_api("<= keyboard.type failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.type(text=text, delay=delay) + ) async def press(self, key: str, *, delay: float = None) -> NoneType: """Keyboard.press @@ -923,16 +811,7 @@ async def press(self, key: str, *, delay: float = None) -> NoneType: Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. """ - try: - log_api("=> keyboard.press started") - result = mapping.from_maybe_impl( - await self._impl_obj.press(key=key, delay=delay) - ) - log_api("<= keyboard.press succeded") - return result - except Exception as e: - log_api("<= keyboard.press failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.press(key=key, delay=delay)) mapping.register(KeyboardImpl, Keyboard) @@ -955,16 +834,7 @@ async def move(self, x: float, y: float, *, steps: int = None) -> NoneType: defaults to 1. Sends intermediate `mousemove` events. """ - try: - log_api("=> mouse.move started") - result = mapping.from_maybe_impl( - await self._impl_obj.move(x=x, y=y, steps=steps) - ) - log_api("<= mouse.move succeded") - return result - except Exception as e: - log_api("<= mouse.move failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.move(x=x, y=y, steps=steps)) async def down( self, @@ -984,16 +854,9 @@ async def down( defaults to 1. See [UIEvent.detail]. """ - try: - log_api("=> mouse.down started") - result = mapping.from_maybe_impl( - await self._impl_obj.down(button=button, clickCount=click_count) - ) - log_api("<= mouse.down succeded") - return result - except Exception as e: - log_api("<= mouse.down failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.down(button=button, clickCount=click_count) + ) async def up( self, @@ -1013,16 +876,9 @@ async def up( defaults to 1. See [UIEvent.detail]. """ - try: - log_api("=> mouse.up started") - result = mapping.from_maybe_impl( - await self._impl_obj.up(button=button, clickCount=click_count) - ) - log_api("<= mouse.up succeded") - return result - except Exception as e: - log_api("<= mouse.up failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.up(button=button, clickCount=click_count) + ) async def click( self, @@ -1049,18 +905,11 @@ async def click( defaults to 1. See [UIEvent.detail]. """ - try: - log_api("=> mouse.click started") - result = mapping.from_maybe_impl( - await self._impl_obj.click( - x=x, y=y, delay=delay, button=button, clickCount=click_count - ) + return mapping.from_maybe_impl( + await self._impl_obj.click( + x=x, y=y, delay=delay, button=button, clickCount=click_count ) - log_api("<= mouse.click succeded") - return result - except Exception as e: - log_api("<= mouse.click failed") - raise e + ) async def dblclick( self, @@ -1085,16 +934,9 @@ async def dblclick( Defaults to `left`. """ - try: - log_api("=> mouse.dblclick started") - result = mapping.from_maybe_impl( - await self._impl_obj.dblclick(x=x, y=y, delay=delay, button=button) - ) - log_api("<= mouse.dblclick succeded") - return result - except Exception as e: - log_api("<= mouse.dblclick failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.dblclick(x=x, y=y, delay=delay, button=button) + ) mapping.register(MouseImpl, Mouse) @@ -1115,14 +957,7 @@ async def tap(self, x: float, y: float) -> NoneType: y : float """ - try: - log_api("=> touchscreen.tap started") - result = mapping.from_maybe_impl(await self._impl_obj.tap(x=x, y=y)) - log_api("<= touchscreen.tap succeded") - return result - except Exception as e: - log_api("<= touchscreen.tap failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.tap(x=x, y=y)) mapping.register(TouchscreenImpl, Touchscreen) @@ -1154,25 +989,18 @@ async def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any: JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> js_handle.evaluate started") - result = mapping.from_maybe_impl( - await self._impl_obj.evaluate( - expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_maybe_impl( + await self._impl_obj.evaluate( + expression=expression, arg=mapping.to_impl(arg) ) - log_api("<= js_handle.evaluate succeded") - return result - except Exception as e: - log_api("<= js_handle.evaluate failed") - raise e + ) async def evaluate_handle( self, expression: str, arg: typing.Any = None @@ -1197,25 +1025,18 @@ async def evaluate_handle( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- JSHandle """ - try: - log_api("=> js_handle.evaluate_handle started") - result = mapping.from_impl( - await self._impl_obj.evaluate_handle( - expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_impl( + await self._impl_obj.evaluate_handle( + expression=expression, arg=mapping.to_impl(arg) ) - log_api("<= js_handle.evaluate_handle succeded") - return result - except Exception as e: - log_api("<= js_handle.evaluate_handle failed") - raise e + ) async def get_property(self, property_name: str) -> "JSHandle": """JSHandle.get_property @@ -1232,16 +1053,9 @@ async def get_property(self, property_name: str) -> "JSHandle": JSHandle """ - try: - log_api("=> js_handle.get_property started") - result = mapping.from_impl( - await self._impl_obj.get_property(propertyName=property_name) - ) - log_api("<= js_handle.get_property succeded") - return result - except Exception as e: - log_api("<= js_handle.get_property failed") - raise e + return mapping.from_impl( + await self._impl_obj.get_property(propertyName=property_name) + ) async def get_properties(self) -> typing.Dict[str, "JSHandle"]: """JSHandle.get_properties @@ -1261,14 +1075,7 @@ async def get_properties(self) -> typing.Dict[str, "JSHandle"]: Dict[str, JSHandle] """ - try: - log_api("=> js_handle.get_properties started") - result = mapping.from_impl_dict(await self._impl_obj.get_properties()) - log_api("<= js_handle.get_properties succeded") - return result - except Exception as e: - log_api("<= js_handle.get_properties failed") - raise e + return mapping.from_impl_dict(await self._impl_obj.get_properties()) def as_element(self) -> typing.Union["ElementHandle", NoneType]: """JSHandle.as_element @@ -1280,14 +1087,7 @@ def as_element(self) -> typing.Union["ElementHandle", NoneType]: Union[ElementHandle, NoneType] """ - try: - log_api("=> js_handle.as_element started") - result = mapping.from_impl_nullable(self._impl_obj.as_element()) - log_api("<= js_handle.as_element succeded") - return result - except Exception as e: - log_api("<= js_handle.as_element failed") - raise e + return mapping.from_impl_nullable(self._impl_obj.as_element()) async def dispose(self) -> NoneType: """JSHandle.dispose @@ -1295,14 +1095,7 @@ async def dispose(self) -> NoneType: The `jsHandle.dispose` method stops referencing the element handle. """ - try: - log_api("=> js_handle.dispose started") - result = mapping.from_maybe_impl(await self._impl_obj.dispose()) - log_api("<= js_handle.dispose succeded") - return result - except Exception as e: - log_api("<= js_handle.dispose failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.dispose()) async def json_value(self) -> typing.Any: """JSHandle.json_value @@ -1317,14 +1110,7 @@ async def json_value(self) -> typing.Any: Any """ - try: - log_api("=> js_handle.json_value started") - result = mapping.from_maybe_impl(await self._impl_obj.json_value()) - log_api("<= js_handle.json_value succeded") - return result - except Exception as e: - log_api("<= js_handle.json_value failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.json_value()) mapping.register(JSHandleImpl, JSHandle) @@ -1344,14 +1130,7 @@ def as_element(self) -> typing.Union["ElementHandle", NoneType]: Union[ElementHandle, NoneType] """ - try: - log_api("=> element_handle.as_element started") - result = mapping.from_impl_nullable(self._impl_obj.as_element()) - log_api("<= element_handle.as_element succeded") - return result - except Exception as e: - log_api("<= element_handle.as_element failed") - raise e + return mapping.from_impl_nullable(self._impl_obj.as_element()) async def owner_frame(self) -> typing.Union["Frame", NoneType]: """ElementHandle.owner_frame @@ -1363,14 +1142,7 @@ async def owner_frame(self) -> typing.Union["Frame", NoneType]: Union[Frame, NoneType] """ - try: - log_api("=> element_handle.owner_frame started") - result = mapping.from_impl_nullable(await self._impl_obj.owner_frame()) - log_api("<= element_handle.owner_frame succeded") - return result - except Exception as e: - log_api("<= element_handle.owner_frame failed") - raise e + return mapping.from_impl_nullable(await self._impl_obj.owner_frame()) async def content_frame(self) -> typing.Union["Frame", NoneType]: """ElementHandle.content_frame @@ -1382,14 +1154,7 @@ async def content_frame(self) -> typing.Union["Frame", NoneType]: Union[Frame, NoneType] """ - try: - log_api("=> element_handle.content_frame started") - result = mapping.from_impl_nullable(await self._impl_obj.content_frame()) - log_api("<= element_handle.content_frame succeded") - return result - except Exception as e: - log_api("<= element_handle.content_frame failed") - raise e + return mapping.from_impl_nullable(await self._impl_obj.content_frame()) async def get_attribute(self, name: str) -> typing.Union[str, NoneType]: """ElementHandle.get_attribute @@ -1406,16 +1171,7 @@ async def get_attribute(self, name: str) -> typing.Union[str, NoneType]: Union[str, NoneType] """ - try: - log_api("=> element_handle.get_attribute started") - result = mapping.from_maybe_impl( - await self._impl_obj.get_attribute(name=name) - ) - log_api("<= element_handle.get_attribute succeded") - return result - except Exception as e: - log_api("<= element_handle.get_attribute failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.get_attribute(name=name)) async def text_content(self) -> typing.Union[str, NoneType]: """ElementHandle.text_content @@ -1427,14 +1183,7 @@ async def text_content(self) -> typing.Union[str, NoneType]: Union[str, NoneType] """ - try: - log_api("=> element_handle.text_content started") - result = mapping.from_maybe_impl(await self._impl_obj.text_content()) - log_api("<= element_handle.text_content succeded") - return result - except Exception as e: - log_api("<= element_handle.text_content failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.text_content()) async def inner_text(self) -> str: """ElementHandle.inner_text @@ -1446,14 +1195,7 @@ async def inner_text(self) -> str: str """ - try: - log_api("=> element_handle.inner_text started") - result = mapping.from_maybe_impl(await self._impl_obj.inner_text()) - log_api("<= element_handle.inner_text succeded") - return result - except Exception as e: - log_api("<= element_handle.inner_text failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.inner_text()) async def inner_html(self) -> str: """ElementHandle.inner_html @@ -1465,14 +1207,7 @@ async def inner_html(self) -> str: str """ - try: - log_api("=> element_handle.inner_html started") - result = mapping.from_maybe_impl(await self._impl_obj.inner_html()) - log_api("<= element_handle.inner_html succeded") - return result - except Exception as e: - log_api("<= element_handle.inner_html failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.inner_html()) async def is_checked(self) -> bool: """ElementHandle.is_checked @@ -1484,14 +1219,7 @@ async def is_checked(self) -> bool: bool """ - try: - log_api("=> element_handle.is_checked started") - result = mapping.from_maybe_impl(await self._impl_obj.is_checked()) - log_api("<= element_handle.is_checked succeded") - return result - except Exception as e: - log_api("<= element_handle.is_checked failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.is_checked()) async def is_disabled(self) -> bool: """ElementHandle.is_disabled @@ -1503,14 +1231,7 @@ async def is_disabled(self) -> bool: bool """ - try: - log_api("=> element_handle.is_disabled started") - result = mapping.from_maybe_impl(await self._impl_obj.is_disabled()) - log_api("<= element_handle.is_disabled succeded") - return result - except Exception as e: - log_api("<= element_handle.is_disabled failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.is_disabled()) async def is_editable(self) -> bool: """ElementHandle.is_editable @@ -1522,14 +1243,7 @@ async def is_editable(self) -> bool: bool """ - try: - log_api("=> element_handle.is_editable started") - result = mapping.from_maybe_impl(await self._impl_obj.is_editable()) - log_api("<= element_handle.is_editable succeded") - return result - except Exception as e: - log_api("<= element_handle.is_editable failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.is_editable()) async def is_enabled(self) -> bool: """ElementHandle.is_enabled @@ -1541,14 +1255,7 @@ async def is_enabled(self) -> bool: bool """ - try: - log_api("=> element_handle.is_enabled started") - result = mapping.from_maybe_impl(await self._impl_obj.is_enabled()) - log_api("<= element_handle.is_enabled succeded") - return result - except Exception as e: - log_api("<= element_handle.is_enabled failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.is_enabled()) async def is_hidden(self) -> bool: """ElementHandle.is_hidden @@ -1560,14 +1267,7 @@ async def is_hidden(self) -> bool: bool """ - try: - log_api("=> element_handle.is_hidden started") - result = mapping.from_maybe_impl(await self._impl_obj.is_hidden()) - log_api("<= element_handle.is_hidden succeded") - return result - except Exception as e: - log_api("<= element_handle.is_hidden failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.is_hidden()) async def is_visible(self) -> bool: """ElementHandle.is_visible @@ -1579,14 +1279,7 @@ async def is_visible(self) -> bool: bool """ - try: - log_api("=> element_handle.is_visible started") - result = mapping.from_maybe_impl(await self._impl_obj.is_visible()) - log_api("<= element_handle.is_visible succeded") - return result - except Exception as e: - log_api("<= element_handle.is_visible failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.is_visible()) async def dispatch_event( self, type: str, event_init: typing.Dict = None @@ -1629,18 +1322,11 @@ async def dispatch_event( Optional event-specific initialization properties. """ - try: - log_api("=> element_handle.dispatch_event started") - result = mapping.from_maybe_impl( - await self._impl_obj.dispatch_event( - type=type, eventInit=mapping.to_impl(event_init) - ) + return mapping.from_maybe_impl( + await self._impl_obj.dispatch_event( + type=type, eventInit=mapping.to_impl(event_init) ) - log_api("<= element_handle.dispatch_event succeded") - return result - except Exception as e: - log_api("<= element_handle.dispatch_event failed") - raise e + ) async def scroll_into_view_if_needed(self, *, timeout: float = None) -> NoneType: """ElementHandle.scroll_into_view_if_needed @@ -1659,16 +1345,9 @@ async def scroll_into_view_if_needed(self, *, timeout: float = None) -> NoneType using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ - try: - log_api("=> element_handle.scroll_into_view_if_needed started") - result = mapping.from_maybe_impl( - await self._impl_obj.scroll_into_view_if_needed(timeout=timeout) - ) - log_api("<= element_handle.scroll_into_view_if_needed succeded") - return result - except Exception as e: - log_api("<= element_handle.scroll_into_view_if_needed failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.scroll_into_view_if_needed(timeout=timeout) + ) async def hover( self, @@ -1708,18 +1387,11 @@ async def hover( Whether to bypass the [actionability](./actionability.md) checks. Defaults to `false`. """ - try: - log_api("=> element_handle.hover started") - result = mapping.from_maybe_impl( - await self._impl_obj.hover( - modifiers=modifiers, position=position, timeout=timeout, force=force - ) + return mapping.from_maybe_impl( + await self._impl_obj.hover( + modifiers=modifiers, position=position, timeout=timeout, force=force ) - log_api("<= element_handle.hover succeded") - return result - except Exception as e: - log_api("<= element_handle.hover failed") - raise e + ) async def click( self, @@ -1773,25 +1445,18 @@ async def click( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.click started") - result = mapping.from_maybe_impl( - await self._impl_obj.click( - modifiers=modifiers, - position=position, - delay=delay, - button=button, - clickCount=click_count, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.click( + modifiers=modifiers, + position=position, + delay=delay, + button=button, + clickCount=click_count, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) - log_api("<= element_handle.click succeded") - return result - except Exception as e: - log_api("<= element_handle.click failed") - raise e + ) async def dblclick( self, @@ -1845,24 +1510,17 @@ async def dblclick( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.dblclick started") - result = mapping.from_maybe_impl( - await self._impl_obj.dblclick( - modifiers=modifiers, - position=position, - delay=delay, - button=button, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.dblclick( + modifiers=modifiers, + position=position, + delay=delay, + button=button, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) - log_api("<= element_handle.dblclick succeded") - return result - except Exception as e: - log_api("<= element_handle.dblclick failed") - raise e + ) async def select_option( self, @@ -1917,23 +1575,16 @@ async def select_option( List[str] """ - try: - log_api("=> element_handle.select_option started") - result = mapping.from_maybe_impl( - await self._impl_obj.select_option( - value=value, - index=index, - label=label, - element=mapping.to_impl(element), - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.select_option( + value=value, + index=index, + label=label, + element=mapping.to_impl(element), + timeout=timeout, + noWaitAfter=no_wait_after, ) - log_api("<= element_handle.select_option succeded") - return result - except Exception as e: - log_api("<= element_handle.select_option failed") - raise e + ) async def tap( self, @@ -1980,22 +1631,15 @@ async def tap( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.tap started") - result = mapping.from_maybe_impl( - await self._impl_obj.tap( - modifiers=modifiers, - position=position, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.tap( + modifiers=modifiers, + position=position, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) - log_api("<= element_handle.tap succeded") - return result - except Exception as e: - log_api("<= element_handle.tap failed") - raise e + ) async def fill( self, value: str, *, timeout: float = None, no_wait_after: bool = None @@ -2021,18 +1665,11 @@ async def fill( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.fill started") - result = mapping.from_maybe_impl( - await self._impl_obj.fill( - value=value, timeout=timeout, noWaitAfter=no_wait_after - ) + return mapping.from_maybe_impl( + await self._impl_obj.fill( + value=value, timeout=timeout, noWaitAfter=no_wait_after ) - log_api("<= element_handle.fill succeded") - return result - except Exception as e: - log_api("<= element_handle.fill failed") - raise e + ) async def select_text(self, *, timeout: float = None) -> NoneType: """ElementHandle.select_text @@ -2047,16 +1684,9 @@ async def select_text(self, *, timeout: float = None) -> NoneType: using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ - try: - log_api("=> element_handle.select_text started") - result = mapping.from_maybe_impl( - await self._impl_obj.select_text(timeout=timeout) - ) - log_api("<= element_handle.select_text succeded") - return result - except Exception as e: - log_api("<= element_handle.select_text failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.select_text(timeout=timeout) + ) async def set_input_files( self, @@ -2091,18 +1721,11 @@ async def set_input_files( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.set_input_files started") - result = mapping.from_maybe_impl( - await self._impl_obj.set_input_files( - files=files, timeout=timeout, noWaitAfter=no_wait_after - ) + return mapping.from_maybe_impl( + await self._impl_obj.set_input_files( + files=files, timeout=timeout, noWaitAfter=no_wait_after ) - log_api("<= element_handle.set_input_files succeded") - return result - except Exception as e: - log_api("<= element_handle.set_input_files failed") - raise e + ) async def focus(self) -> NoneType: """ElementHandle.focus @@ -2110,14 +1733,7 @@ async def focus(self) -> NoneType: Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the element. """ - try: - log_api("=> element_handle.focus started") - result = mapping.from_maybe_impl(await self._impl_obj.focus()) - log_api("<= element_handle.focus succeded") - return result - except Exception as e: - log_api("<= element_handle.focus failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.focus()) async def type( self, @@ -2161,18 +1777,11 @@ async def type( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.type started") - result = mapping.from_maybe_impl( - await self._impl_obj.type( - text=text, delay=delay, timeout=timeout, noWaitAfter=no_wait_after - ) + return mapping.from_maybe_impl( + await self._impl_obj.type( + text=text, delay=delay, timeout=timeout, noWaitAfter=no_wait_after ) - log_api("<= element_handle.type succeded") - return result - except Exception as e: - log_api("<= element_handle.type failed") - raise e + ) async def press( self, @@ -2218,18 +1827,11 @@ async def press( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.press started") - result = mapping.from_maybe_impl( - await self._impl_obj.press( - key=key, delay=delay, timeout=timeout, noWaitAfter=no_wait_after - ) + return mapping.from_maybe_impl( + await self._impl_obj.press( + key=key, delay=delay, timeout=timeout, noWaitAfter=no_wait_after ) - log_api("<= element_handle.press succeded") - return result - except Exception as e: - log_api("<= element_handle.press failed") - raise e + ) async def check( self, *, timeout: float = None, force: bool = None, no_wait_after: bool = None @@ -2263,18 +1865,11 @@ async def check( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.check started") - result = mapping.from_maybe_impl( - await self._impl_obj.check( - timeout=timeout, force=force, noWaitAfter=no_wait_after - ) + return mapping.from_maybe_impl( + await self._impl_obj.check( + timeout=timeout, force=force, noWaitAfter=no_wait_after ) - log_api("<= element_handle.check succeded") - return result - except Exception as e: - log_api("<= element_handle.check failed") - raise e + ) async def uncheck( self, *, timeout: float = None, force: bool = None, no_wait_after: bool = None @@ -2308,18 +1903,11 @@ async def uncheck( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.uncheck started") - result = mapping.from_maybe_impl( - await self._impl_obj.uncheck( - timeout=timeout, force=force, noWaitAfter=no_wait_after - ) + return mapping.from_maybe_impl( + await self._impl_obj.uncheck( + timeout=timeout, force=force, noWaitAfter=no_wait_after ) - log_api("<= element_handle.uncheck succeded") - return result - except Exception as e: - log_api("<= element_handle.uncheck failed") - raise e + ) async def bounding_box(self) -> typing.Union[FloatRect, NoneType]: """ElementHandle.bounding_box @@ -2347,14 +1935,7 @@ async def bounding_box(self) -> typing.Union[FloatRect, NoneType]: Union[{x: float, y: float, width: float, height: float}, NoneType] """ - try: - log_api("=> element_handle.bounding_box started") - result = mapping.from_impl_nullable(await self._impl_obj.bounding_box()) - log_api("<= element_handle.bounding_box succeded") - return result - except Exception as e: - log_api("<= element_handle.bounding_box failed") - raise e + return mapping.from_impl_nullable(await self._impl_obj.bounding_box()) async def screenshot( self, @@ -2394,22 +1975,15 @@ async def screenshot( bytes """ - try: - log_api("=> element_handle.screenshot started") - result = mapping.from_maybe_impl( - await self._impl_obj.screenshot( - timeout=timeout, - type=type, - path=path, - quality=quality, - omitBackground=omit_background, - ) + return mapping.from_maybe_impl( + await self._impl_obj.screenshot( + timeout=timeout, + type=type, + path=path, + quality=quality, + omitBackground=omit_background, ) - log_api("<= element_handle.screenshot succeded") - return result - except Exception as e: - log_api("<= element_handle.screenshot failed") - raise e + ) async def query_selector( self, selector: str @@ -2429,16 +2003,9 @@ async def query_selector( Union[ElementHandle, NoneType] """ - try: - log_api("=> element_handle.query_selector started") - result = mapping.from_impl_nullable( - await self._impl_obj.query_selector(selector=selector) - ) - log_api("<= element_handle.query_selector succeded") - return result - except Exception as e: - log_api("<= element_handle.query_selector failed") - raise e + return mapping.from_impl_nullable( + await self._impl_obj.query_selector(selector=selector) + ) async def query_selector_all(self, selector: str) -> typing.List["ElementHandle"]: """ElementHandle.query_selector_all @@ -2456,16 +2023,9 @@ async def query_selector_all(self, selector: str) -> typing.List["ElementHandle" List[ElementHandle] """ - try: - log_api("=> element_handle.query_selector_all started") - result = mapping.from_impl_list( - await self._impl_obj.query_selector_all(selector=selector) - ) - log_api("<= element_handle.query_selector_all succeded") - return result - except Exception as e: - log_api("<= element_handle.query_selector_all failed") - raise e + return mapping.from_impl_list( + await self._impl_obj.query_selector_all(selector=selector) + ) async def eval_on_selector( self, selector: str, expression: str, arg: typing.Any = None @@ -2497,25 +2057,18 @@ async def eval_on_selector( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> element_handle.eval_on_selector started") - result = mapping.from_maybe_impl( - await self._impl_obj.eval_on_selector( - selector=selector, expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_maybe_impl( + await self._impl_obj.eval_on_selector( + selector=selector, expression=expression, arg=mapping.to_impl(arg) ) - log_api("<= element_handle.eval_on_selector succeded") - return result - except Exception as e: - log_api("<= element_handle.eval_on_selector failed") - raise e + ) async def eval_on_selector_all( self, selector: str, expression: str, arg: typing.Any = None @@ -2552,25 +2105,18 @@ async def eval_on_selector_all( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> element_handle.eval_on_selector_all started") - result = mapping.from_maybe_impl( - await self._impl_obj.eval_on_selector_all( - selector=selector, expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_maybe_impl( + await self._impl_obj.eval_on_selector_all( + selector=selector, expression=expression, arg=mapping.to_impl(arg) ) - log_api("<= element_handle.eval_on_selector_all succeded") - return result - except Exception as e: - log_api("<= element_handle.eval_on_selector_all failed") - raise e + ) async def wait_for_element_state( self, @@ -2606,18 +2152,9 @@ async def wait_for_element_state( using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ - try: - log_api("=> element_handle.wait_for_element_state started") - result = mapping.from_maybe_impl( - await self._impl_obj.wait_for_element_state( - state=state, timeout=timeout - ) - ) - log_api("<= element_handle.wait_for_element_state succeded") - return result - except Exception as e: - log_api("<= element_handle.wait_for_element_state failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.wait_for_element_state(state=state, timeout=timeout) + ) async def wait_for_selector( self, @@ -2666,18 +2203,11 @@ async def wait_for_selector( Union[ElementHandle, NoneType] """ - try: - log_api("=> element_handle.wait_for_selector started") - result = mapping.from_impl_nullable( - await self._impl_obj.wait_for_selector( - selector=selector, state=state, timeout=timeout - ) + return mapping.from_impl_nullable( + await self._impl_obj.wait_for_selector( + selector=selector, state=state, timeout=timeout ) - log_api("<= element_handle.wait_for_selector succeded") - return result - except Exception as e: - log_api("<= element_handle.wait_for_selector failed") - raise e + ) mapping.register(ElementHandleImpl, ElementHandle) @@ -2734,18 +2264,11 @@ def find_focused_node(node): Union[Dict, NoneType] """ - try: - log_api("=> accessibility.snapshot started") - result = mapping.from_maybe_impl( - await self._impl_obj.snapshot( - interestingOnly=interesting_only, root=mapping.to_impl(root) - ) + return mapping.from_maybe_impl( + await self._impl_obj.snapshot( + interestingOnly=interesting_only, root=mapping.to_impl(root) ) - log_api("<= accessibility.snapshot succeded") - return result - except Exception as e: - log_api("<= accessibility.snapshot failed") - raise e + ) mapping.register(AccessibilityImpl, Accessibility) @@ -2789,14 +2312,7 @@ def is_multiple(self) -> bool: bool """ - try: - log_api("=> file_chooser.is_multiple started") - result = mapping.from_maybe_impl(self._impl_obj.is_multiple()) - log_api("<= file_chooser.is_multiple succeded") - return result - except Exception as e: - log_api("<= file_chooser.is_multiple failed") - raise e + return mapping.from_maybe_impl(self._impl_obj.is_multiple()) async def set_files( self, @@ -2828,18 +2344,11 @@ async def set_files( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> file_chooser.set_files started") - result = mapping.from_maybe_impl( - await self._impl_obj.set_files( - files=files, timeout=timeout, noWaitAfter=no_wait_after - ) + return mapping.from_maybe_impl( + await self._impl_obj.set_files( + files=files, timeout=timeout, noWaitAfter=no_wait_after ) - log_api("<= file_chooser.set_files succeded") - return result - except Exception as e: - log_api("<= file_chooser.set_files failed") - raise e + ) mapping.register(FileChooserImpl, FileChooser) @@ -2963,18 +2472,11 @@ async def goto( Union[Response, NoneType] """ - try: - log_api("=> frame.goto started") - result = mapping.from_impl_nullable( - await self._impl_obj.goto( - url=url, timeout=timeout, waitUntil=wait_until, referer=referer - ) + return mapping.from_impl_nullable( + await self._impl_obj.goto( + url=url, timeout=timeout, waitUntil=wait_until, referer=referer ) - log_api("<= frame.goto succeded") - return result - except Exception as e: - log_api("<= frame.goto failed") - raise e + ) def expect_navigation( self, @@ -3060,16 +2562,9 @@ async def wait_for_load_state( `page.set_default_timeout()` methods. """ - try: - log_api("=> frame.wait_for_load_state started") - result = mapping.from_maybe_impl( - await self._impl_obj.wait_for_load_state(state=state, timeout=timeout) - ) - log_api("<= frame.wait_for_load_state succeded") - return result - except Exception as e: - log_api("<= frame.wait_for_load_state failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.wait_for_load_state(state=state, timeout=timeout) + ) async def frame_element(self) -> "ElementHandle": """Frame.frame_element @@ -3092,14 +2587,7 @@ async def frame_element(self) -> "ElementHandle": ElementHandle """ - try: - log_api("=> frame.frame_element started") - result = mapping.from_impl(await self._impl_obj.frame_element()) - log_api("<= frame.frame_element succeded") - return result - except Exception as e: - log_api("<= frame.frame_element failed") - raise e + return mapping.from_impl(await self._impl_obj.frame_element()) async def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any: """Frame.evaluate @@ -3140,25 +2628,18 @@ async def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any: JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> frame.evaluate started") - result = mapping.from_maybe_impl( - await self._impl_obj.evaluate( - expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_maybe_impl( + await self._impl_obj.evaluate( + expression=expression, arg=mapping.to_impl(arg) ) - log_api("<= frame.evaluate succeded") - return result - except Exception as e: - log_api("<= frame.evaluate failed") - raise e + ) async def evaluate_handle( self, expression: str, arg: typing.Any = None @@ -3199,25 +2680,18 @@ async def evaluate_handle( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- JSHandle """ - try: - log_api("=> frame.evaluate_handle started") - result = mapping.from_impl( - await self._impl_obj.evaluate_handle( - expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_impl( + await self._impl_obj.evaluate_handle( + expression=expression, arg=mapping.to_impl(arg) ) - log_api("<= frame.evaluate_handle succeded") - return result - except Exception as e: - log_api("<= frame.evaluate_handle failed") - raise e + ) async def query_selector( self, selector: str @@ -3239,16 +2713,9 @@ async def query_selector( Union[ElementHandle, NoneType] """ - try: - log_api("=> frame.query_selector started") - result = mapping.from_impl_nullable( - await self._impl_obj.query_selector(selector=selector) - ) - log_api("<= frame.query_selector succeded") - return result - except Exception as e: - log_api("<= frame.query_selector failed") - raise e + return mapping.from_impl_nullable( + await self._impl_obj.query_selector(selector=selector) + ) async def query_selector_all(self, selector: str) -> typing.List["ElementHandle"]: """Frame.query_selector_all @@ -3268,16 +2735,9 @@ async def query_selector_all(self, selector: str) -> typing.List["ElementHandle" List[ElementHandle] """ - try: - log_api("=> frame.query_selector_all started") - result = mapping.from_impl_list( - await self._impl_obj.query_selector_all(selector=selector) - ) - log_api("<= frame.query_selector_all succeded") - return result - except Exception as e: - log_api("<= frame.query_selector_all failed") - raise e + return mapping.from_impl_list( + await self._impl_obj.query_selector_all(selector=selector) + ) async def wait_for_selector( self, @@ -3338,18 +2798,11 @@ async def main(): Union[ElementHandle, NoneType] """ - try: - log_api("=> frame.wait_for_selector started") - result = mapping.from_impl_nullable( - await self._impl_obj.wait_for_selector( - selector=selector, timeout=timeout, state=state - ) + return mapping.from_impl_nullable( + await self._impl_obj.wait_for_selector( + selector=selector, timeout=timeout, state=state ) - log_api("<= frame.wait_for_selector succeded") - return result - except Exception as e: - log_api("<= frame.wait_for_selector failed") - raise e + ) async def is_checked(self, selector: str, *, timeout: float = None) -> bool: """Frame.is_checked @@ -3370,16 +2823,9 @@ async def is_checked(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> frame.is_checked started") - result = mapping.from_maybe_impl( - await self._impl_obj.is_checked(selector=selector, timeout=timeout) - ) - log_api("<= frame.is_checked succeded") - return result - except Exception as e: - log_api("<= frame.is_checked failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.is_checked(selector=selector, timeout=timeout) + ) async def is_disabled(self, selector: str, *, timeout: float = None) -> bool: """Frame.is_disabled @@ -3400,16 +2846,9 @@ async def is_disabled(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> frame.is_disabled started") - result = mapping.from_maybe_impl( - await self._impl_obj.is_disabled(selector=selector, timeout=timeout) - ) - log_api("<= frame.is_disabled succeded") - return result - except Exception as e: - log_api("<= frame.is_disabled failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.is_disabled(selector=selector, timeout=timeout) + ) async def is_editable(self, selector: str, *, timeout: float = None) -> bool: """Frame.is_editable @@ -3430,16 +2869,9 @@ async def is_editable(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> frame.is_editable started") - result = mapping.from_maybe_impl( - await self._impl_obj.is_editable(selector=selector, timeout=timeout) - ) - log_api("<= frame.is_editable succeded") - return result - except Exception as e: - log_api("<= frame.is_editable failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.is_editable(selector=selector, timeout=timeout) + ) async def is_enabled(self, selector: str, *, timeout: float = None) -> bool: """Frame.is_enabled @@ -3460,21 +2892,15 @@ async def is_enabled(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> frame.is_enabled started") - result = mapping.from_maybe_impl( - await self._impl_obj.is_enabled(selector=selector, timeout=timeout) - ) - log_api("<= frame.is_enabled succeded") - return result - except Exception as e: - log_api("<= frame.is_enabled failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.is_enabled(selector=selector, timeout=timeout) + ) async def is_hidden(self, selector: str, *, timeout: float = None) -> bool: """Frame.is_hidden - Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). + Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). `selector` that does not + match any elements is considered hidden. Parameters ---------- @@ -3490,21 +2916,15 @@ async def is_hidden(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> frame.is_hidden started") - result = mapping.from_maybe_impl( - await self._impl_obj.is_hidden(selector=selector, timeout=timeout) - ) - log_api("<= frame.is_hidden succeded") - return result - except Exception as e: - log_api("<= frame.is_hidden failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.is_hidden(selector=selector, timeout=timeout) + ) async def is_visible(self, selector: str, *, timeout: float = None) -> bool: """Frame.is_visible - Returns whether the element is [visible](./actionability.md#visible). + Returns whether the element is [visible](./actionability.md#visible). `selector` that does not match any elements is + considered not visible. Parameters ---------- @@ -3520,16 +2940,9 @@ async def is_visible(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> frame.is_visible started") - result = mapping.from_maybe_impl( - await self._impl_obj.is_visible(selector=selector, timeout=timeout) - ) - log_api("<= frame.is_visible succeded") - return result - except Exception as e: - log_api("<= frame.is_visible failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.is_visible(selector=selector, timeout=timeout) + ) async def dispatch_event( self, @@ -3583,21 +2996,14 @@ async def dispatch_event( using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ - try: - log_api("=> frame.dispatch_event started") - result = mapping.from_maybe_impl( - await self._impl_obj.dispatch_event( - selector=selector, - type=type, - eventInit=mapping.to_impl(event_init), - timeout=timeout, - ) + return mapping.from_maybe_impl( + await self._impl_obj.dispatch_event( + selector=selector, + type=type, + eventInit=mapping.to_impl(event_init), + timeout=timeout, ) - log_api("<= frame.dispatch_event succeded") - return result - except Exception as e: - log_api("<= frame.dispatch_event failed") - raise e + ) async def eval_on_selector( self, selector: str, expression: str, arg: typing.Any = None @@ -3629,25 +3035,18 @@ async def eval_on_selector( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> frame.eval_on_selector started") - result = mapping.from_maybe_impl( - await self._impl_obj.eval_on_selector( - selector=selector, expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_maybe_impl( + await self._impl_obj.eval_on_selector( + selector=selector, expression=expression, arg=mapping.to_impl(arg) ) - log_api("<= frame.eval_on_selector succeded") - return result - except Exception as e: - log_api("<= frame.eval_on_selector failed") - raise e + ) async def eval_on_selector_all( self, selector: str, expression: str, arg: typing.Any = None @@ -3676,25 +3075,18 @@ async def eval_on_selector_all( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> frame.eval_on_selector_all started") - result = mapping.from_maybe_impl( - await self._impl_obj.eval_on_selector_all( - selector=selector, expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_maybe_impl( + await self._impl_obj.eval_on_selector_all( + selector=selector, expression=expression, arg=mapping.to_impl(arg) ) - log_api("<= frame.eval_on_selector_all succeded") - return result - except Exception as e: - log_api("<= frame.eval_on_selector_all failed") - raise e + ) async def content(self) -> str: """Frame.content @@ -3706,14 +3098,7 @@ async def content(self) -> str: str """ - try: - log_api("=> frame.content started") - result = mapping.from_maybe_impl(await self._impl_obj.content()) - log_api("<= frame.content succeded") - return result - except Exception as e: - log_api("<= frame.content failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.content()) async def set_content( self, @@ -3740,18 +3125,11 @@ async def set_content( - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. """ - try: - log_api("=> frame.set_content started") - result = mapping.from_maybe_impl( - await self._impl_obj.set_content( - html=html, timeout=timeout, waitUntil=wait_until - ) + return mapping.from_maybe_impl( + await self._impl_obj.set_content( + html=html, timeout=timeout, waitUntil=wait_until ) - log_api("<= frame.set_content succeded") - return result - except Exception as e: - log_api("<= frame.set_content failed") - raise e + ) def is_detached(self) -> bool: """Frame.is_detached @@ -3763,14 +3141,7 @@ def is_detached(self) -> bool: bool """ - try: - log_api("=> frame.is_detached started") - result = mapping.from_maybe_impl(self._impl_obj.is_detached()) - log_api("<= frame.is_detached succeded") - return result - except Exception as e: - log_api("<= frame.is_detached failed") - raise e + return mapping.from_maybe_impl(self._impl_obj.is_detached()) async def add_script_tag( self, @@ -3804,18 +3175,11 @@ async def add_script_tag( ElementHandle """ - try: - log_api("=> frame.add_script_tag started") - result = mapping.from_impl( - await self._impl_obj.add_script_tag( - url=url, path=path, content=content, type=type - ) + return mapping.from_impl( + await self._impl_obj.add_script_tag( + url=url, path=path, content=content, type=type ) - log_api("<= frame.add_script_tag succeded") - return result - except Exception as e: - log_api("<= frame.add_script_tag failed") - raise e + ) async def add_style_tag( self, @@ -3846,16 +3210,9 @@ async def add_style_tag( ElementHandle """ - try: - log_api("=> frame.add_style_tag started") - result = mapping.from_impl( - await self._impl_obj.add_style_tag(url=url, path=path, content=content) - ) - log_api("<= frame.add_style_tag succeded") - return result - except Exception as e: - log_api("<= frame.add_style_tag failed") - raise e + return mapping.from_impl( + await self._impl_obj.add_style_tag(url=url, path=path, content=content) + ) async def click( self, @@ -3913,26 +3270,19 @@ async def click( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.click started") - result = mapping.from_maybe_impl( - await self._impl_obj.click( - selector=selector, - modifiers=modifiers, - position=position, - delay=delay, - button=button, - clickCount=click_count, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.click( + selector=selector, + modifiers=modifiers, + position=position, + delay=delay, + button=button, + clickCount=click_count, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) - log_api("<= frame.click succeded") - return result - except Exception as e: - log_api("<= frame.click failed") - raise e + ) async def dblclick( self, @@ -3990,25 +3340,18 @@ async def dblclick( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.dblclick started") - result = mapping.from_maybe_impl( - await self._impl_obj.dblclick( - selector=selector, - modifiers=modifiers, - position=position, - delay=delay, - button=button, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.dblclick( + selector=selector, + modifiers=modifiers, + position=position, + delay=delay, + button=button, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) - log_api("<= frame.dblclick succeded") - return result - except Exception as e: - log_api("<= frame.dblclick failed") - raise e + ) async def tap( self, @@ -4059,23 +3402,16 @@ async def tap( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.tap started") - result = mapping.from_maybe_impl( - await self._impl_obj.tap( - selector=selector, - modifiers=modifiers, - position=position, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.tap( + selector=selector, + modifiers=modifiers, + position=position, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) - log_api("<= frame.tap succeded") - return result - except Exception as e: - log_api("<= frame.tap failed") - raise e + ) async def fill( self, @@ -4111,21 +3447,14 @@ async def fill( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.fill started") - result = mapping.from_maybe_impl( - await self._impl_obj.fill( - selector=selector, - value=value, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.fill( + selector=selector, + value=value, + timeout=timeout, + noWaitAfter=no_wait_after, ) - log_api("<= frame.fill succeded") - return result - except Exception as e: - log_api("<= frame.fill failed") - raise e + ) async def focus(self, selector: str, *, timeout: float = None) -> NoneType: """Frame.focus @@ -4143,16 +3472,9 @@ async def focus(self, selector: str, *, timeout: float = None) -> NoneType: using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ - try: - log_api("=> frame.focus started") - result = mapping.from_maybe_impl( - await self._impl_obj.focus(selector=selector, timeout=timeout) - ) - log_api("<= frame.focus succeded") - return result - except Exception as e: - log_api("<= frame.focus failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.focus(selector=selector, timeout=timeout) + ) async def text_content( self, selector: str, *, timeout: float = None @@ -4175,16 +3497,9 @@ async def text_content( Union[str, NoneType] """ - try: - log_api("=> frame.text_content started") - result = mapping.from_maybe_impl( - await self._impl_obj.text_content(selector=selector, timeout=timeout) - ) - log_api("<= frame.text_content succeded") - return result - except Exception as e: - log_api("<= frame.text_content failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.text_content(selector=selector, timeout=timeout) + ) async def inner_text(self, selector: str, *, timeout: float = None) -> str: """Frame.inner_text @@ -4205,16 +3520,9 @@ async def inner_text(self, selector: str, *, timeout: float = None) -> str: str """ - try: - log_api("=> frame.inner_text started") - result = mapping.from_maybe_impl( - await self._impl_obj.inner_text(selector=selector, timeout=timeout) - ) - log_api("<= frame.inner_text succeded") - return result - except Exception as e: - log_api("<= frame.inner_text failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.inner_text(selector=selector, timeout=timeout) + ) async def inner_html(self, selector: str, *, timeout: float = None) -> str: """Frame.inner_html @@ -4235,16 +3543,9 @@ async def inner_html(self, selector: str, *, timeout: float = None) -> str: str """ - try: - log_api("=> frame.inner_html started") - result = mapping.from_maybe_impl( - await self._impl_obj.inner_html(selector=selector, timeout=timeout) - ) - log_api("<= frame.inner_html succeded") - return result - except Exception as e: - log_api("<= frame.inner_html failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.inner_html(selector=selector, timeout=timeout) + ) async def get_attribute( self, selector: str, name: str, *, timeout: float = None @@ -4269,18 +3570,11 @@ async def get_attribute( Union[str, NoneType] """ - try: - log_api("=> frame.get_attribute started") - result = mapping.from_maybe_impl( - await self._impl_obj.get_attribute( - selector=selector, name=name, timeout=timeout - ) + return mapping.from_maybe_impl( + await self._impl_obj.get_attribute( + selector=selector, name=name, timeout=timeout ) - log_api("<= frame.get_attribute succeded") - return result - except Exception as e: - log_api("<= frame.get_attribute failed") - raise e + ) async def hover( self, @@ -4324,22 +3618,15 @@ async def hover( Whether to bypass the [actionability](./actionability.md) checks. Defaults to `false`. """ - try: - log_api("=> frame.hover started") - result = mapping.from_maybe_impl( - await self._impl_obj.hover( - selector=selector, - modifiers=modifiers, - position=position, - timeout=timeout, - force=force, - ) + return mapping.from_maybe_impl( + await self._impl_obj.hover( + selector=selector, + modifiers=modifiers, + position=position, + timeout=timeout, + force=force, ) - log_api("<= frame.hover succeded") - return result - except Exception as e: - log_api("<= frame.hover failed") - raise e + ) async def select_option( self, @@ -4397,24 +3684,17 @@ async def select_option( List[str] """ - try: - log_api("=> frame.select_option started") - result = mapping.from_maybe_impl( - await self._impl_obj.select_option( - selector=selector, - value=value, - index=index, - label=label, - element=mapping.to_impl(element), - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.select_option( + selector=selector, + value=value, + index=index, + label=label, + element=mapping.to_impl(element), + timeout=timeout, + noWaitAfter=no_wait_after, ) - log_api("<= frame.select_option succeded") - return result - except Exception as e: - log_api("<= frame.select_option failed") - raise e + ) async def set_input_files( self, @@ -4453,21 +3733,14 @@ async def set_input_files( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.set_input_files started") - result = mapping.from_maybe_impl( - await self._impl_obj.set_input_files( - selector=selector, - files=files, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.set_input_files( + selector=selector, + files=files, + timeout=timeout, + noWaitAfter=no_wait_after, ) - log_api("<= frame.set_input_files succeded") - return result - except Exception as e: - log_api("<= frame.set_input_files failed") - raise e + ) async def type( self, @@ -4508,22 +3781,15 @@ async def type( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.type started") - result = mapping.from_maybe_impl( - await self._impl_obj.type( - selector=selector, - text=text, - delay=delay, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.type( + selector=selector, + text=text, + delay=delay, + timeout=timeout, + noWaitAfter=no_wait_after, ) - log_api("<= frame.type succeded") - return result - except Exception as e: - log_api("<= frame.type failed") - raise e + ) async def press( self, @@ -4571,22 +3837,15 @@ async def press( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.press started") - result = mapping.from_maybe_impl( - await self._impl_obj.press( - selector=selector, - key=key, - delay=delay, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.press( + selector=selector, + key=key, + delay=delay, + timeout=timeout, + noWaitAfter=no_wait_after, ) - log_api("<= frame.press succeded") - return result - except Exception as e: - log_api("<= frame.press failed") - raise e + ) async def check( self, @@ -4628,21 +3887,14 @@ async def check( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.check started") - result = mapping.from_maybe_impl( - await self._impl_obj.check( - selector=selector, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.check( + selector=selector, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) - log_api("<= frame.check succeded") - return result - except Exception as e: - log_api("<= frame.check failed") - raise e + ) async def uncheck( self, @@ -4684,21 +3936,14 @@ async def uncheck( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.uncheck started") - result = mapping.from_maybe_impl( - await self._impl_obj.uncheck( - selector=selector, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.uncheck( + selector=selector, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) - log_api("<= frame.uncheck succeded") - return result - except Exception as e: - log_api("<= frame.uncheck failed") - raise e + ) async def wait_for_timeout(self, timeout: float) -> NoneType: """Frame.wait_for_timeout @@ -4714,16 +3959,9 @@ async def wait_for_timeout(self, timeout: float) -> NoneType: A timeout to wait for """ - try: - log_api("=> frame.wait_for_timeout started") - result = mapping.from_maybe_impl( - await self._impl_obj.wait_for_timeout(timeout=timeout) - ) - log_api("<= frame.wait_for_timeout succeded") - return result - except Exception as e: - log_api("<= frame.wait_for_timeout failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.wait_for_timeout(timeout=timeout) + ) async def wait_for_function( self, @@ -4770,7 +4008,7 @@ async def main(): JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. timeout : Union[float, NoneType] maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_timeout()`. @@ -4783,21 +4021,14 @@ async def main(): JSHandle """ - try: - log_api("=> frame.wait_for_function started") - result = mapping.from_impl( - await self._impl_obj.wait_for_function( - expression=expression, - arg=mapping.to_impl(arg), - timeout=timeout, - polling=polling, - ) + return mapping.from_impl( + await self._impl_obj.wait_for_function( + expression=expression, + arg=mapping.to_impl(arg), + timeout=timeout, + polling=polling, ) - log_api("<= frame.wait_for_function succeded") - return result - except Exception as e: - log_api("<= frame.wait_for_function failed") - raise e + ) async def title(self) -> str: """Frame.title @@ -4809,14 +4040,7 @@ async def title(self) -> str: str """ - try: - log_api("=> frame.title started") - result = mapping.from_maybe_impl(await self._impl_obj.title()) - log_api("<= frame.title succeded") - return result - except Exception as e: - log_api("<= frame.title failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.title()) mapping.register(FrameImpl, Frame) @@ -4854,25 +4078,18 @@ async def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any: JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> worker.evaluate started") - result = mapping.from_maybe_impl( - await self._impl_obj.evaluate( - expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_maybe_impl( + await self._impl_obj.evaluate( + expression=expression, arg=mapping.to_impl(arg) ) - log_api("<= worker.evaluate succeded") - return result - except Exception as e: - log_api("<= worker.evaluate failed") - raise e + ) async def evaluate_handle( self, expression: str, arg: typing.Any = None @@ -4893,25 +4110,18 @@ async def evaluate_handle( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- JSHandle """ - try: - log_api("=> worker.evaluate_handle started") - result = mapping.from_impl( - await self._impl_obj.evaluate_handle( - expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_impl( + await self._impl_obj.evaluate_handle( + expression=expression, arg=mapping.to_impl(arg) ) - log_api("<= worker.evaluate_handle succeded") - return result - except Exception as e: - log_api("<= worker.evaluate_handle failed") - raise e + ) mapping.register(WorkerImpl, Worker) @@ -4953,18 +4163,11 @@ async def register( guaranteed when this engine is used together with other registered engines. """ - try: - log_api("=> selectors.register started") - result = mapping.from_maybe_impl( - await self._impl_obj.register( - name=name, script=script, path=path, contentScript=content_script - ) + return mapping.from_maybe_impl( + await self._impl_obj.register( + name=name, script=script, path=path, contentScript=content_script ) - log_api("<= selectors.register succeded") - return result - except Exception as e: - log_api("<= selectors.register failed") - raise e + ) mapping.register(SelectorsImpl, Selectors) @@ -5073,16 +4276,9 @@ async def accept(self, prompt_text: str = None) -> NoneType: A text to enter in prompt. Does not cause any effects if the dialog's `type` is not prompt. Optional. """ - try: - log_api("=> dialog.accept started") - result = mapping.from_maybe_impl( - await self._impl_obj.accept(promptText=prompt_text) - ) - log_api("<= dialog.accept succeded") - return result - except Exception as e: - log_api("<= dialog.accept failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.accept(promptText=prompt_text) + ) async def dismiss(self) -> NoneType: """Dialog.dismiss @@ -5090,14 +4286,7 @@ async def dismiss(self) -> NoneType: Returns when the dialog has been dismissed. """ - try: - log_api("=> dialog.dismiss started") - result = mapping.from_maybe_impl(await self._impl_obj.dismiss()) - log_api("<= dialog.dismiss succeded") - return result - except Exception as e: - log_api("<= dialog.dismiss failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.dismiss()) mapping.register(DialogImpl, Dialog) @@ -5140,14 +4329,7 @@ async def delete(self) -> NoneType: Deletes the downloaded file. """ - try: - log_api("=> download.delete started") - result = mapping.from_maybe_impl(await self._impl_obj.delete()) - log_api("<= download.delete succeded") - return result - except Exception as e: - log_api("<= download.delete failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.delete()) async def failure(self) -> typing.Union[str, NoneType]: """Download.failure @@ -5159,14 +4341,7 @@ async def failure(self) -> typing.Union[str, NoneType]: Union[str, NoneType] """ - try: - log_api("=> download.failure started") - result = mapping.from_maybe_impl(await self._impl_obj.failure()) - log_api("<= download.failure succeded") - return result - except Exception as e: - log_api("<= download.failure failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.failure()) async def path(self) -> typing.Union[pathlib.Path, NoneType]: """Download.path @@ -5178,14 +4353,7 @@ async def path(self) -> typing.Union[pathlib.Path, NoneType]: Union[pathlib.Path, NoneType] """ - try: - log_api("=> download.path started") - result = mapping.from_maybe_impl(await self._impl_obj.path()) - log_api("<= download.path succeded") - return result - except Exception as e: - log_api("<= download.path failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.path()) async def save_as(self, path: typing.Union[str, pathlib.Path]) -> NoneType: """Download.save_as @@ -5198,14 +4366,7 @@ async def save_as(self, path: typing.Union[str, pathlib.Path]) -> NoneType: Path where the download should be saved. """ - try: - log_api("=> download.save_as started") - result = mapping.from_maybe_impl(await self._impl_obj.save_as(path=path)) - log_api("<= download.save_as succeded") - return result - except Exception as e: - log_api("<= download.save_as failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.save_as(path=path)) mapping.register(DownloadImpl, Download) @@ -5226,14 +4387,7 @@ async def path(self) -> pathlib.Path: pathlib.Path """ - try: - log_api("=> video.path started") - result = mapping.from_maybe_impl(await self._impl_obj.path()) - log_api("<= video.path succeded") - return result - except Exception as e: - log_api("<= video.path failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.path()) mapping.register(VideoImpl, Video) @@ -5378,14 +4532,7 @@ async def opener(self) -> typing.Union["Page", NoneType]: Union[Page, NoneType] """ - try: - log_api("=> page.opener started") - result = mapping.from_impl_nullable(await self._impl_obj.opener()) - log_api("<= page.opener succeded") - return result - except Exception as e: - log_api("<= page.opener failed") - raise e + return mapping.from_impl_nullable(await self._impl_obj.opener()) def frame( self, @@ -5417,16 +4564,9 @@ def frame( Union[Frame, NoneType] """ - try: - log_api("=> page.frame started") - result = mapping.from_impl_nullable( - self._impl_obj.frame(name=name, url=self._wrap_handler(url)) - ) - log_api("<= page.frame succeded") - return result - except Exception as e: - log_api("<= page.frame failed") - raise e + return mapping.from_impl_nullable( + self._impl_obj.frame(name=name, url=self._wrap_handler(url)) + ) def set_default_navigation_timeout(self, timeout: float) -> NoneType: """Page.set_default_navigation_timeout @@ -5448,16 +4588,9 @@ def set_default_navigation_timeout(self, timeout: float) -> NoneType: Maximum navigation time in milliseconds """ - try: - log_api("=> page.set_default_navigation_timeout started") - result = mapping.from_maybe_impl( - self._impl_obj.set_default_navigation_timeout(timeout=timeout) - ) - log_api("<= page.set_default_navigation_timeout succeded") - return result - except Exception as e: - log_api("<= page.set_default_navigation_timeout failed") - raise e + return mapping.from_maybe_impl( + self._impl_obj.set_default_navigation_timeout(timeout=timeout) + ) def set_default_timeout(self, timeout: float) -> NoneType: """Page.set_default_timeout @@ -5472,16 +4605,9 @@ def set_default_timeout(self, timeout: float) -> NoneType: Maximum time in milliseconds """ - try: - log_api("=> page.set_default_timeout started") - result = mapping.from_maybe_impl( - self._impl_obj.set_default_timeout(timeout=timeout) - ) - log_api("<= page.set_default_timeout succeded") - return result - except Exception as e: - log_api("<= page.set_default_timeout failed") - raise e + return mapping.from_maybe_impl( + self._impl_obj.set_default_timeout(timeout=timeout) + ) async def query_selector( self, selector: str @@ -5503,16 +4629,9 @@ async def query_selector( Union[ElementHandle, NoneType] """ - try: - log_api("=> page.query_selector started") - result = mapping.from_impl_nullable( - await self._impl_obj.query_selector(selector=selector) - ) - log_api("<= page.query_selector succeded") - return result - except Exception as e: - log_api("<= page.query_selector failed") - raise e + return mapping.from_impl_nullable( + await self._impl_obj.query_selector(selector=selector) + ) async def query_selector_all(self, selector: str) -> typing.List["ElementHandle"]: """Page.query_selector_all @@ -5532,16 +4651,9 @@ async def query_selector_all(self, selector: str) -> typing.List["ElementHandle" List[ElementHandle] """ - try: - log_api("=> page.query_selector_all started") - result = mapping.from_impl_list( - await self._impl_obj.query_selector_all(selector=selector) - ) - log_api("<= page.query_selector_all succeded") - return result - except Exception as e: - log_api("<= page.query_selector_all failed") - raise e + return mapping.from_impl_list( + await self._impl_obj.query_selector_all(selector=selector) + ) async def wait_for_selector( self, @@ -5602,18 +4714,11 @@ async def main(): Union[ElementHandle, NoneType] """ - try: - log_api("=> page.wait_for_selector started") - result = mapping.from_impl_nullable( - await self._impl_obj.wait_for_selector( - selector=selector, timeout=timeout, state=state - ) + return mapping.from_impl_nullable( + await self._impl_obj.wait_for_selector( + selector=selector, timeout=timeout, state=state ) - log_api("<= page.wait_for_selector succeded") - return result - except Exception as e: - log_api("<= page.wait_for_selector failed") - raise e + ) async def is_checked(self, selector: str, *, timeout: float = None) -> bool: """Page.is_checked @@ -5634,16 +4739,9 @@ async def is_checked(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> page.is_checked started") - result = mapping.from_maybe_impl( - await self._impl_obj.is_checked(selector=selector, timeout=timeout) - ) - log_api("<= page.is_checked succeded") - return result - except Exception as e: - log_api("<= page.is_checked failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.is_checked(selector=selector, timeout=timeout) + ) async def is_disabled(self, selector: str, *, timeout: float = None) -> bool: """Page.is_disabled @@ -5664,16 +4762,9 @@ async def is_disabled(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> page.is_disabled started") - result = mapping.from_maybe_impl( - await self._impl_obj.is_disabled(selector=selector, timeout=timeout) - ) - log_api("<= page.is_disabled succeded") - return result - except Exception as e: - log_api("<= page.is_disabled failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.is_disabled(selector=selector, timeout=timeout) + ) async def is_editable(self, selector: str, *, timeout: float = None) -> bool: """Page.is_editable @@ -5694,16 +4785,9 @@ async def is_editable(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> page.is_editable started") - result = mapping.from_maybe_impl( - await self._impl_obj.is_editable(selector=selector, timeout=timeout) - ) - log_api("<= page.is_editable succeded") - return result - except Exception as e: - log_api("<= page.is_editable failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.is_editable(selector=selector, timeout=timeout) + ) async def is_enabled(self, selector: str, *, timeout: float = None) -> bool: """Page.is_enabled @@ -5724,21 +4808,15 @@ async def is_enabled(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> page.is_enabled started") - result = mapping.from_maybe_impl( - await self._impl_obj.is_enabled(selector=selector, timeout=timeout) - ) - log_api("<= page.is_enabled succeded") - return result - except Exception as e: - log_api("<= page.is_enabled failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.is_enabled(selector=selector, timeout=timeout) + ) async def is_hidden(self, selector: str, *, timeout: float = None) -> bool: """Page.is_hidden - Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). + Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). `selector` that does not + match any elements is considered hidden. Parameters ---------- @@ -5754,21 +4832,15 @@ async def is_hidden(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> page.is_hidden started") - result = mapping.from_maybe_impl( - await self._impl_obj.is_hidden(selector=selector, timeout=timeout) - ) - log_api("<= page.is_hidden succeded") - return result - except Exception as e: - log_api("<= page.is_hidden failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.is_hidden(selector=selector, timeout=timeout) + ) async def is_visible(self, selector: str, *, timeout: float = None) -> bool: """Page.is_visible - Returns whether the element is [visible](./actionability.md#visible). + Returns whether the element is [visible](./actionability.md#visible). `selector` that does not match any elements is + considered not visible. Parameters ---------- @@ -5784,16 +4856,9 @@ async def is_visible(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> page.is_visible started") - result = mapping.from_maybe_impl( - await self._impl_obj.is_visible(selector=selector, timeout=timeout) - ) - log_api("<= page.is_visible succeded") - return result - except Exception as e: - log_api("<= page.is_visible failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.is_visible(selector=selector, timeout=timeout) + ) async def dispatch_event( self, @@ -5847,21 +4912,14 @@ async def dispatch_event( using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ - try: - log_api("=> page.dispatch_event started") - result = mapping.from_maybe_impl( - await self._impl_obj.dispatch_event( - selector=selector, - type=type, - eventInit=mapping.to_impl(event_init), - timeout=timeout, - ) + return mapping.from_maybe_impl( + await self._impl_obj.dispatch_event( + selector=selector, + type=type, + eventInit=mapping.to_impl(event_init), + timeout=timeout, ) - log_api("<= page.dispatch_event succeded") - return result - except Exception as e: - log_api("<= page.dispatch_event failed") - raise e + ) async def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any: """Page.evaluate @@ -5906,25 +4964,18 @@ async def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any: JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> page.evaluate started") - result = mapping.from_maybe_impl( - await self._impl_obj.evaluate( - expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_maybe_impl( + await self._impl_obj.evaluate( + expression=expression, arg=mapping.to_impl(arg) ) - log_api("<= page.evaluate succeded") - return result - except Exception as e: - log_api("<= page.evaluate failed") - raise e + ) async def evaluate_handle( self, expression: str, arg: typing.Any = None @@ -5965,25 +5016,18 @@ async def evaluate_handle( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- JSHandle """ - try: - log_api("=> page.evaluate_handle started") - result = mapping.from_impl( - await self._impl_obj.evaluate_handle( - expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_impl( + await self._impl_obj.evaluate_handle( + expression=expression, arg=mapping.to_impl(arg) ) - log_api("<= page.evaluate_handle succeded") - return result - except Exception as e: - log_api("<= page.evaluate_handle failed") - raise e + ) async def eval_on_selector( self, selector: str, expression: str, arg: typing.Any = None @@ -6014,25 +5058,18 @@ async def eval_on_selector( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> page.eval_on_selector started") - result = mapping.from_maybe_impl( - await self._impl_obj.eval_on_selector( - selector=selector, expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_maybe_impl( + await self._impl_obj.eval_on_selector( + selector=selector, expression=expression, arg=mapping.to_impl(arg) ) - log_api("<= page.eval_on_selector succeded") - return result - except Exception as e: - log_api("<= page.eval_on_selector failed") - raise e + ) async def eval_on_selector_all( self, selector: str, expression: str, arg: typing.Any = None @@ -6059,25 +5096,18 @@ async def eval_on_selector_all( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> page.eval_on_selector_all started") - result = mapping.from_maybe_impl( - await self._impl_obj.eval_on_selector_all( - selector=selector, expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_maybe_impl( + await self._impl_obj.eval_on_selector_all( + selector=selector, expression=expression, arg=mapping.to_impl(arg) ) - log_api("<= page.eval_on_selector_all succeded") - return result - except Exception as e: - log_api("<= page.eval_on_selector_all failed") - raise e + ) async def add_script_tag( self, @@ -6112,18 +5142,11 @@ async def add_script_tag( ElementHandle """ - try: - log_api("=> page.add_script_tag started") - result = mapping.from_impl( - await self._impl_obj.add_script_tag( - url=url, path=path, content=content, type=type - ) + return mapping.from_impl( + await self._impl_obj.add_script_tag( + url=url, path=path, content=content, type=type ) - log_api("<= page.add_script_tag succeded") - return result - except Exception as e: - log_api("<= page.add_script_tag failed") - raise e + ) async def add_style_tag( self, @@ -6154,16 +5177,9 @@ async def add_style_tag( ElementHandle """ - try: - log_api("=> page.add_style_tag started") - result = mapping.from_impl( - await self._impl_obj.add_style_tag(url=url, path=path, content=content) - ) - log_api("<= page.add_style_tag succeded") - return result - except Exception as e: - log_api("<= page.add_style_tag failed") - raise e + return mapping.from_impl( + await self._impl_obj.add_style_tag(url=url, path=path, content=content) + ) async def expose_function(self, name: str, callback: typing.Callable) -> NoneType: """Page.expose_function @@ -6219,18 +5235,11 @@ async def main(): Callback function which will be called in Playwright's context. """ - try: - log_api("=> page.expose_function started") - result = mapping.from_maybe_impl( - await self._impl_obj.expose_function( - name=name, callback=self._wrap_handler(callback) - ) + return mapping.from_maybe_impl( + await self._impl_obj.expose_function( + name=name, callback=self._wrap_handler(callback) ) - log_api("<= page.expose_function succeded") - return result - except Exception as e: - log_api("<= page.expose_function failed") - raise e + ) async def expose_binding( self, name: str, callback: typing.Callable, *, handle: bool = None @@ -6304,18 +5313,11 @@ async def print(source, element): supported. When passing by value, multiple arguments are supported. """ - try: - log_api("=> page.expose_binding started") - result = mapping.from_maybe_impl( - await self._impl_obj.expose_binding( - name=name, callback=self._wrap_handler(callback), handle=handle - ) + return mapping.from_maybe_impl( + await self._impl_obj.expose_binding( + name=name, callback=self._wrap_handler(callback), handle=handle ) - log_api("<= page.expose_binding succeded") - return result - except Exception as e: - log_api("<= page.expose_binding failed") - raise e + ) async def set_extra_http_headers(self, headers: typing.Dict[str, str]) -> NoneType: """Page.set_extra_http_headers @@ -6330,18 +5332,11 @@ async def set_extra_http_headers(self, headers: typing.Dict[str, str]) -> NoneTy An object containing additional HTTP headers to be sent with every request. All header values must be strings. """ - try: - log_api("=> page.set_extra_http_headers started") - result = mapping.from_maybe_impl( - await self._impl_obj.set_extra_http_headers( - headers=mapping.to_impl(headers) - ) + return mapping.from_maybe_impl( + await self._impl_obj.set_extra_http_headers( + headers=mapping.to_impl(headers) ) - log_api("<= page.set_extra_http_headers succeded") - return result - except Exception as e: - log_api("<= page.set_extra_http_headers failed") - raise e + ) async def content(self) -> str: """Page.content @@ -6353,14 +5348,7 @@ async def content(self) -> str: str """ - try: - log_api("=> page.content started") - result = mapping.from_maybe_impl(await self._impl_obj.content()) - log_api("<= page.content succeded") - return result - except Exception as e: - log_api("<= page.content failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.content()) async def set_content( self, @@ -6387,18 +5375,11 @@ async def set_content( - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. """ - try: - log_api("=> page.set_content started") - result = mapping.from_maybe_impl( - await self._impl_obj.set_content( - html=html, timeout=timeout, waitUntil=wait_until - ) + return mapping.from_maybe_impl( + await self._impl_obj.set_content( + html=html, timeout=timeout, waitUntil=wait_until ) - log_api("<= page.set_content succeded") - return result - except Exception as e: - log_api("<= page.set_content failed") - raise e + ) async def goto( self, @@ -6454,18 +5435,11 @@ async def goto( Union[Response, NoneType] """ - try: - log_api("=> page.goto started") - result = mapping.from_impl_nullable( - await self._impl_obj.goto( - url=url, timeout=timeout, waitUntil=wait_until, referer=referer - ) + return mapping.from_impl_nullable( + await self._impl_obj.goto( + url=url, timeout=timeout, waitUntil=wait_until, referer=referer ) - log_api("<= page.goto succeded") - return result - except Exception as e: - log_api("<= page.goto failed") - raise e + ) async def reload( self, @@ -6496,16 +5470,9 @@ async def reload( Union[Response, NoneType] """ - try: - log_api("=> page.reload started") - result = mapping.from_impl_nullable( - await self._impl_obj.reload(timeout=timeout, waitUntil=wait_until) - ) - log_api("<= page.reload succeded") - return result - except Exception as e: - log_api("<= page.reload failed") - raise e + return mapping.from_impl_nullable( + await self._impl_obj.reload(timeout=timeout, waitUntil=wait_until) + ) async def wait_for_load_state( self, @@ -6551,16 +5518,9 @@ async def wait_for_load_state( `page.set_default_timeout()` methods. """ - try: - log_api("=> page.wait_for_load_state started") - result = mapping.from_maybe_impl( - await self._impl_obj.wait_for_load_state(state=state, timeout=timeout) - ) - log_api("<= page.wait_for_load_state succeded") - return result - except Exception as e: - log_api("<= page.wait_for_load_state failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.wait_for_load_state(state=state, timeout=timeout) + ) async def wait_for_event( self, event: str, predicate: typing.Callable = None, *, timeout: float = None @@ -6588,20 +5548,11 @@ async def wait_for_event( Any """ - try: - log_api("=> page.wait_for_event started") - result = mapping.from_maybe_impl( - await self._impl_obj.wait_for_event( - event=event, - predicate=self._wrap_handler(predicate), - timeout=timeout, - ) + return mapping.from_maybe_impl( + await self._impl_obj.wait_for_event( + event=event, predicate=self._wrap_handler(predicate), timeout=timeout ) - log_api("<= page.wait_for_event succeded") - return result - except Exception as e: - log_api("<= page.wait_for_event failed") - raise e + ) async def go_back( self, @@ -6634,16 +5585,9 @@ async def go_back( Union[Response, NoneType] """ - try: - log_api("=> page.go_back started") - result = mapping.from_impl_nullable( - await self._impl_obj.go_back(timeout=timeout, waitUntil=wait_until) - ) - log_api("<= page.go_back succeded") - return result - except Exception as e: - log_api("<= page.go_back failed") - raise e + return mapping.from_impl_nullable( + await self._impl_obj.go_back(timeout=timeout, waitUntil=wait_until) + ) async def go_forward( self, @@ -6676,16 +5620,9 @@ async def go_forward( Union[Response, NoneType] """ - try: - log_api("=> page.go_forward started") - result = mapping.from_impl_nullable( - await self._impl_obj.go_forward(timeout=timeout, waitUntil=wait_until) - ) - log_api("<= page.go_forward succeded") - return result - except Exception as e: - log_api("<= page.go_forward failed") - raise e + return mapping.from_impl_nullable( + await self._impl_obj.go_forward(timeout=timeout, waitUntil=wait_until) + ) async def emulate_media( self, @@ -6734,18 +5671,9 @@ async def emulate_media( `null` disables color scheme emulation. """ - try: - log_api("=> page.emulate_media started") - result = mapping.from_maybe_impl( - await self._impl_obj.emulate_media( - media=media, colorScheme=color_scheme - ) - ) - log_api("<= page.emulate_media succeded") - return result - except Exception as e: - log_api("<= page.emulate_media failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.emulate_media(media=media, colorScheme=color_scheme) + ) async def set_viewport_size(self, viewport_size: ViewportSize) -> NoneType: """Page.set_viewport_size @@ -6767,16 +5695,9 @@ async def set_viewport_size(self, viewport_size: ViewportSize) -> NoneType: viewport_size : {width: int, height: int} """ - try: - log_api("=> page.set_viewport_size started") - result = mapping.from_maybe_impl( - await self._impl_obj.set_viewport_size(viewportSize=viewport_size) - ) - log_api("<= page.set_viewport_size succeded") - return result - except Exception as e: - log_api("<= page.set_viewport_size failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.set_viewport_size(viewportSize=viewport_size) + ) async def bring_to_front(self) -> NoneType: """Page.bring_to_front @@ -6784,14 +5705,7 @@ async def bring_to_front(self) -> NoneType: Brings page to front (activates tab). """ - try: - log_api("=> page.bring_to_front started") - result = mapping.from_maybe_impl(await self._impl_obj.bring_to_front()) - log_api("<= page.bring_to_front succeded") - return result - except Exception as e: - log_api("<= page.bring_to_front failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.bring_to_front()) async def add_init_script( self, script: str = None, *, path: typing.Union[str, pathlib.Path] = None @@ -6819,21 +5733,15 @@ async def add_init_script( Parameters ---------- script : Union[str, NoneType] + Script to be evaluated in all pages in the browser context. Optional. path : Union[pathlib.Path, str, NoneType] Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional. """ - try: - log_api("=> page.add_init_script started") - result = mapping.from_maybe_impl( - await self._impl_obj.add_init_script(script=script, path=path) - ) - log_api("<= page.add_init_script succeded") - return result - except Exception as e: - log_api("<= page.add_init_script failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.add_init_script(script=script, path=path) + ) async def route( self, @@ -6882,18 +5790,11 @@ async def route( handler function to route the request. """ - try: - log_api("=> page.route started") - result = mapping.from_maybe_impl( - await self._impl_obj.route( - url=self._wrap_handler(url), handler=self._wrap_handler(handler) - ) + return mapping.from_maybe_impl( + await self._impl_obj.route( + url=self._wrap_handler(url), handler=self._wrap_handler(handler) ) - log_api("<= page.route succeded") - return result - except Exception as e: - log_api("<= page.route failed") - raise e + ) async def unroute( self, @@ -6915,18 +5816,11 @@ async def unroute( Optional handler function to route the request. """ - try: - log_api("=> page.unroute started") - result = mapping.from_maybe_impl( - await self._impl_obj.unroute( - url=self._wrap_handler(url), handler=self._wrap_handler(handler) - ) + return mapping.from_maybe_impl( + await self._impl_obj.unroute( + url=self._wrap_handler(url), handler=self._wrap_handler(handler) ) - log_api("<= page.unroute succeded") - return result - except Exception as e: - log_api("<= page.unroute failed") - raise e + ) async def screenshot( self, @@ -6973,24 +5867,17 @@ async def screenshot( bytes """ - try: - log_api("=> page.screenshot started") - result = mapping.from_maybe_impl( - await self._impl_obj.screenshot( - timeout=timeout, - type=type, - path=path, - quality=quality, - omitBackground=omit_background, - fullPage=full_page, - clip=clip, - ) + return mapping.from_maybe_impl( + await self._impl_obj.screenshot( + timeout=timeout, + type=type, + path=path, + quality=quality, + omitBackground=omit_background, + fullPage=full_page, + clip=clip, ) - log_api("<= page.screenshot succeded") - return result - except Exception as e: - log_api("<= page.screenshot failed") - raise e + ) async def title(self) -> str: """Page.title @@ -7002,14 +5889,7 @@ async def title(self) -> str: str """ - try: - log_api("=> page.title started") - result = mapping.from_maybe_impl(await self._impl_obj.title()) - log_api("<= page.title succeded") - return result - except Exception as e: - log_api("<= page.title failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.title()) async def close(self, *, run_before_unload: bool = None) -> NoneType: """Page.close @@ -7029,16 +5909,9 @@ async def close(self, *, run_before_unload: bool = None) -> NoneType: [before unload](https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload) page handlers. """ - try: - log_api("=> page.close started") - result = mapping.from_maybe_impl( - await self._impl_obj.close(runBeforeUnload=run_before_unload) - ) - log_api("<= page.close succeded") - return result - except Exception as e: - log_api("<= page.close failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.close(runBeforeUnload=run_before_unload) + ) def is_closed(self) -> bool: """Page.is_closed @@ -7050,14 +5923,7 @@ def is_closed(self) -> bool: bool """ - try: - log_api("=> page.is_closed started") - result = mapping.from_maybe_impl(self._impl_obj.is_closed()) - log_api("<= page.is_closed succeded") - return result - except Exception as e: - log_api("<= page.is_closed failed") - raise e + return mapping.from_maybe_impl(self._impl_obj.is_closed()) async def click( self, @@ -7117,26 +5983,19 @@ async def click( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.click started") - result = mapping.from_maybe_impl( - await self._impl_obj.click( - selector=selector, - modifiers=modifiers, - position=position, - delay=delay, - button=button, - clickCount=click_count, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.click( + selector=selector, + modifiers=modifiers, + position=position, + delay=delay, + button=button, + clickCount=click_count, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) - log_api("<= page.click succeded") - return result - except Exception as e: - log_api("<= page.click failed") - raise e + ) async def dblclick( self, @@ -7196,25 +6055,18 @@ async def dblclick( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.dblclick started") - result = mapping.from_maybe_impl( - await self._impl_obj.dblclick( - selector=selector, - modifiers=modifiers, - position=position, - delay=delay, - button=button, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.dblclick( + selector=selector, + modifiers=modifiers, + position=position, + delay=delay, + button=button, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) - log_api("<= page.dblclick succeded") - return result - except Exception as e: - log_api("<= page.dblclick failed") - raise e + ) async def tap( self, @@ -7267,23 +6119,16 @@ async def tap( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.tap started") - result = mapping.from_maybe_impl( - await self._impl_obj.tap( - selector=selector, - modifiers=modifiers, - position=position, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.tap( + selector=selector, + modifiers=modifiers, + position=position, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) - log_api("<= page.tap succeded") - return result - except Exception as e: - log_api("<= page.tap failed") - raise e + ) async def fill( self, @@ -7321,21 +6166,14 @@ async def fill( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.fill started") - result = mapping.from_maybe_impl( - await self._impl_obj.fill( - selector=selector, - value=value, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.fill( + selector=selector, + value=value, + timeout=timeout, + noWaitAfter=no_wait_after, ) - log_api("<= page.fill succeded") - return result - except Exception as e: - log_api("<= page.fill failed") - raise e + ) async def focus(self, selector: str, *, timeout: float = None) -> NoneType: """Page.focus @@ -7355,16 +6193,9 @@ async def focus(self, selector: str, *, timeout: float = None) -> NoneType: using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ - try: - log_api("=> page.focus started") - result = mapping.from_maybe_impl( - await self._impl_obj.focus(selector=selector, timeout=timeout) - ) - log_api("<= page.focus succeded") - return result - except Exception as e: - log_api("<= page.focus failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.focus(selector=selector, timeout=timeout) + ) async def text_content( self, selector: str, *, timeout: float = None @@ -7387,16 +6218,9 @@ async def text_content( Union[str, NoneType] """ - try: - log_api("=> page.text_content started") - result = mapping.from_maybe_impl( - await self._impl_obj.text_content(selector=selector, timeout=timeout) - ) - log_api("<= page.text_content succeded") - return result - except Exception as e: - log_api("<= page.text_content failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.text_content(selector=selector, timeout=timeout) + ) async def inner_text(self, selector: str, *, timeout: float = None) -> str: """Page.inner_text @@ -7417,16 +6241,9 @@ async def inner_text(self, selector: str, *, timeout: float = None) -> str: str """ - try: - log_api("=> page.inner_text started") - result = mapping.from_maybe_impl( - await self._impl_obj.inner_text(selector=selector, timeout=timeout) - ) - log_api("<= page.inner_text succeded") - return result - except Exception as e: - log_api("<= page.inner_text failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.inner_text(selector=selector, timeout=timeout) + ) async def inner_html(self, selector: str, *, timeout: float = None) -> str: """Page.inner_html @@ -7447,16 +6264,9 @@ async def inner_html(self, selector: str, *, timeout: float = None) -> str: str """ - try: - log_api("=> page.inner_html started") - result = mapping.from_maybe_impl( - await self._impl_obj.inner_html(selector=selector, timeout=timeout) - ) - log_api("<= page.inner_html succeded") - return result - except Exception as e: - log_api("<= page.inner_html failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.inner_html(selector=selector, timeout=timeout) + ) async def get_attribute( self, selector: str, name: str, *, timeout: float = None @@ -7481,18 +6291,11 @@ async def get_attribute( Union[str, NoneType] """ - try: - log_api("=> page.get_attribute started") - result = mapping.from_maybe_impl( - await self._impl_obj.get_attribute( - selector=selector, name=name, timeout=timeout - ) + return mapping.from_maybe_impl( + await self._impl_obj.get_attribute( + selector=selector, name=name, timeout=timeout ) - log_api("<= page.get_attribute succeded") - return result - except Exception as e: - log_api("<= page.get_attribute failed") - raise e + ) async def hover( self, @@ -7538,22 +6341,15 @@ async def hover( Whether to bypass the [actionability](./actionability.md) checks. Defaults to `false`. """ - try: - log_api("=> page.hover started") - result = mapping.from_maybe_impl( - await self._impl_obj.hover( - selector=selector, - modifiers=modifiers, - position=position, - timeout=timeout, - force=force, - ) + return mapping.from_maybe_impl( + await self._impl_obj.hover( + selector=selector, + modifiers=modifiers, + position=position, + timeout=timeout, + force=force, ) - log_api("<= page.hover succeded") - return result - except Exception as e: - log_api("<= page.hover failed") - raise e + ) async def select_option( self, @@ -7614,24 +6410,17 @@ async def select_option( List[str] """ - try: - log_api("=> page.select_option started") - result = mapping.from_maybe_impl( - await self._impl_obj.select_option( - selector=selector, - value=value, - index=index, - label=label, - element=mapping.to_impl(element), - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.select_option( + selector=selector, + value=value, + index=index, + label=label, + element=mapping.to_impl(element), + timeout=timeout, + noWaitAfter=no_wait_after, ) - log_api("<= page.select_option succeded") - return result - except Exception as e: - log_api("<= page.select_option failed") - raise e + ) async def set_input_files( self, @@ -7670,21 +6459,14 @@ async def set_input_files( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.set_input_files started") - result = mapping.from_maybe_impl( - await self._impl_obj.set_input_files( - selector=selector, - files=files, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.set_input_files( + selector=selector, + files=files, + timeout=timeout, + noWaitAfter=no_wait_after, ) - log_api("<= page.set_input_files succeded") - return result - except Exception as e: - log_api("<= page.set_input_files failed") - raise e + ) async def type( self, @@ -7727,22 +6509,15 @@ async def type( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.type started") - result = mapping.from_maybe_impl( - await self._impl_obj.type( - selector=selector, - text=text, - delay=delay, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.type( + selector=selector, + text=text, + delay=delay, + timeout=timeout, + noWaitAfter=no_wait_after, ) - log_api("<= page.type succeded") - return result - except Exception as e: - log_api("<= page.type failed") - raise e + ) async def press( self, @@ -7804,22 +6579,15 @@ async def press( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.press started") - result = mapping.from_maybe_impl( - await self._impl_obj.press( - selector=selector, - key=key, - delay=delay, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.press( + selector=selector, + key=key, + delay=delay, + timeout=timeout, + noWaitAfter=no_wait_after, ) - log_api("<= page.press succeded") - return result - except Exception as e: - log_api("<= page.press failed") - raise e + ) async def check( self, @@ -7863,21 +6631,14 @@ async def check( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.check started") - result = mapping.from_maybe_impl( - await self._impl_obj.check( - selector=selector, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.check( + selector=selector, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) - log_api("<= page.check succeded") - return result - except Exception as e: - log_api("<= page.check failed") - raise e + ) async def uncheck( self, @@ -7921,21 +6682,14 @@ async def uncheck( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.uncheck started") - result = mapping.from_maybe_impl( - await self._impl_obj.uncheck( - selector=selector, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + await self._impl_obj.uncheck( + selector=selector, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) - log_api("<= page.uncheck succeded") - return result - except Exception as e: - log_api("<= page.uncheck failed") - raise e + ) async def wait_for_timeout(self, timeout: float) -> NoneType: """Page.wait_for_timeout @@ -7958,16 +6712,9 @@ async def wait_for_timeout(self, timeout: float) -> NoneType: A timeout to wait for """ - try: - log_api("=> page.wait_for_timeout started") - result = mapping.from_maybe_impl( - await self._impl_obj.wait_for_timeout(timeout=timeout) - ) - log_api("<= page.wait_for_timeout succeded") - return result - except Exception as e: - log_api("<= page.wait_for_timeout failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.wait_for_timeout(timeout=timeout) + ) async def wait_for_function( self, @@ -8016,7 +6763,7 @@ async def main(): JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. timeout : Union[float, NoneType] maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_timeout()`. @@ -8029,21 +6776,14 @@ async def main(): JSHandle """ - try: - log_api("=> page.wait_for_function started") - result = mapping.from_impl( - await self._impl_obj.wait_for_function( - expression=expression, - arg=mapping.to_impl(arg), - timeout=timeout, - polling=polling, - ) + return mapping.from_impl( + await self._impl_obj.wait_for_function( + expression=expression, + arg=mapping.to_impl(arg), + timeout=timeout, + polling=polling, ) - log_api("<= page.wait_for_function succeded") - return result - except Exception as e: - log_api("<= page.wait_for_function failed") - raise e + ) async def pause(self) -> NoneType: """Page.pause @@ -8054,18 +6794,11 @@ async def pause(self) -> NoneType: User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from the place it was paused. - > NOTE: This method requires Playwright to be started in a headed mode, with a falsy [`options: headless`] value in the + > NOTE: This method requires Playwright to be started in a headed mode, with a falsy `headless` value in the `browser_type.launch()`. """ - try: - log_api("=> page.pause started") - result = mapping.from_maybe_impl(await self._impl_obj.pause()) - log_api("<= page.pause succeded") - return result - except Exception as e: - log_api("<= page.pause failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.pause()) async def pdf( self, @@ -8174,30 +6907,23 @@ async def pdf( bytes """ - try: - log_api("=> page.pdf started") - result = mapping.from_maybe_impl( - await self._impl_obj.pdf( - scale=scale, - displayHeaderFooter=display_header_footer, - headerTemplate=header_template, - footerTemplate=footer_template, - printBackground=print_background, - landscape=landscape, - pageRanges=page_ranges, - format=format, - width=width, - height=height, - preferCSSPageSize=prefer_css_page_size, - margin=margin, - path=path, - ) + return mapping.from_maybe_impl( + await self._impl_obj.pdf( + scale=scale, + displayHeaderFooter=display_header_footer, + headerTemplate=header_template, + footerTemplate=footer_template, + printBackground=print_background, + landscape=landscape, + pageRanges=page_ranges, + format=format, + width=width, + height=height, + preferCSSPageSize=prefer_css_page_size, + margin=margin, + path=path, ) - log_api("<= page.pdf succeded") - return result - except Exception as e: - log_api("<= page.pdf failed") - raise e + ) def expect_event( self, event: str, predicate: typing.Callable = None, *, timeout: float = None @@ -8242,9 +6968,9 @@ def expect_console_message( ) -> AsyncEventContextManager["ConsoleMessage"]: """Page.expect_console_message - Performs action and waits for `console` event to fire. If predicate is provided, it passes `ConsoleMessage` value into - the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is - closed before the worker event is fired. + Performs action and waits for a [ConoleMessage] to be logged by in the page. If predicate is provided, it passes + `ConsoleMessage` value into the `predicate` function and waits for `predicate(message)` to return a truthy value. Will + throw an error if the page is closed before the console event is fired. Parameters ---------- @@ -8273,8 +6999,8 @@ def expect_download( ) -> AsyncEventContextManager["Download"]: """Page.expect_download - Performs action and waits for `download` event to fire. If predicate is provided, it passes `Download` value into the - `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is + Performs action and waits for a new `Download`. If predicate is provided, it passes `Download` value into the + `predicate` function and waits for `predicate(download)` to return a truthy value. Will throw an error if the page is closed before the download event is fired. Parameters @@ -8304,9 +7030,9 @@ def expect_file_chooser( ) -> AsyncEventContextManager["FileChooser"]: """Page.expect_file_chooser - Performs action and waits for `filechooser` event to fire. If predicate is provided, it passes `FileChooser` value into - the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is - closed before the worker event is fired. + Performs action and waits for a new `FileChooser` to be created. If predicate is provided, it passes `FileChooser` value + into the `predicate` function and waits for `predicate(fileChooser)` to return a truthy value. Will throw an error if + the page is closed before the file chooser is opened. Parameters ---------- @@ -8389,14 +7115,14 @@ def expect_popup( ) -> AsyncEventContextManager["Page"]: """Page.expect_popup - Performs action and waits for `popup` event to fire. If predicate is provided, it passes [Popup] value into the - `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is - closed before the popup event is fired. + Performs action and waits for a popup `Page`. If predicate is provided, it passes [Popup] value into the `predicate` + function and waits for `predicate(page)` to return a truthy value. Will throw an error if the page is closed before the + popup event is fired. Parameters ---------- predicate : Union[Callable[[Page], bool], NoneType] - Receives the [Popup] object and resolves to truthy value when the waiting should resolve. + Receives the `Page` object and resolves to truthy value when the waiting should resolve. timeout : Union[float, NoneType] Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_timeout()`. @@ -8498,9 +7224,9 @@ def expect_worker( ) -> AsyncEventContextManager["Worker"]: """Page.expect_worker - Performs action and waits for `worker` event to fire. If predicate is provided, it passes `Worker` value into the - `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is - closed before the worker event is fired. + Performs action and waits for a new `Worker`. If predicate is provided, it passes `Worker` value into the `predicate` + function and waits for `predicate(worker)` to return a truthy value. Will throw an error if the page is closed before + the worker event is fired. Parameters ---------- @@ -8574,16 +7300,9 @@ def set_default_navigation_timeout(self, timeout: float) -> NoneType: Maximum navigation time in milliseconds """ - try: - log_api("=> browser_context.set_default_navigation_timeout started") - result = mapping.from_maybe_impl( - self._impl_obj.set_default_navigation_timeout(timeout=timeout) - ) - log_api("<= browser_context.set_default_navigation_timeout succeded") - return result - except Exception as e: - log_api("<= browser_context.set_default_navigation_timeout failed") - raise e + return mapping.from_maybe_impl( + self._impl_obj.set_default_navigation_timeout(timeout=timeout) + ) def set_default_timeout(self, timeout: float) -> NoneType: """BrowserContext.set_default_timeout @@ -8599,16 +7318,9 @@ def set_default_timeout(self, timeout: float) -> NoneType: Maximum time in milliseconds """ - try: - log_api("=> browser_context.set_default_timeout started") - result = mapping.from_maybe_impl( - self._impl_obj.set_default_timeout(timeout=timeout) - ) - log_api("<= browser_context.set_default_timeout succeded") - return result - except Exception as e: - log_api("<= browser_context.set_default_timeout failed") - raise e + return mapping.from_maybe_impl( + self._impl_obj.set_default_timeout(timeout=timeout) + ) async def new_page(self) -> "Page": """BrowserContext.new_page @@ -8620,14 +7332,7 @@ async def new_page(self) -> "Page": Page """ - try: - log_api("=> browser_context.new_page started") - result = mapping.from_impl(await self._impl_obj.new_page()) - log_api("<= browser_context.new_page succeded") - return result - except Exception as e: - log_api("<= browser_context.new_page failed") - raise e + return mapping.from_impl(await self._impl_obj.new_page()) async def cookies( self, urls: typing.Union[str, typing.List[str]] = None @@ -8647,14 +7352,7 @@ async def cookies( List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}] """ - try: - log_api("=> browser_context.cookies started") - result = mapping.from_impl_list(await self._impl_obj.cookies(urls=urls)) - log_api("<= browser_context.cookies succeded") - return result - except Exception as e: - log_api("<= browser_context.cookies failed") - raise e + return mapping.from_impl_list(await self._impl_obj.cookies(urls=urls)) async def add_cookies(self, cookies: typing.List[Cookie]) -> NoneType: """BrowserContext.add_cookies @@ -8671,16 +7369,9 @@ async def add_cookies(self, cookies: typing.List[Cookie]) -> NoneType: cookies : List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}] """ - try: - log_api("=> browser_context.add_cookies started") - result = mapping.from_maybe_impl( - await self._impl_obj.add_cookies(cookies=cookies) - ) - log_api("<= browser_context.add_cookies succeded") - return result - except Exception as e: - log_api("<= browser_context.add_cookies failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.add_cookies(cookies=cookies) + ) async def clear_cookies(self) -> NoneType: """BrowserContext.clear_cookies @@ -8688,14 +7379,7 @@ async def clear_cookies(self) -> NoneType: Clears context cookies. """ - try: - log_api("=> browser_context.clear_cookies started") - result = mapping.from_maybe_impl(await self._impl_obj.clear_cookies()) - log_api("<= browser_context.clear_cookies succeded") - return result - except Exception as e: - log_api("<= browser_context.clear_cookies failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.clear_cookies()) async def grant_permissions( self, permissions: typing.List[str], *, origin: str = None @@ -8729,18 +7413,11 @@ async def grant_permissions( The [origin] to grant permissions to, e.g. "https://example.com". """ - try: - log_api("=> browser_context.grant_permissions started") - result = mapping.from_maybe_impl( - await self._impl_obj.grant_permissions( - permissions=permissions, origin=origin - ) + return mapping.from_maybe_impl( + await self._impl_obj.grant_permissions( + permissions=permissions, origin=origin ) - log_api("<= browser_context.grant_permissions succeded") - return result - except Exception as e: - log_api("<= browser_context.grant_permissions failed") - raise e + ) async def clear_permissions(self) -> NoneType: """BrowserContext.clear_permissions @@ -8755,14 +7432,7 @@ async def clear_permissions(self) -> NoneType: ``` """ - try: - log_api("=> browser_context.clear_permissions started") - result = mapping.from_maybe_impl(await self._impl_obj.clear_permissions()) - log_api("<= browser_context.clear_permissions succeded") - return result - except Exception as e: - log_api("<= browser_context.clear_permissions failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.clear_permissions()) async def set_geolocation(self, geolocation: Geolocation = None) -> NoneType: """BrowserContext.set_geolocation @@ -8781,16 +7451,9 @@ async def set_geolocation(self, geolocation: Geolocation = None) -> NoneType: geolocation : Union[{latitude: float, longitude: float, accuracy: Union[float, NoneType]}, NoneType] """ - try: - log_api("=> browser_context.set_geolocation started") - result = mapping.from_maybe_impl( - await self._impl_obj.set_geolocation(geolocation=geolocation) - ) - log_api("<= browser_context.set_geolocation succeded") - return result - except Exception as e: - log_api("<= browser_context.set_geolocation failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.set_geolocation(geolocation=geolocation) + ) async def set_extra_http_headers(self, headers: typing.Dict[str, str]) -> NoneType: """BrowserContext.set_extra_http_headers @@ -8807,18 +7470,11 @@ async def set_extra_http_headers(self, headers: typing.Dict[str, str]) -> NoneTy An object containing additional HTTP headers to be sent with every request. All header values must be strings. """ - try: - log_api("=> browser_context.set_extra_http_headers started") - result = mapping.from_maybe_impl( - await self._impl_obj.set_extra_http_headers( - headers=mapping.to_impl(headers) - ) + return mapping.from_maybe_impl( + await self._impl_obj.set_extra_http_headers( + headers=mapping.to_impl(headers) ) - log_api("<= browser_context.set_extra_http_headers succeded") - return result - except Exception as e: - log_api("<= browser_context.set_extra_http_headers failed") - raise e + ) async def set_offline(self, offline: bool) -> NoneType: """BrowserContext.set_offline @@ -8829,16 +7485,9 @@ async def set_offline(self, offline: bool) -> NoneType: Whether to emulate network being offline for the browser context. """ - try: - log_api("=> browser_context.set_offline started") - result = mapping.from_maybe_impl( - await self._impl_obj.set_offline(offline=offline) - ) - log_api("<= browser_context.set_offline succeded") - return result - except Exception as e: - log_api("<= browser_context.set_offline failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.set_offline(offline=offline) + ) async def add_init_script( self, script: str = None, *, path: typing.Union[str, pathlib.Path] = None @@ -8866,21 +7515,15 @@ async def add_init_script( Parameters ---------- script : Union[str, NoneType] + Script to be evaluated in all pages in the browser context. Optional. path : Union[pathlib.Path, str, NoneType] Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional. """ - try: - log_api("=> browser_context.add_init_script started") - result = mapping.from_maybe_impl( - await self._impl_obj.add_init_script(script=script, path=path) - ) - log_api("<= browser_context.add_init_script succeded") - return result - except Exception as e: - log_api("<= browser_context.add_init_script failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.add_init_script(script=script, path=path) + ) async def expose_binding( self, name: str, callback: typing.Callable, *, handle: bool = None @@ -8952,18 +7595,11 @@ async def print(source, element): supported. When passing by value, multiple arguments are supported. """ - try: - log_api("=> browser_context.expose_binding started") - result = mapping.from_maybe_impl( - await self._impl_obj.expose_binding( - name=name, callback=self._wrap_handler(callback), handle=handle - ) + return mapping.from_maybe_impl( + await self._impl_obj.expose_binding( + name=name, callback=self._wrap_handler(callback), handle=handle ) - log_api("<= browser_context.expose_binding succeded") - return result - except Exception as e: - log_api("<= browser_context.expose_binding failed") - raise e + ) async def expose_function(self, name: str, callback: typing.Callable) -> NoneType: """BrowserContext.expose_function @@ -9018,18 +7654,11 @@ async def main(): Callback function that will be called in the Playwright's context. """ - try: - log_api("=> browser_context.expose_function started") - result = mapping.from_maybe_impl( - await self._impl_obj.expose_function( - name=name, callback=self._wrap_handler(callback) - ) + return mapping.from_maybe_impl( + await self._impl_obj.expose_function( + name=name, callback=self._wrap_handler(callback) ) - log_api("<= browser_context.expose_function succeded") - return result - except Exception as e: - log_api("<= browser_context.expose_function failed") - raise e + ) async def route( self, @@ -9078,18 +7707,11 @@ async def route( handler function to route the request. """ - try: - log_api("=> browser_context.route started") - result = mapping.from_maybe_impl( - await self._impl_obj.route( - url=self._wrap_handler(url), handler=self._wrap_handler(handler) - ) + return mapping.from_maybe_impl( + await self._impl_obj.route( + url=self._wrap_handler(url), handler=self._wrap_handler(handler) ) - log_api("<= browser_context.route succeded") - return result - except Exception as e: - log_api("<= browser_context.route failed") - raise e + ) async def unroute( self, @@ -9113,18 +7735,11 @@ async def unroute( Optional handler function used to register a routing with `browser_context.route()`. """ - try: - log_api("=> browser_context.unroute started") - result = mapping.from_maybe_impl( - await self._impl_obj.unroute( - url=self._wrap_handler(url), handler=self._wrap_handler(handler) - ) + return mapping.from_maybe_impl( + await self._impl_obj.unroute( + url=self._wrap_handler(url), handler=self._wrap_handler(handler) ) - log_api("<= browser_context.unroute succeded") - return result - except Exception as e: - log_api("<= browser_context.unroute failed") - raise e + ) def expect_event( self, event: str, predicate: typing.Callable = None, *, timeout: float = None @@ -9169,14 +7784,7 @@ async def close(self) -> NoneType: > NOTE: The default browser context cannot be closed. """ - try: - log_api("=> browser_context.close started") - result = mapping.from_maybe_impl(await self._impl_obj.close()) - log_api("<= browser_context.close succeded") - return result - except Exception as e: - log_api("<= browser_context.close failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.close()) async def storage_state( self, *, path: typing.Union[str, pathlib.Path] = None @@ -9196,14 +7804,7 @@ async def storage_state( {cookies: Union[List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}], NoneType], origins: Union[List[{origin: str, localStorage: List[{name: str, value: str}]}], NoneType]} """ - try: - log_api("=> browser_context.storage_state started") - result = mapping.from_impl(await self._impl_obj.storage_state(path=path)) - log_api("<= browser_context.storage_state succeded") - return result - except Exception as e: - log_api("<= browser_context.storage_state failed") - raise e + return mapping.from_impl(await self._impl_obj.storage_state(path=path)) async def wait_for_event( self, event: str, predicate: typing.Callable = None, *, timeout: float = None @@ -9231,20 +7832,11 @@ async def wait_for_event( Any """ - try: - log_api("=> browser_context.wait_for_event started") - result = mapping.from_maybe_impl( - await self._impl_obj.wait_for_event( - event=event, - predicate=self._wrap_handler(predicate), - timeout=timeout, - ) + return mapping.from_maybe_impl( + await self._impl_obj.wait_for_event( + event=event, predicate=self._wrap_handler(predicate), timeout=timeout ) - log_api("<= browser_context.wait_for_event succeded") - return result - except Exception as e: - log_api("<= browser_context.wait_for_event failed") - raise e + ) def expect_page( self, @@ -9254,9 +7846,9 @@ def expect_page( ) -> AsyncEventContextManager["Page"]: """BrowserContext.expect_page - Performs action and waits for `page` event to fire. If predicate is provided, it passes `Page` value into the - `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is - closed before the worker event is fired. + Performs action and waits for a new `Page` to be created in the context. If predicate is provided, it passes `Page` + value into the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if + the context closes before new `Page` is created. Parameters ---------- @@ -9300,16 +7892,9 @@ async def send(self, method: str, params: typing.Dict = None) -> typing.Dict: Dict """ - try: - log_api("=> cdp_session.send started") - result = mapping.from_maybe_impl( - await self._impl_obj.send(method=method, params=mapping.to_impl(params)) - ) - log_api("<= cdp_session.send succeded") - return result - except Exception as e: - log_api("<= cdp_session.send failed") - raise e + return mapping.from_maybe_impl( + await self._impl_obj.send(method=method, params=mapping.to_impl(params)) + ) async def detach(self) -> NoneType: """CDPSession.detach @@ -9318,14 +7903,7 @@ async def detach(self) -> NoneType: send messages. """ - try: - log_api("=> cdp_session.detach started") - result = mapping.from_maybe_impl(await self._impl_obj.detach()) - log_api("<= cdp_session.detach succeded") - return result - except Exception as e: - log_api("<= cdp_session.detach failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.detach()) mapping.register(CDPSessionImpl, CDPSession) @@ -9374,16 +7952,9 @@ async def new_cdp_session(self, page: "Page") -> "CDPSession": CDPSession """ - try: - log_api("=> chromium_browser_context.new_cdp_session started") - result = mapping.from_impl( - await self._impl_obj.new_cdp_session(page=page._impl_obj) - ) - log_api("<= chromium_browser_context.new_cdp_session succeded") - return result - except Exception as e: - log_api("<= chromium_browser_context.new_cdp_session failed") - raise e + return mapping.from_impl( + await self._impl_obj.new_cdp_session(page=page._impl_obj) + ) mapping.register(ChromiumBrowserContextImpl, ChromiumBrowserContext) @@ -9434,14 +8005,7 @@ def is_connected(self) -> bool: bool """ - try: - log_api("=> browser.is_connected started") - result = mapping.from_maybe_impl(self._impl_obj.is_connected()) - log_api("<= browser.is_connected succeded") - return result - except Exception as e: - log_api("<= browser.is_connected failed") - raise e + return mapping.from_maybe_impl(self._impl_obj.is_connected()) async def new_context( self, @@ -9539,7 +8103,9 @@ async def new_context( record_video_dir : Union[pathlib.Path, str, NoneType] Path to the directory to put videos into. record_video_size : Union[{width: int, height: int}, NoneType] - Optional dimensions of the recorded videos. If not specified the size will be equal to `viewport`. + Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into + 800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will + be scaled down if necessary to fit the specified size. storage_state : Union[pathlib.Path, str, {cookies: Union[List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}], NoneType], origins: Union[List[{origin: str, localStorage: List[{name: str, value: str}]}], NoneType]}, NoneType] Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via `browser_context.storage_state()`. Either a path to the file with saved storage, or an object with @@ -9550,42 +8116,35 @@ async def new_context( BrowserContext """ - try: - log_api("=> browser.new_context started") - result = mapping.from_impl( - await self._impl_obj.new_context( - viewport=viewport, - noViewport=no_viewport, - ignoreHTTPSErrors=ignore_https_errors, - javaScriptEnabled=java_script_enabled, - bypassCSP=bypass_csp, - userAgent=user_agent, - locale=locale, - timezoneId=timezone_id, - geolocation=geolocation, - permissions=permissions, - extraHTTPHeaders=mapping.to_impl(extra_http_headers), - offline=offline, - httpCredentials=http_credentials, - deviceScaleFactor=device_scale_factor, - isMobile=is_mobile, - hasTouch=has_touch, - colorScheme=color_scheme, - acceptDownloads=accept_downloads, - defaultBrowserType=default_browser_type, - proxy=proxy, - recordHarPath=record_har_path, - recordHarOmitContent=record_har_omit_content, - recordVideoDir=record_video_dir, - recordVideoSize=record_video_size, - storageState=storage_state, - ) + return mapping.from_impl( + await self._impl_obj.new_context( + viewport=viewport, + noViewport=no_viewport, + ignoreHTTPSErrors=ignore_https_errors, + javaScriptEnabled=java_script_enabled, + bypassCSP=bypass_csp, + userAgent=user_agent, + locale=locale, + timezoneId=timezone_id, + geolocation=geolocation, + permissions=permissions, + extraHTTPHeaders=mapping.to_impl(extra_http_headers), + offline=offline, + httpCredentials=http_credentials, + deviceScaleFactor=device_scale_factor, + isMobile=is_mobile, + hasTouch=has_touch, + colorScheme=color_scheme, + acceptDownloads=accept_downloads, + defaultBrowserType=default_browser_type, + proxy=proxy, + recordHarPath=record_har_path, + recordHarOmitContent=record_har_omit_content, + recordVideoDir=record_video_dir, + recordVideoSize=record_video_size, + storageState=storage_state, ) - log_api("<= browser.new_context succeded") - return result - except Exception as e: - log_api("<= browser.new_context failed") - raise e + ) async def new_page( self, @@ -9678,7 +8237,9 @@ async def new_page( record_video_dir : Union[pathlib.Path, str, NoneType] Path to the directory to put videos into. record_video_size : Union[{width: int, height: int}, NoneType] - Optional dimensions of the recorded videos. If not specified the size will be equal to `viewport`. + Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into + 800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will + be scaled down if necessary to fit the specified size. storage_state : Union[pathlib.Path, str, {cookies: Union[List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}], NoneType], origins: Union[List[{origin: str, localStorage: List[{name: str, value: str}]}], NoneType]}, NoneType] Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via `browser_context.storage_state()`. Either a path to the file with saved storage, or an object with @@ -9689,42 +8250,35 @@ async def new_page( Page """ - try: - log_api("=> browser.new_page started") - result = mapping.from_impl( - await self._impl_obj.new_page( - viewport=viewport, - noViewport=no_viewport, - ignoreHTTPSErrors=ignore_https_errors, - javaScriptEnabled=java_script_enabled, - bypassCSP=bypass_csp, - userAgent=user_agent, - locale=locale, - timezoneId=timezone_id, - geolocation=geolocation, - permissions=permissions, - extraHTTPHeaders=mapping.to_impl(extra_http_headers), - offline=offline, - httpCredentials=http_credentials, - deviceScaleFactor=device_scale_factor, - isMobile=is_mobile, - hasTouch=has_touch, - colorScheme=color_scheme, - acceptDownloads=accept_downloads, - defaultBrowserType=default_browser_type, - proxy=proxy, - recordHarPath=record_har_path, - recordHarOmitContent=record_har_omit_content, - recordVideoDir=record_video_dir, - recordVideoSize=record_video_size, - storageState=storage_state, - ) + return mapping.from_impl( + await self._impl_obj.new_page( + viewport=viewport, + noViewport=no_viewport, + ignoreHTTPSErrors=ignore_https_errors, + javaScriptEnabled=java_script_enabled, + bypassCSP=bypass_csp, + userAgent=user_agent, + locale=locale, + timezoneId=timezone_id, + geolocation=geolocation, + permissions=permissions, + extraHTTPHeaders=mapping.to_impl(extra_http_headers), + offline=offline, + httpCredentials=http_credentials, + deviceScaleFactor=device_scale_factor, + isMobile=is_mobile, + hasTouch=has_touch, + colorScheme=color_scheme, + acceptDownloads=accept_downloads, + defaultBrowserType=default_browser_type, + proxy=proxy, + recordHarPath=record_har_path, + recordHarOmitContent=record_har_omit_content, + recordVideoDir=record_video_dir, + recordVideoSize=record_video_size, + storageState=storage_state, ) - log_api("<= browser.new_page succeded") - return result - except Exception as e: - log_api("<= browser.new_page failed") - raise e + ) async def close(self) -> NoneType: """Browser.close @@ -9738,14 +8292,7 @@ async def close(self) -> NoneType: The `Browser` object itself is considered to be disposed and cannot be used anymore. """ - try: - log_api("=> browser.close started") - result = mapping.from_maybe_impl(await self._impl_obj.close()) - log_api("<= browser.close succeded") - return result - except Exception as e: - log_api("<= browser.close failed") - raise e + return mapping.from_maybe_impl(await self._impl_obj.close()) mapping.register(BrowserImpl, Browser) @@ -9812,19 +8359,19 @@ async def launch( ) ``` - > **Chromium-only** Playwright can also be used to control the Chrome browser, but it works best with the version of - Chromium it is bundled with. There is no guarantee it will work with any other version. Use `executablePath` option with - extreme caution. + > **Chromium-only** Playwright can also be used to control the Google Chrome or Microsoft Edge browsers, but it works + best with the version of Chromium it is bundled with. There is no guarantee it will work with any other version. Use + `executablePath` option with extreme caution. > > If Google Chrome (rather than Chromium) is preferred, a [Chrome Canary](https://www.google.com/chrome/browser/canary.html) or [Dev Channel](https://www.chromium.org/getting-involved/dev-channel) build is suggested. > - > In `browser_type.launch()` above, any mention of Chromium also applies to Chrome. - > - > See [`this article`](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for - a description of the differences between Chromium and Chrome. - [`This article`](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md) + > Stock browsers like Google Chrome and Microsoft Edge are suitable for tests that require proprietary media codecs for + video playback. See + [this article](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for other + differences between Chromium and Chrome. + [This article](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md) describes some differences for Linux users. Parameters @@ -9876,32 +8423,25 @@ async def launch( Browser """ - try: - log_api("=> browser_type.launch started") - result = mapping.from_impl( - await self._impl_obj.launch( - executablePath=executable_path, - args=args, - ignoreDefaultArgs=ignore_default_args, - handleSIGINT=handle_sigint, - handleSIGTERM=handle_sigterm, - handleSIGHUP=handle_sighup, - timeout=timeout, - env=mapping.to_impl(env), - headless=headless, - devtools=devtools, - proxy=proxy, - downloadsPath=downloads_path, - slowMo=slow_mo, - chromiumSandbox=chromium_sandbox, - firefoxUserPrefs=mapping.to_impl(firefox_user_prefs), - ) + return mapping.from_impl( + await self._impl_obj.launch( + executablePath=executable_path, + args=args, + ignoreDefaultArgs=ignore_default_args, + handleSIGINT=handle_sigint, + handleSIGTERM=handle_sigterm, + handleSIGHUP=handle_sighup, + timeout=timeout, + env=mapping.to_impl(env), + headless=headless, + devtools=devtools, + proxy=proxy, + downloadsPath=downloads_path, + slowMo=slow_mo, + chromiumSandbox=chromium_sandbox, + firefoxUserPrefs=mapping.to_impl(firefox_user_prefs), ) - log_api("<= browser_type.launch succeded") - return result - except Exception as e: - log_api("<= browser_type.launch failed") - raise e + ) async def launch_persistent_context( self, @@ -10045,61 +8585,56 @@ async def launch_persistent_context( record_video_dir : Union[pathlib.Path, str, NoneType] Path to the directory to put videos into. record_video_size : Union[{width: int, height: int}, NoneType] - Optional dimensions of the recorded videos. If not specified the size will be equal to `viewport`. + Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into + 800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will + be scaled down if necessary to fit the specified size. Returns ------- BrowserContext """ - try: - log_api("=> browser_type.launch_persistent_context started") - result = mapping.from_impl( - await self._impl_obj.launch_persistent_context( - userDataDir=user_data_dir, - executablePath=executable_path, - args=args, - ignoreDefaultArgs=ignore_default_args, - handleSIGINT=handle_sigint, - handleSIGTERM=handle_sigterm, - handleSIGHUP=handle_sighup, - timeout=timeout, - env=mapping.to_impl(env), - headless=headless, - devtools=devtools, - proxy=proxy, - downloadsPath=downloads_path, - slowMo=slow_mo, - viewport=viewport, - noViewport=no_viewport, - ignoreHTTPSErrors=ignore_https_errors, - javaScriptEnabled=java_script_enabled, - bypassCSP=bypass_csp, - userAgent=user_agent, - locale=locale, - timezoneId=timezone_id, - geolocation=geolocation, - permissions=permissions, - extraHTTPHeaders=mapping.to_impl(extra_http_headers), - offline=offline, - httpCredentials=http_credentials, - deviceScaleFactor=device_scale_factor, - isMobile=is_mobile, - hasTouch=has_touch, - colorScheme=color_scheme, - acceptDownloads=accept_downloads, - chromiumSandbox=chromium_sandbox, - recordHarPath=record_har_path, - recordHarOmitContent=record_har_omit_content, - recordVideoDir=record_video_dir, - recordVideoSize=record_video_size, - ) + return mapping.from_impl( + await self._impl_obj.launch_persistent_context( + userDataDir=user_data_dir, + executablePath=executable_path, + args=args, + ignoreDefaultArgs=ignore_default_args, + handleSIGINT=handle_sigint, + handleSIGTERM=handle_sigterm, + handleSIGHUP=handle_sighup, + timeout=timeout, + env=mapping.to_impl(env), + headless=headless, + devtools=devtools, + proxy=proxy, + downloadsPath=downloads_path, + slowMo=slow_mo, + viewport=viewport, + noViewport=no_viewport, + ignoreHTTPSErrors=ignore_https_errors, + javaScriptEnabled=java_script_enabled, + bypassCSP=bypass_csp, + userAgent=user_agent, + locale=locale, + timezoneId=timezone_id, + geolocation=geolocation, + permissions=permissions, + extraHTTPHeaders=mapping.to_impl(extra_http_headers), + offline=offline, + httpCredentials=http_credentials, + deviceScaleFactor=device_scale_factor, + isMobile=is_mobile, + hasTouch=has_touch, + colorScheme=color_scheme, + acceptDownloads=accept_downloads, + chromiumSandbox=chromium_sandbox, + recordHarPath=record_har_path, + recordHarOmitContent=record_har_omit_content, + recordVideoDir=record_video_dir, + recordVideoSize=record_video_size, ) - log_api("<= browser_type.launch_persistent_context succeded") - return result - except Exception as e: - log_api("<= browser_type.launch_persistent_context failed") - raise e + ) mapping.register(BrowserTypeImpl, BrowserType) @@ -10211,14 +8746,7 @@ def stop(self) -> NoneType: ``` """ - try: - log_api("=> playwright.stop started") - result = mapping.from_maybe_impl(self._impl_obj.stop()) - log_api("<= playwright.stop succeded") - return result - except Exception as e: - log_api("<= playwright.stop failed") - raise e + return mapping.from_maybe_impl(self._impl_obj.stop()) mapping.register(PlaywrightImpl, Playwright) diff --git a/playwright/sync_api/_generated.py b/playwright/sync_api/_generated.py index 578bd50d1..bb6264704 100644 --- a/playwright/sync_api/_generated.py +++ b/playwright/sync_api/_generated.py @@ -54,7 +54,6 @@ from playwright._impl._input import Mouse as MouseImpl from playwright._impl._input import Touchscreen as TouchscreenImpl from playwright._impl._js_handle import JSHandle as JSHandleImpl -from playwright._impl._logger import log_api from playwright._impl._network import Request as RequestImpl from playwright._impl._network import Response as ResponseImpl from playwright._impl._network import Route as RouteImpl @@ -271,14 +270,7 @@ def response(self) -> typing.Union["Response", NoneType]: Union[Response, NoneType] """ - try: - log_api("=> request.response started") - result = mapping.from_impl_nullable(self._sync(self._impl_obj.response())) - log_api("<= request.response succeded") - return result - except Exception as e: - log_api("<= request.response failed") - raise e + return mapping.from_impl_nullable(self._sync(self._impl_obj.response())) def is_navigation_request(self) -> bool: """Request.is_navigation_request @@ -290,14 +282,7 @@ def is_navigation_request(self) -> bool: bool """ - try: - log_api("=> request.is_navigation_request started") - result = mapping.from_maybe_impl(self._impl_obj.is_navigation_request()) - log_api("<= request.is_navigation_request succeded") - return result - except Exception as e: - log_api("<= request.is_navigation_request failed") - raise e + return mapping.from_maybe_impl(self._impl_obj.is_navigation_request()) mapping.register(RequestImpl, Request) @@ -401,14 +386,7 @@ def finished(self) -> typing.Union[str, NoneType]: Union[str, NoneType] """ - try: - log_api("=> response.finished started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.finished())) - log_api("<= response.finished succeded") - return result - except Exception as e: - log_api("<= response.finished failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.finished())) def body(self) -> bytes: """Response.body @@ -420,14 +398,7 @@ def body(self) -> bytes: bytes """ - try: - log_api("=> response.body started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.body())) - log_api("<= response.body succeded") - return result - except Exception as e: - log_api("<= response.body failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.body())) def text(self) -> str: """Response.text @@ -439,14 +410,7 @@ def text(self) -> str: str """ - try: - log_api("=> response.text started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.text())) - log_api("<= response.text succeded") - return result - except Exception as e: - log_api("<= response.text failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.text())) def json(self) -> typing.Any: """Response.json @@ -460,14 +424,7 @@ def json(self) -> typing.Any: Any """ - try: - log_api("=> response.json started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.json())) - log_api("<= response.json succeded") - return result - except Exception as e: - log_api("<= response.json failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.json())) mapping.register(ResponseImpl, Response) @@ -516,16 +473,9 @@ def abort(self, error_code: str = None) -> NoneType: - `'failed'` - A generic failure occurred. """ - try: - log_api("=> route.abort started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.abort(errorCode=error_code)) - ) - log_api("<= route.abort succeded") - return result - except Exception as e: - log_api("<= route.abort failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.abort(errorCode=error_code)) + ) def fulfill( self, @@ -570,24 +520,17 @@ def fulfill( If set, equals to setting `Content-Type` response header. """ - try: - log_api("=> route.fulfill started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.fulfill( - status=status, - headers=mapping.to_impl(headers), - body=body, - path=path, - contentType=content_type, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.fulfill( + status=status, + headers=mapping.to_impl(headers), + body=body, + path=path, + contentType=content_type, ) ) - log_api("<= route.fulfill succeded") - return result - except Exception as e: - log_api("<= route.fulfill failed") - raise e + ) def continue_( self, @@ -626,23 +569,16 @@ def handle(route, request): If set changes the post data of request """ - try: - log_api("=> route.continue_ started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.continue_( - url=url, - method=method, - headers=mapping.to_impl(headers), - postData=post_data, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.continue_( + url=url, + method=method, + headers=mapping.to_impl(headers), + postData=post_data, ) ) - log_api("<= route.continue_ succeded") - return result - except Exception as e: - log_api("<= route.continue_ failed") - raise e + ) mapping.register(RouteImpl, Route) @@ -719,22 +655,15 @@ def wait_for_event( Any """ - try: - log_api("=> web_socket.wait_for_event started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.wait_for_event( - event=event, - predicate=self._wrap_handler(predicate), - timeout=timeout, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.wait_for_event( + event=event, + predicate=self._wrap_handler(predicate), + timeout=timeout, ) ) - log_api("<= web_socket.wait_for_event succeded") - return result - except Exception as e: - log_api("<= web_socket.wait_for_event failed") - raise e + ) def is_closed(self) -> bool: """WebSocket.is_closed @@ -746,14 +675,7 @@ def is_closed(self) -> bool: bool """ - try: - log_api("=> web_socket.is_closed started") - result = mapping.from_maybe_impl(self._impl_obj.is_closed()) - log_api("<= web_socket.is_closed succeded") - return result - except Exception as e: - log_api("<= web_socket.is_closed failed") - raise e + return mapping.from_maybe_impl(self._impl_obj.is_closed()) mapping.register(WebSocketImpl, WebSocket) @@ -797,14 +719,7 @@ def down(self, key: str) -> NoneType: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. """ - try: - log_api("=> keyboard.down started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.down(key=key))) - log_api("<= keyboard.down succeded") - return result - except Exception as e: - log_api("<= keyboard.down failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.down(key=key))) def up(self, key: str) -> NoneType: """Keyboard.up @@ -817,14 +732,7 @@ def up(self, key: str) -> NoneType: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. """ - try: - log_api("=> keyboard.up started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.up(key=key))) - log_api("<= keyboard.up succeded") - return result - except Exception as e: - log_api("<= keyboard.up failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.up(key=key))) def insert_text(self, text: str) -> NoneType: """Keyboard.insert_text @@ -843,16 +751,9 @@ def insert_text(self, text: str) -> NoneType: Sets input to the specified text value. """ - try: - log_api("=> keyboard.insert_text started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.insert_text(text=text)) - ) - log_api("<= keyboard.insert_text succeded") - return result - except Exception as e: - log_api("<= keyboard.insert_text failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.insert_text(text=text)) + ) def type(self, text: str, *, delay: float = None) -> NoneType: """Keyboard.type @@ -876,16 +777,9 @@ def type(self, text: str, *, delay: float = None) -> NoneType: Time to wait between key presses in milliseconds. Defaults to 0. """ - try: - log_api("=> keyboard.type started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.type(text=text, delay=delay)) - ) - log_api("<= keyboard.type succeded") - return result - except Exception as e: - log_api("<= keyboard.type failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.type(text=text, delay=delay)) + ) def press(self, key: str, *, delay: float = None) -> NoneType: """Keyboard.press @@ -929,16 +823,9 @@ def press(self, key: str, *, delay: float = None) -> NoneType: Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. """ - try: - log_api("=> keyboard.press started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.press(key=key, delay=delay)) - ) - log_api("<= keyboard.press succeded") - return result - except Exception as e: - log_api("<= keyboard.press failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.press(key=key, delay=delay)) + ) mapping.register(KeyboardImpl, Keyboard) @@ -961,16 +848,9 @@ def move(self, x: float, y: float, *, steps: int = None) -> NoneType: defaults to 1. Sends intermediate `mousemove` events. """ - try: - log_api("=> mouse.move started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.move(x=x, y=y, steps=steps)) - ) - log_api("<= mouse.move succeded") - return result - except Exception as e: - log_api("<= mouse.move failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.move(x=x, y=y, steps=steps)) + ) def down( self, @@ -990,16 +870,9 @@ def down( defaults to 1. See [UIEvent.detail]. """ - try: - log_api("=> mouse.down started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.down(button=button, clickCount=click_count)) - ) - log_api("<= mouse.down succeded") - return result - except Exception as e: - log_api("<= mouse.down failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.down(button=button, clickCount=click_count)) + ) def up( self, @@ -1019,16 +892,9 @@ def up( defaults to 1. See [UIEvent.detail]. """ - try: - log_api("=> mouse.up started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.up(button=button, clickCount=click_count)) - ) - log_api("<= mouse.up succeded") - return result - except Exception as e: - log_api("<= mouse.up failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.up(button=button, clickCount=click_count)) + ) def click( self, @@ -1055,20 +921,13 @@ def click( defaults to 1. See [UIEvent.detail]. """ - try: - log_api("=> mouse.click started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.click( - x=x, y=y, delay=delay, button=button, clickCount=click_count - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.click( + x=x, y=y, delay=delay, button=button, clickCount=click_count ) ) - log_api("<= mouse.click succeded") - return result - except Exception as e: - log_api("<= mouse.click failed") - raise e + ) def dblclick( self, @@ -1093,18 +952,9 @@ def dblclick( Defaults to `left`. """ - try: - log_api("=> mouse.dblclick started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.dblclick(x=x, y=y, delay=delay, button=button) - ) - ) - log_api("<= mouse.dblclick succeded") - return result - except Exception as e: - log_api("<= mouse.dblclick failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.dblclick(x=x, y=y, delay=delay, button=button)) + ) mapping.register(MouseImpl, Mouse) @@ -1125,14 +975,7 @@ def tap(self, x: float, y: float) -> NoneType: y : float """ - try: - log_api("=> touchscreen.tap started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.tap(x=x, y=y))) - log_api("<= touchscreen.tap succeded") - return result - except Exception as e: - log_api("<= touchscreen.tap failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.tap(x=x, y=y))) mapping.register(TouchscreenImpl, Touchscreen) @@ -1164,27 +1007,18 @@ def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any: JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> js_handle.evaluate started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.evaluate( - expression=expression, arg=mapping.to_impl(arg) - ) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.evaluate(expression=expression, arg=mapping.to_impl(arg)) ) - log_api("<= js_handle.evaluate succeded") - return result - except Exception as e: - log_api("<= js_handle.evaluate failed") - raise e + ) def evaluate_handle(self, expression: str, arg: typing.Any = None) -> "JSHandle": """JSHandle.evaluate_handle @@ -1207,27 +1041,20 @@ def evaluate_handle(self, expression: str, arg: typing.Any = None) -> "JSHandle" JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- JSHandle """ - try: - log_api("=> js_handle.evaluate_handle started") - result = mapping.from_impl( - self._sync( - self._impl_obj.evaluate_handle( - expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_impl( + self._sync( + self._impl_obj.evaluate_handle( + expression=expression, arg=mapping.to_impl(arg) ) ) - log_api("<= js_handle.evaluate_handle succeded") - return result - except Exception as e: - log_api("<= js_handle.evaluate_handle failed") - raise e + ) def get_property(self, property_name: str) -> "JSHandle": """JSHandle.get_property @@ -1244,16 +1071,9 @@ def get_property(self, property_name: str) -> "JSHandle": JSHandle """ - try: - log_api("=> js_handle.get_property started") - result = mapping.from_impl( - self._sync(self._impl_obj.get_property(propertyName=property_name)) - ) - log_api("<= js_handle.get_property succeded") - return result - except Exception as e: - log_api("<= js_handle.get_property failed") - raise e + return mapping.from_impl( + self._sync(self._impl_obj.get_property(propertyName=property_name)) + ) def get_properties(self) -> typing.Dict[str, "JSHandle"]: """JSHandle.get_properties @@ -1273,14 +1093,7 @@ def get_properties(self) -> typing.Dict[str, "JSHandle"]: Dict[str, JSHandle] """ - try: - log_api("=> js_handle.get_properties started") - result = mapping.from_impl_dict(self._sync(self._impl_obj.get_properties())) - log_api("<= js_handle.get_properties succeded") - return result - except Exception as e: - log_api("<= js_handle.get_properties failed") - raise e + return mapping.from_impl_dict(self._sync(self._impl_obj.get_properties())) def as_element(self) -> typing.Union["ElementHandle", NoneType]: """JSHandle.as_element @@ -1292,14 +1105,7 @@ def as_element(self) -> typing.Union["ElementHandle", NoneType]: Union[ElementHandle, NoneType] """ - try: - log_api("=> js_handle.as_element started") - result = mapping.from_impl_nullable(self._impl_obj.as_element()) - log_api("<= js_handle.as_element succeded") - return result - except Exception as e: - log_api("<= js_handle.as_element failed") - raise e + return mapping.from_impl_nullable(self._impl_obj.as_element()) def dispose(self) -> NoneType: """JSHandle.dispose @@ -1307,14 +1113,7 @@ def dispose(self) -> NoneType: The `jsHandle.dispose` method stops referencing the element handle. """ - try: - log_api("=> js_handle.dispose started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.dispose())) - log_api("<= js_handle.dispose succeded") - return result - except Exception as e: - log_api("<= js_handle.dispose failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.dispose())) def json_value(self) -> typing.Any: """JSHandle.json_value @@ -1329,14 +1128,7 @@ def json_value(self) -> typing.Any: Any """ - try: - log_api("=> js_handle.json_value started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.json_value())) - log_api("<= js_handle.json_value succeded") - return result - except Exception as e: - log_api("<= js_handle.json_value failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.json_value())) mapping.register(JSHandleImpl, JSHandle) @@ -1356,14 +1148,7 @@ def as_element(self) -> typing.Union["ElementHandle", NoneType]: Union[ElementHandle, NoneType] """ - try: - log_api("=> element_handle.as_element started") - result = mapping.from_impl_nullable(self._impl_obj.as_element()) - log_api("<= element_handle.as_element succeded") - return result - except Exception as e: - log_api("<= element_handle.as_element failed") - raise e + return mapping.from_impl_nullable(self._impl_obj.as_element()) def owner_frame(self) -> typing.Union["Frame", NoneType]: """ElementHandle.owner_frame @@ -1375,16 +1160,7 @@ def owner_frame(self) -> typing.Union["Frame", NoneType]: Union[Frame, NoneType] """ - try: - log_api("=> element_handle.owner_frame started") - result = mapping.from_impl_nullable( - self._sync(self._impl_obj.owner_frame()) - ) - log_api("<= element_handle.owner_frame succeded") - return result - except Exception as e: - log_api("<= element_handle.owner_frame failed") - raise e + return mapping.from_impl_nullable(self._sync(self._impl_obj.owner_frame())) def content_frame(self) -> typing.Union["Frame", NoneType]: """ElementHandle.content_frame @@ -1396,16 +1172,7 @@ def content_frame(self) -> typing.Union["Frame", NoneType]: Union[Frame, NoneType] """ - try: - log_api("=> element_handle.content_frame started") - result = mapping.from_impl_nullable( - self._sync(self._impl_obj.content_frame()) - ) - log_api("<= element_handle.content_frame succeded") - return result - except Exception as e: - log_api("<= element_handle.content_frame failed") - raise e + return mapping.from_impl_nullable(self._sync(self._impl_obj.content_frame())) def get_attribute(self, name: str) -> typing.Union[str, NoneType]: """ElementHandle.get_attribute @@ -1422,16 +1189,9 @@ def get_attribute(self, name: str) -> typing.Union[str, NoneType]: Union[str, NoneType] """ - try: - log_api("=> element_handle.get_attribute started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.get_attribute(name=name)) - ) - log_api("<= element_handle.get_attribute succeded") - return result - except Exception as e: - log_api("<= element_handle.get_attribute failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.get_attribute(name=name)) + ) def text_content(self) -> typing.Union[str, NoneType]: """ElementHandle.text_content @@ -1443,14 +1203,7 @@ def text_content(self) -> typing.Union[str, NoneType]: Union[str, NoneType] """ - try: - log_api("=> element_handle.text_content started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.text_content())) - log_api("<= element_handle.text_content succeded") - return result - except Exception as e: - log_api("<= element_handle.text_content failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.text_content())) def inner_text(self) -> str: """ElementHandle.inner_text @@ -1462,14 +1215,7 @@ def inner_text(self) -> str: str """ - try: - log_api("=> element_handle.inner_text started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.inner_text())) - log_api("<= element_handle.inner_text succeded") - return result - except Exception as e: - log_api("<= element_handle.inner_text failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.inner_text())) def inner_html(self) -> str: """ElementHandle.inner_html @@ -1481,14 +1227,7 @@ def inner_html(self) -> str: str """ - try: - log_api("=> element_handle.inner_html started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.inner_html())) - log_api("<= element_handle.inner_html succeded") - return result - except Exception as e: - log_api("<= element_handle.inner_html failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.inner_html())) def is_checked(self) -> bool: """ElementHandle.is_checked @@ -1500,14 +1239,7 @@ def is_checked(self) -> bool: bool """ - try: - log_api("=> element_handle.is_checked started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.is_checked())) - log_api("<= element_handle.is_checked succeded") - return result - except Exception as e: - log_api("<= element_handle.is_checked failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.is_checked())) def is_disabled(self) -> bool: """ElementHandle.is_disabled @@ -1519,14 +1251,7 @@ def is_disabled(self) -> bool: bool """ - try: - log_api("=> element_handle.is_disabled started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.is_disabled())) - log_api("<= element_handle.is_disabled succeded") - return result - except Exception as e: - log_api("<= element_handle.is_disabled failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.is_disabled())) def is_editable(self) -> bool: """ElementHandle.is_editable @@ -1538,14 +1263,7 @@ def is_editable(self) -> bool: bool """ - try: - log_api("=> element_handle.is_editable started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.is_editable())) - log_api("<= element_handle.is_editable succeded") - return result - except Exception as e: - log_api("<= element_handle.is_editable failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.is_editable())) def is_enabled(self) -> bool: """ElementHandle.is_enabled @@ -1557,14 +1275,7 @@ def is_enabled(self) -> bool: bool """ - try: - log_api("=> element_handle.is_enabled started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.is_enabled())) - log_api("<= element_handle.is_enabled succeded") - return result - except Exception as e: - log_api("<= element_handle.is_enabled failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.is_enabled())) def is_hidden(self) -> bool: """ElementHandle.is_hidden @@ -1576,14 +1287,7 @@ def is_hidden(self) -> bool: bool """ - try: - log_api("=> element_handle.is_hidden started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.is_hidden())) - log_api("<= element_handle.is_hidden succeded") - return result - except Exception as e: - log_api("<= element_handle.is_hidden failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.is_hidden())) def is_visible(self) -> bool: """ElementHandle.is_visible @@ -1595,14 +1299,7 @@ def is_visible(self) -> bool: bool """ - try: - log_api("=> element_handle.is_visible started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.is_visible())) - log_api("<= element_handle.is_visible succeded") - return result - except Exception as e: - log_api("<= element_handle.is_visible failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.is_visible())) def dispatch_event(self, type: str, event_init: typing.Dict = None) -> NoneType: """ElementHandle.dispatch_event @@ -1643,20 +1340,13 @@ def dispatch_event(self, type: str, event_init: typing.Dict = None) -> NoneType: Optional event-specific initialization properties. """ - try: - log_api("=> element_handle.dispatch_event started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.dispatch_event( - type=type, eventInit=mapping.to_impl(event_init) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.dispatch_event( + type=type, eventInit=mapping.to_impl(event_init) ) ) - log_api("<= element_handle.dispatch_event succeded") - return result - except Exception as e: - log_api("<= element_handle.dispatch_event failed") - raise e + ) def scroll_into_view_if_needed(self, *, timeout: float = None) -> NoneType: """ElementHandle.scroll_into_view_if_needed @@ -1675,16 +1365,9 @@ def scroll_into_view_if_needed(self, *, timeout: float = None) -> NoneType: using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ - try: - log_api("=> element_handle.scroll_into_view_if_needed started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.scroll_into_view_if_needed(timeout=timeout)) - ) - log_api("<= element_handle.scroll_into_view_if_needed succeded") - return result - except Exception as e: - log_api("<= element_handle.scroll_into_view_if_needed failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.scroll_into_view_if_needed(timeout=timeout)) + ) def hover( self, @@ -1724,23 +1407,13 @@ def hover( Whether to bypass the [actionability](./actionability.md) checks. Defaults to `false`. """ - try: - log_api("=> element_handle.hover started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.hover( - modifiers=modifiers, - position=position, - timeout=timeout, - force=force, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.hover( + modifiers=modifiers, position=position, timeout=timeout, force=force ) ) - log_api("<= element_handle.hover succeded") - return result - except Exception as e: - log_api("<= element_handle.hover failed") - raise e + ) def click( self, @@ -1794,27 +1467,20 @@ def click( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.click started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.click( - modifiers=modifiers, - position=position, - delay=delay, - button=button, - clickCount=click_count, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.click( + modifiers=modifiers, + position=position, + delay=delay, + button=button, + clickCount=click_count, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) ) - log_api("<= element_handle.click succeded") - return result - except Exception as e: - log_api("<= element_handle.click failed") - raise e + ) def dblclick( self, @@ -1868,26 +1534,19 @@ def dblclick( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.dblclick started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.dblclick( - modifiers=modifiers, - position=position, - delay=delay, - button=button, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.dblclick( + modifiers=modifiers, + position=position, + delay=delay, + button=button, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) ) - log_api("<= element_handle.dblclick succeded") - return result - except Exception as e: - log_api("<= element_handle.dblclick failed") - raise e + ) def select_option( self, @@ -1953,25 +1612,18 @@ def select_option( List[str] """ - try: - log_api("=> element_handle.select_option started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.select_option( - value=value, - index=index, - label=label, - element=mapping.to_impl(element), - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.select_option( + value=value, + index=index, + label=label, + element=mapping.to_impl(element), + timeout=timeout, + noWaitAfter=no_wait_after, ) ) - log_api("<= element_handle.select_option succeded") - return result - except Exception as e: - log_api("<= element_handle.select_option failed") - raise e + ) def tap( self, @@ -2018,24 +1670,17 @@ def tap( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.tap started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.tap( - modifiers=modifiers, - position=position, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.tap( + modifiers=modifiers, + position=position, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) ) - log_api("<= element_handle.tap succeded") - return result - except Exception as e: - log_api("<= element_handle.tap failed") - raise e + ) def fill( self, value: str, *, timeout: float = None, no_wait_after: bool = None @@ -2061,20 +1706,13 @@ def fill( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.fill started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.fill( - value=value, timeout=timeout, noWaitAfter=no_wait_after - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.fill( + value=value, timeout=timeout, noWaitAfter=no_wait_after ) ) - log_api("<= element_handle.fill succeded") - return result - except Exception as e: - log_api("<= element_handle.fill failed") - raise e + ) def select_text(self, *, timeout: float = None) -> NoneType: """ElementHandle.select_text @@ -2089,16 +1727,9 @@ def select_text(self, *, timeout: float = None) -> NoneType: using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ - try: - log_api("=> element_handle.select_text started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.select_text(timeout=timeout)) - ) - log_api("<= element_handle.select_text succeded") - return result - except Exception as e: - log_api("<= element_handle.select_text failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.select_text(timeout=timeout)) + ) def set_input_files( self, @@ -2133,20 +1764,13 @@ def set_input_files( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.set_input_files started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.set_input_files( - files=files, timeout=timeout, noWaitAfter=no_wait_after - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.set_input_files( + files=files, timeout=timeout, noWaitAfter=no_wait_after ) ) - log_api("<= element_handle.set_input_files succeded") - return result - except Exception as e: - log_api("<= element_handle.set_input_files failed") - raise e + ) def focus(self) -> NoneType: """ElementHandle.focus @@ -2154,14 +1778,7 @@ def focus(self) -> NoneType: Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the element. """ - try: - log_api("=> element_handle.focus started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.focus())) - log_api("<= element_handle.focus succeded") - return result - except Exception as e: - log_api("<= element_handle.focus failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.focus())) def type( self, @@ -2205,23 +1822,13 @@ def type( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.type started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.type( - text=text, - delay=delay, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.type( + text=text, delay=delay, timeout=timeout, noWaitAfter=no_wait_after ) ) - log_api("<= element_handle.type succeded") - return result - except Exception as e: - log_api("<= element_handle.type failed") - raise e + ) def press( self, @@ -2267,20 +1874,13 @@ def press( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.press started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.press( - key=key, delay=delay, timeout=timeout, noWaitAfter=no_wait_after - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.press( + key=key, delay=delay, timeout=timeout, noWaitAfter=no_wait_after ) ) - log_api("<= element_handle.press succeded") - return result - except Exception as e: - log_api("<= element_handle.press failed") - raise e + ) def check( self, *, timeout: float = None, force: bool = None, no_wait_after: bool = None @@ -2314,20 +1914,13 @@ def check( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.check started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.check( - timeout=timeout, force=force, noWaitAfter=no_wait_after - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.check( + timeout=timeout, force=force, noWaitAfter=no_wait_after ) ) - log_api("<= element_handle.check succeded") - return result - except Exception as e: - log_api("<= element_handle.check failed") - raise e + ) def uncheck( self, *, timeout: float = None, force: bool = None, no_wait_after: bool = None @@ -2361,20 +1954,13 @@ def uncheck( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> element_handle.uncheck started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.uncheck( - timeout=timeout, force=force, noWaitAfter=no_wait_after - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.uncheck( + timeout=timeout, force=force, noWaitAfter=no_wait_after ) ) - log_api("<= element_handle.uncheck succeded") - return result - except Exception as e: - log_api("<= element_handle.uncheck failed") - raise e + ) def bounding_box(self) -> typing.Union[FloatRect, NoneType]: """ElementHandle.bounding_box @@ -2402,16 +1988,7 @@ def bounding_box(self) -> typing.Union[FloatRect, NoneType]: Union[{x: float, y: float, width: float, height: float}, NoneType] """ - try: - log_api("=> element_handle.bounding_box started") - result = mapping.from_impl_nullable( - self._sync(self._impl_obj.bounding_box()) - ) - log_api("<= element_handle.bounding_box succeded") - return result - except Exception as e: - log_api("<= element_handle.bounding_box failed") - raise e + return mapping.from_impl_nullable(self._sync(self._impl_obj.bounding_box())) def screenshot( self, @@ -2451,24 +2028,17 @@ def screenshot( bytes """ - try: - log_api("=> element_handle.screenshot started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.screenshot( - timeout=timeout, - type=type, - path=path, - quality=quality, - omitBackground=omit_background, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.screenshot( + timeout=timeout, + type=type, + path=path, + quality=quality, + omitBackground=omit_background, ) ) - log_api("<= element_handle.screenshot succeded") - return result - except Exception as e: - log_api("<= element_handle.screenshot failed") - raise e + ) def query_selector(self, selector: str) -> typing.Union["ElementHandle", NoneType]: """ElementHandle.query_selector @@ -2486,16 +2056,9 @@ def query_selector(self, selector: str) -> typing.Union["ElementHandle", NoneTyp Union[ElementHandle, NoneType] """ - try: - log_api("=> element_handle.query_selector started") - result = mapping.from_impl_nullable( - self._sync(self._impl_obj.query_selector(selector=selector)) - ) - log_api("<= element_handle.query_selector succeded") - return result - except Exception as e: - log_api("<= element_handle.query_selector failed") - raise e + return mapping.from_impl_nullable( + self._sync(self._impl_obj.query_selector(selector=selector)) + ) def query_selector_all(self, selector: str) -> typing.List["ElementHandle"]: """ElementHandle.query_selector_all @@ -2513,16 +2076,9 @@ def query_selector_all(self, selector: str) -> typing.List["ElementHandle"]: List[ElementHandle] """ - try: - log_api("=> element_handle.query_selector_all started") - result = mapping.from_impl_list( - self._sync(self._impl_obj.query_selector_all(selector=selector)) - ) - log_api("<= element_handle.query_selector_all succeded") - return result - except Exception as e: - log_api("<= element_handle.query_selector_all failed") - raise e + return mapping.from_impl_list( + self._sync(self._impl_obj.query_selector_all(selector=selector)) + ) def eval_on_selector( self, selector: str, expression: str, arg: typing.Any = None @@ -2554,29 +2110,20 @@ def eval_on_selector( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> element_handle.eval_on_selector started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.eval_on_selector( - selector=selector, - expression=expression, - arg=mapping.to_impl(arg), - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.eval_on_selector( + selector=selector, expression=expression, arg=mapping.to_impl(arg) ) ) - log_api("<= element_handle.eval_on_selector succeded") - return result - except Exception as e: - log_api("<= element_handle.eval_on_selector failed") - raise e + ) def eval_on_selector_all( self, selector: str, expression: str, arg: typing.Any = None @@ -2613,29 +2160,20 @@ def eval_on_selector_all( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> element_handle.eval_on_selector_all started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.eval_on_selector_all( - selector=selector, - expression=expression, - arg=mapping.to_impl(arg), - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.eval_on_selector_all( + selector=selector, expression=expression, arg=mapping.to_impl(arg) ) ) - log_api("<= element_handle.eval_on_selector_all succeded") - return result - except Exception as e: - log_api("<= element_handle.eval_on_selector_all failed") - raise e + ) def wait_for_element_state( self, @@ -2671,18 +2209,11 @@ def wait_for_element_state( using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ - try: - log_api("=> element_handle.wait_for_element_state started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.wait_for_element_state(state=state, timeout=timeout) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.wait_for_element_state(state=state, timeout=timeout) ) - log_api("<= element_handle.wait_for_element_state succeded") - return result - except Exception as e: - log_api("<= element_handle.wait_for_element_state failed") - raise e + ) def wait_for_selector( self, @@ -2731,20 +2262,13 @@ def wait_for_selector( Union[ElementHandle, NoneType] """ - try: - log_api("=> element_handle.wait_for_selector started") - result = mapping.from_impl_nullable( - self._sync( - self._impl_obj.wait_for_selector( - selector=selector, state=state, timeout=timeout - ) + return mapping.from_impl_nullable( + self._sync( + self._impl_obj.wait_for_selector( + selector=selector, state=state, timeout=timeout ) ) - log_api("<= element_handle.wait_for_selector succeded") - return result - except Exception as e: - log_api("<= element_handle.wait_for_selector failed") - raise e + ) mapping.register(ElementHandleImpl, ElementHandle) @@ -2801,20 +2325,13 @@ def find_focused_node(node): Union[Dict, NoneType] """ - try: - log_api("=> accessibility.snapshot started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.snapshot( - interestingOnly=interesting_only, root=mapping.to_impl(root) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.snapshot( + interestingOnly=interesting_only, root=mapping.to_impl(root) ) ) - log_api("<= accessibility.snapshot succeded") - return result - except Exception as e: - log_api("<= accessibility.snapshot failed") - raise e + ) mapping.register(AccessibilityImpl, Accessibility) @@ -2858,14 +2375,7 @@ def is_multiple(self) -> bool: bool """ - try: - log_api("=> file_chooser.is_multiple started") - result = mapping.from_maybe_impl(self._impl_obj.is_multiple()) - log_api("<= file_chooser.is_multiple succeded") - return result - except Exception as e: - log_api("<= file_chooser.is_multiple failed") - raise e + return mapping.from_maybe_impl(self._impl_obj.is_multiple()) def set_files( self, @@ -2897,20 +2407,13 @@ def set_files( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> file_chooser.set_files started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.set_files( - files=files, timeout=timeout, noWaitAfter=no_wait_after - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.set_files( + files=files, timeout=timeout, noWaitAfter=no_wait_after ) ) - log_api("<= file_chooser.set_files succeded") - return result - except Exception as e: - log_api("<= file_chooser.set_files failed") - raise e + ) mapping.register(FileChooserImpl, FileChooser) @@ -3034,20 +2537,13 @@ def goto( Union[Response, NoneType] """ - try: - log_api("=> frame.goto started") - result = mapping.from_impl_nullable( - self._sync( - self._impl_obj.goto( - url=url, timeout=timeout, waitUntil=wait_until, referer=referer - ) + return mapping.from_impl_nullable( + self._sync( + self._impl_obj.goto( + url=url, timeout=timeout, waitUntil=wait_until, referer=referer ) ) - log_api("<= frame.goto succeded") - return result - except Exception as e: - log_api("<= frame.goto failed") - raise e + ) def expect_navigation( self, @@ -3133,18 +2629,9 @@ def wait_for_load_state( `page.set_default_timeout()` methods. """ - try: - log_api("=> frame.wait_for_load_state started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.wait_for_load_state(state=state, timeout=timeout) - ) - ) - log_api("<= frame.wait_for_load_state succeded") - return result - except Exception as e: - log_api("<= frame.wait_for_load_state failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.wait_for_load_state(state=state, timeout=timeout)) + ) def frame_element(self) -> "ElementHandle": """Frame.frame_element @@ -3167,14 +2654,7 @@ def frame_element(self) -> "ElementHandle": ElementHandle """ - try: - log_api("=> frame.frame_element started") - result = mapping.from_impl(self._sync(self._impl_obj.frame_element())) - log_api("<= frame.frame_element succeded") - return result - except Exception as e: - log_api("<= frame.frame_element failed") - raise e + return mapping.from_impl(self._sync(self._impl_obj.frame_element())) def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any: """Frame.evaluate @@ -3215,27 +2695,18 @@ def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any: JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> frame.evaluate started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.evaluate( - expression=expression, arg=mapping.to_impl(arg) - ) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.evaluate(expression=expression, arg=mapping.to_impl(arg)) ) - log_api("<= frame.evaluate succeded") - return result - except Exception as e: - log_api("<= frame.evaluate failed") - raise e + ) def evaluate_handle(self, expression: str, arg: typing.Any = None) -> "JSHandle": """Frame.evaluate_handle @@ -3274,27 +2745,20 @@ def evaluate_handle(self, expression: str, arg: typing.Any = None) -> "JSHandle" JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- JSHandle """ - try: - log_api("=> frame.evaluate_handle started") - result = mapping.from_impl( - self._sync( - self._impl_obj.evaluate_handle( - expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_impl( + self._sync( + self._impl_obj.evaluate_handle( + expression=expression, arg=mapping.to_impl(arg) ) ) - log_api("<= frame.evaluate_handle succeded") - return result - except Exception as e: - log_api("<= frame.evaluate_handle failed") - raise e + ) def query_selector(self, selector: str) -> typing.Union["ElementHandle", NoneType]: """Frame.query_selector @@ -3314,16 +2778,9 @@ def query_selector(self, selector: str) -> typing.Union["ElementHandle", NoneTyp Union[ElementHandle, NoneType] """ - try: - log_api("=> frame.query_selector started") - result = mapping.from_impl_nullable( - self._sync(self._impl_obj.query_selector(selector=selector)) - ) - log_api("<= frame.query_selector succeded") - return result - except Exception as e: - log_api("<= frame.query_selector failed") - raise e + return mapping.from_impl_nullable( + self._sync(self._impl_obj.query_selector(selector=selector)) + ) def query_selector_all(self, selector: str) -> typing.List["ElementHandle"]: """Frame.query_selector_all @@ -3343,16 +2800,9 @@ def query_selector_all(self, selector: str) -> typing.List["ElementHandle"]: List[ElementHandle] """ - try: - log_api("=> frame.query_selector_all started") - result = mapping.from_impl_list( - self._sync(self._impl_obj.query_selector_all(selector=selector)) - ) - log_api("<= frame.query_selector_all succeded") - return result - except Exception as e: - log_api("<= frame.query_selector_all failed") - raise e + return mapping.from_impl_list( + self._sync(self._impl_obj.query_selector_all(selector=selector)) + ) def wait_for_selector( self, @@ -3410,20 +2860,13 @@ def run(playwright): Union[ElementHandle, NoneType] """ - try: - log_api("=> frame.wait_for_selector started") - result = mapping.from_impl_nullable( - self._sync( - self._impl_obj.wait_for_selector( - selector=selector, timeout=timeout, state=state - ) + return mapping.from_impl_nullable( + self._sync( + self._impl_obj.wait_for_selector( + selector=selector, timeout=timeout, state=state ) ) - log_api("<= frame.wait_for_selector succeded") - return result - except Exception as e: - log_api("<= frame.wait_for_selector failed") - raise e + ) def is_checked(self, selector: str, *, timeout: float = None) -> bool: """Frame.is_checked @@ -3444,18 +2887,9 @@ def is_checked(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> frame.is_checked started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.is_checked(selector=selector, timeout=timeout) - ) - ) - log_api("<= frame.is_checked succeded") - return result - except Exception as e: - log_api("<= frame.is_checked failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.is_checked(selector=selector, timeout=timeout)) + ) def is_disabled(self, selector: str, *, timeout: float = None) -> bool: """Frame.is_disabled @@ -3476,18 +2910,9 @@ def is_disabled(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> frame.is_disabled started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.is_disabled(selector=selector, timeout=timeout) - ) - ) - log_api("<= frame.is_disabled succeded") - return result - except Exception as e: - log_api("<= frame.is_disabled failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.is_disabled(selector=selector, timeout=timeout)) + ) def is_editable(self, selector: str, *, timeout: float = None) -> bool: """Frame.is_editable @@ -3508,18 +2933,9 @@ def is_editable(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> frame.is_editable started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.is_editable(selector=selector, timeout=timeout) - ) - ) - log_api("<= frame.is_editable succeded") - return result - except Exception as e: - log_api("<= frame.is_editable failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.is_editable(selector=selector, timeout=timeout)) + ) def is_enabled(self, selector: str, *, timeout: float = None) -> bool: """Frame.is_enabled @@ -3540,23 +2956,15 @@ def is_enabled(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> frame.is_enabled started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.is_enabled(selector=selector, timeout=timeout) - ) - ) - log_api("<= frame.is_enabled succeded") - return result - except Exception as e: - log_api("<= frame.is_enabled failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.is_enabled(selector=selector, timeout=timeout)) + ) def is_hidden(self, selector: str, *, timeout: float = None) -> bool: """Frame.is_hidden - Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). + Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). `selector` that does not + match any elements is considered hidden. Parameters ---------- @@ -3572,21 +2980,15 @@ def is_hidden(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> frame.is_hidden started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.is_hidden(selector=selector, timeout=timeout)) - ) - log_api("<= frame.is_hidden succeded") - return result - except Exception as e: - log_api("<= frame.is_hidden failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.is_hidden(selector=selector, timeout=timeout)) + ) def is_visible(self, selector: str, *, timeout: float = None) -> bool: """Frame.is_visible - Returns whether the element is [visible](./actionability.md#visible). + Returns whether the element is [visible](./actionability.md#visible). `selector` that does not match any elements is + considered not visible. Parameters ---------- @@ -3602,18 +3004,9 @@ def is_visible(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> frame.is_visible started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.is_visible(selector=selector, timeout=timeout) - ) - ) - log_api("<= frame.is_visible succeded") - return result - except Exception as e: - log_api("<= frame.is_visible failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.is_visible(selector=selector, timeout=timeout)) + ) def dispatch_event( self, @@ -3667,23 +3060,16 @@ def dispatch_event( using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ - try: - log_api("=> frame.dispatch_event started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.dispatch_event( - selector=selector, - type=type, - eventInit=mapping.to_impl(event_init), - timeout=timeout, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.dispatch_event( + selector=selector, + type=type, + eventInit=mapping.to_impl(event_init), + timeout=timeout, ) ) - log_api("<= frame.dispatch_event succeded") - return result - except Exception as e: - log_api("<= frame.dispatch_event failed") - raise e + ) def eval_on_selector( self, selector: str, expression: str, arg: typing.Any = None @@ -3715,29 +3101,20 @@ def eval_on_selector( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> frame.eval_on_selector started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.eval_on_selector( - selector=selector, - expression=expression, - arg=mapping.to_impl(arg), - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.eval_on_selector( + selector=selector, expression=expression, arg=mapping.to_impl(arg) ) ) - log_api("<= frame.eval_on_selector succeded") - return result - except Exception as e: - log_api("<= frame.eval_on_selector failed") - raise e + ) def eval_on_selector_all( self, selector: str, expression: str, arg: typing.Any = None @@ -3766,29 +3143,20 @@ def eval_on_selector_all( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> frame.eval_on_selector_all started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.eval_on_selector_all( - selector=selector, - expression=expression, - arg=mapping.to_impl(arg), - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.eval_on_selector_all( + selector=selector, expression=expression, arg=mapping.to_impl(arg) ) ) - log_api("<= frame.eval_on_selector_all succeded") - return result - except Exception as e: - log_api("<= frame.eval_on_selector_all failed") - raise e + ) def content(self) -> str: """Frame.content @@ -3800,14 +3168,7 @@ def content(self) -> str: str """ - try: - log_api("=> frame.content started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.content())) - log_api("<= frame.content succeded") - return result - except Exception as e: - log_api("<= frame.content failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.content())) def set_content( self, @@ -3834,20 +3195,13 @@ def set_content( - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. """ - try: - log_api("=> frame.set_content started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.set_content( - html=html, timeout=timeout, waitUntil=wait_until - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.set_content( + html=html, timeout=timeout, waitUntil=wait_until ) ) - log_api("<= frame.set_content succeded") - return result - except Exception as e: - log_api("<= frame.set_content failed") - raise e + ) def is_detached(self) -> bool: """Frame.is_detached @@ -3859,14 +3213,7 @@ def is_detached(self) -> bool: bool """ - try: - log_api("=> frame.is_detached started") - result = mapping.from_maybe_impl(self._impl_obj.is_detached()) - log_api("<= frame.is_detached succeded") - return result - except Exception as e: - log_api("<= frame.is_detached failed") - raise e + return mapping.from_maybe_impl(self._impl_obj.is_detached()) def add_script_tag( self, @@ -3900,20 +3247,13 @@ def add_script_tag( ElementHandle """ - try: - log_api("=> frame.add_script_tag started") - result = mapping.from_impl( - self._sync( - self._impl_obj.add_script_tag( - url=url, path=path, content=content, type=type - ) + return mapping.from_impl( + self._sync( + self._impl_obj.add_script_tag( + url=url, path=path, content=content, type=type ) ) - log_api("<= frame.add_script_tag succeded") - return result - except Exception as e: - log_api("<= frame.add_script_tag failed") - raise e + ) def add_style_tag( self, @@ -3944,18 +3284,11 @@ def add_style_tag( ElementHandle """ - try: - log_api("=> frame.add_style_tag started") - result = mapping.from_impl( - self._sync( - self._impl_obj.add_style_tag(url=url, path=path, content=content) - ) + return mapping.from_impl( + self._sync( + self._impl_obj.add_style_tag(url=url, path=path, content=content) ) - log_api("<= frame.add_style_tag succeded") - return result - except Exception as e: - log_api("<= frame.add_style_tag failed") - raise e + ) def click( self, @@ -4013,28 +3346,21 @@ def click( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.click started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.click( - selector=selector, - modifiers=modifiers, - position=position, - delay=delay, - button=button, - clickCount=click_count, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.click( + selector=selector, + modifiers=modifiers, + position=position, + delay=delay, + button=button, + clickCount=click_count, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) ) - log_api("<= frame.click succeded") - return result - except Exception as e: - log_api("<= frame.click failed") - raise e + ) def dblclick( self, @@ -4092,27 +3418,20 @@ def dblclick( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.dblclick started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.dblclick( - selector=selector, - modifiers=modifiers, - position=position, - delay=delay, - button=button, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.dblclick( + selector=selector, + modifiers=modifiers, + position=position, + delay=delay, + button=button, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) ) - log_api("<= frame.dblclick succeded") - return result - except Exception as e: - log_api("<= frame.dblclick failed") - raise e + ) def tap( self, @@ -4163,25 +3482,18 @@ def tap( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.tap started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.tap( - selector=selector, - modifiers=modifiers, - position=position, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.tap( + selector=selector, + modifiers=modifiers, + position=position, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) ) - log_api("<= frame.tap succeded") - return result - except Exception as e: - log_api("<= frame.tap failed") - raise e + ) def fill( self, @@ -4217,23 +3529,16 @@ def fill( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.fill started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.fill( - selector=selector, - value=value, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.fill( + selector=selector, + value=value, + timeout=timeout, + noWaitAfter=no_wait_after, ) ) - log_api("<= frame.fill succeded") - return result - except Exception as e: - log_api("<= frame.fill failed") - raise e + ) def focus(self, selector: str, *, timeout: float = None) -> NoneType: """Frame.focus @@ -4251,16 +3556,9 @@ def focus(self, selector: str, *, timeout: float = None) -> NoneType: using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ - try: - log_api("=> frame.focus started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.focus(selector=selector, timeout=timeout)) - ) - log_api("<= frame.focus succeded") - return result - except Exception as e: - log_api("<= frame.focus failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.focus(selector=selector, timeout=timeout)) + ) def text_content( self, selector: str, *, timeout: float = None @@ -4283,18 +3581,9 @@ def text_content( Union[str, NoneType] """ - try: - log_api("=> frame.text_content started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.text_content(selector=selector, timeout=timeout) - ) - ) - log_api("<= frame.text_content succeded") - return result - except Exception as e: - log_api("<= frame.text_content failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.text_content(selector=selector, timeout=timeout)) + ) def inner_text(self, selector: str, *, timeout: float = None) -> str: """Frame.inner_text @@ -4315,18 +3604,9 @@ def inner_text(self, selector: str, *, timeout: float = None) -> str: str """ - try: - log_api("=> frame.inner_text started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.inner_text(selector=selector, timeout=timeout) - ) - ) - log_api("<= frame.inner_text succeded") - return result - except Exception as e: - log_api("<= frame.inner_text failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.inner_text(selector=selector, timeout=timeout)) + ) def inner_html(self, selector: str, *, timeout: float = None) -> str: """Frame.inner_html @@ -4347,18 +3627,9 @@ def inner_html(self, selector: str, *, timeout: float = None) -> str: str """ - try: - log_api("=> frame.inner_html started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.inner_html(selector=selector, timeout=timeout) - ) - ) - log_api("<= frame.inner_html succeded") - return result - except Exception as e: - log_api("<= frame.inner_html failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.inner_html(selector=selector, timeout=timeout)) + ) def get_attribute( self, selector: str, name: str, *, timeout: float = None @@ -4383,20 +3654,13 @@ def get_attribute( Union[str, NoneType] """ - try: - log_api("=> frame.get_attribute started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.get_attribute( - selector=selector, name=name, timeout=timeout - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.get_attribute( + selector=selector, name=name, timeout=timeout ) ) - log_api("<= frame.get_attribute succeded") - return result - except Exception as e: - log_api("<= frame.get_attribute failed") - raise e + ) def hover( self, @@ -4440,24 +3704,17 @@ def hover( Whether to bypass the [actionability](./actionability.md) checks. Defaults to `false`. """ - try: - log_api("=> frame.hover started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.hover( - selector=selector, - modifiers=modifiers, - position=position, - timeout=timeout, - force=force, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.hover( + selector=selector, + modifiers=modifiers, + position=position, + timeout=timeout, + force=force, ) ) - log_api("<= frame.hover succeded") - return result - except Exception as e: - log_api("<= frame.hover failed") - raise e + ) def select_option( self, @@ -4515,26 +3772,19 @@ def select_option( List[str] """ - try: - log_api("=> frame.select_option started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.select_option( - selector=selector, - value=value, - index=index, - label=label, - element=mapping.to_impl(element), - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.select_option( + selector=selector, + value=value, + index=index, + label=label, + element=mapping.to_impl(element), + timeout=timeout, + noWaitAfter=no_wait_after, ) ) - log_api("<= frame.select_option succeded") - return result - except Exception as e: - log_api("<= frame.select_option failed") - raise e + ) def set_input_files( self, @@ -4573,23 +3823,16 @@ def set_input_files( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.set_input_files started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.set_input_files( - selector=selector, - files=files, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.set_input_files( + selector=selector, + files=files, + timeout=timeout, + noWaitAfter=no_wait_after, ) ) - log_api("<= frame.set_input_files succeded") - return result - except Exception as e: - log_api("<= frame.set_input_files failed") - raise e + ) def type( self, @@ -4630,24 +3873,17 @@ def type( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.type started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.type( - selector=selector, - text=text, - delay=delay, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.type( + selector=selector, + text=text, + delay=delay, + timeout=timeout, + noWaitAfter=no_wait_after, ) ) - log_api("<= frame.type succeded") - return result - except Exception as e: - log_api("<= frame.type failed") - raise e + ) def press( self, @@ -4695,24 +3931,17 @@ def press( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.press started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.press( - selector=selector, - key=key, - delay=delay, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.press( + selector=selector, + key=key, + delay=delay, + timeout=timeout, + noWaitAfter=no_wait_after, ) ) - log_api("<= frame.press succeded") - return result - except Exception as e: - log_api("<= frame.press failed") - raise e + ) def check( self, @@ -4754,23 +3983,16 @@ def check( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.check started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.check( - selector=selector, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.check( + selector=selector, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) ) - log_api("<= frame.check succeded") - return result - except Exception as e: - log_api("<= frame.check failed") - raise e + ) def uncheck( self, @@ -4812,23 +4034,16 @@ def uncheck( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> frame.uncheck started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.uncheck( - selector=selector, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.uncheck( + selector=selector, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) ) - log_api("<= frame.uncheck succeded") - return result - except Exception as e: - log_api("<= frame.uncheck failed") - raise e + ) def wait_for_timeout(self, timeout: float) -> NoneType: """Frame.wait_for_timeout @@ -4844,16 +4059,9 @@ def wait_for_timeout(self, timeout: float) -> NoneType: A timeout to wait for """ - try: - log_api("=> frame.wait_for_timeout started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.wait_for_timeout(timeout=timeout)) - ) - log_api("<= frame.wait_for_timeout succeded") - return result - except Exception as e: - log_api("<= frame.wait_for_timeout failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.wait_for_timeout(timeout=timeout)) + ) def wait_for_function( self, @@ -4897,7 +4105,7 @@ def run(playwright): JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. timeout : Union[float, NoneType] maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_timeout()`. @@ -4910,23 +4118,16 @@ def run(playwright): JSHandle """ - try: - log_api("=> frame.wait_for_function started") - result = mapping.from_impl( - self._sync( - self._impl_obj.wait_for_function( - expression=expression, - arg=mapping.to_impl(arg), - timeout=timeout, - polling=polling, - ) + return mapping.from_impl( + self._sync( + self._impl_obj.wait_for_function( + expression=expression, + arg=mapping.to_impl(arg), + timeout=timeout, + polling=polling, ) ) - log_api("<= frame.wait_for_function succeded") - return result - except Exception as e: - log_api("<= frame.wait_for_function failed") - raise e + ) def title(self) -> str: """Frame.title @@ -4938,14 +4139,7 @@ def title(self) -> str: str """ - try: - log_api("=> frame.title started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.title())) - log_api("<= frame.title succeded") - return result - except Exception as e: - log_api("<= frame.title failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.title())) mapping.register(FrameImpl, Frame) @@ -4983,27 +4177,18 @@ def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any: JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> worker.evaluate started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.evaluate( - expression=expression, arg=mapping.to_impl(arg) - ) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.evaluate(expression=expression, arg=mapping.to_impl(arg)) ) - log_api("<= worker.evaluate succeded") - return result - except Exception as e: - log_api("<= worker.evaluate failed") - raise e + ) def evaluate_handle(self, expression: str, arg: typing.Any = None) -> "JSHandle": """Worker.evaluate_handle @@ -5022,27 +4207,20 @@ def evaluate_handle(self, expression: str, arg: typing.Any = None) -> "JSHandle" JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- JSHandle """ - try: - log_api("=> worker.evaluate_handle started") - result = mapping.from_impl( - self._sync( - self._impl_obj.evaluate_handle( - expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_impl( + self._sync( + self._impl_obj.evaluate_handle( + expression=expression, arg=mapping.to_impl(arg) ) ) - log_api("<= worker.evaluate_handle succeded") - return result - except Exception as e: - log_api("<= worker.evaluate_handle failed") - raise e + ) mapping.register(WorkerImpl, Worker) @@ -5084,23 +4262,13 @@ def register( guaranteed when this engine is used together with other registered engines. """ - try: - log_api("=> selectors.register started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.register( - name=name, - script=script, - path=path, - contentScript=content_script, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.register( + name=name, script=script, path=path, contentScript=content_script ) ) - log_api("<= selectors.register succeded") - return result - except Exception as e: - log_api("<= selectors.register failed") - raise e + ) mapping.register(SelectorsImpl, Selectors) @@ -5209,16 +4377,9 @@ def accept(self, prompt_text: str = None) -> NoneType: A text to enter in prompt. Does not cause any effects if the dialog's `type` is not prompt. Optional. """ - try: - log_api("=> dialog.accept started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.accept(promptText=prompt_text)) - ) - log_api("<= dialog.accept succeded") - return result - except Exception as e: - log_api("<= dialog.accept failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.accept(promptText=prompt_text)) + ) def dismiss(self) -> NoneType: """Dialog.dismiss @@ -5226,14 +4387,7 @@ def dismiss(self) -> NoneType: Returns when the dialog has been dismissed. """ - try: - log_api("=> dialog.dismiss started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.dismiss())) - log_api("<= dialog.dismiss succeded") - return result - except Exception as e: - log_api("<= dialog.dismiss failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.dismiss())) mapping.register(DialogImpl, Dialog) @@ -5276,14 +4430,7 @@ def delete(self) -> NoneType: Deletes the downloaded file. """ - try: - log_api("=> download.delete started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.delete())) - log_api("<= download.delete succeded") - return result - except Exception as e: - log_api("<= download.delete failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.delete())) def failure(self) -> typing.Union[str, NoneType]: """Download.failure @@ -5295,14 +4442,7 @@ def failure(self) -> typing.Union[str, NoneType]: Union[str, NoneType] """ - try: - log_api("=> download.failure started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.failure())) - log_api("<= download.failure succeded") - return result - except Exception as e: - log_api("<= download.failure failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.failure())) def path(self) -> typing.Union[pathlib.Path, NoneType]: """Download.path @@ -5314,14 +4454,7 @@ def path(self) -> typing.Union[pathlib.Path, NoneType]: Union[pathlib.Path, NoneType] """ - try: - log_api("=> download.path started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.path())) - log_api("<= download.path succeded") - return result - except Exception as e: - log_api("<= download.path failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.path())) def save_as(self, path: typing.Union[str, pathlib.Path]) -> NoneType: """Download.save_as @@ -5334,16 +4467,7 @@ def save_as(self, path: typing.Union[str, pathlib.Path]) -> NoneType: Path where the download should be saved. """ - try: - log_api("=> download.save_as started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.save_as(path=path)) - ) - log_api("<= download.save_as succeded") - return result - except Exception as e: - log_api("<= download.save_as failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.save_as(path=path))) mapping.register(DownloadImpl, Download) @@ -5364,14 +4488,7 @@ def path(self) -> pathlib.Path: pathlib.Path """ - try: - log_api("=> video.path started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.path())) - log_api("<= video.path succeded") - return result - except Exception as e: - log_api("<= video.path failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.path())) mapping.register(VideoImpl, Video) @@ -5516,14 +4633,7 @@ def opener(self) -> typing.Union["Page", NoneType]: Union[Page, NoneType] """ - try: - log_api("=> page.opener started") - result = mapping.from_impl_nullable(self._sync(self._impl_obj.opener())) - log_api("<= page.opener succeded") - return result - except Exception as e: - log_api("<= page.opener failed") - raise e + return mapping.from_impl_nullable(self._sync(self._impl_obj.opener())) def frame( self, @@ -5555,16 +4665,9 @@ def frame( Union[Frame, NoneType] """ - try: - log_api("=> page.frame started") - result = mapping.from_impl_nullable( - self._impl_obj.frame(name=name, url=self._wrap_handler(url)) - ) - log_api("<= page.frame succeded") - return result - except Exception as e: - log_api("<= page.frame failed") - raise e + return mapping.from_impl_nullable( + self._impl_obj.frame(name=name, url=self._wrap_handler(url)) + ) def set_default_navigation_timeout(self, timeout: float) -> NoneType: """Page.set_default_navigation_timeout @@ -5586,16 +4689,9 @@ def set_default_navigation_timeout(self, timeout: float) -> NoneType: Maximum navigation time in milliseconds """ - try: - log_api("=> page.set_default_navigation_timeout started") - result = mapping.from_maybe_impl( - self._impl_obj.set_default_navigation_timeout(timeout=timeout) - ) - log_api("<= page.set_default_navigation_timeout succeded") - return result - except Exception as e: - log_api("<= page.set_default_navigation_timeout failed") - raise e + return mapping.from_maybe_impl( + self._impl_obj.set_default_navigation_timeout(timeout=timeout) + ) def set_default_timeout(self, timeout: float) -> NoneType: """Page.set_default_timeout @@ -5610,16 +4706,9 @@ def set_default_timeout(self, timeout: float) -> NoneType: Maximum time in milliseconds """ - try: - log_api("=> page.set_default_timeout started") - result = mapping.from_maybe_impl( - self._impl_obj.set_default_timeout(timeout=timeout) - ) - log_api("<= page.set_default_timeout succeded") - return result - except Exception as e: - log_api("<= page.set_default_timeout failed") - raise e + return mapping.from_maybe_impl( + self._impl_obj.set_default_timeout(timeout=timeout) + ) def query_selector(self, selector: str) -> typing.Union["ElementHandle", NoneType]: """Page.query_selector @@ -5639,16 +4728,9 @@ def query_selector(self, selector: str) -> typing.Union["ElementHandle", NoneTyp Union[ElementHandle, NoneType] """ - try: - log_api("=> page.query_selector started") - result = mapping.from_impl_nullable( - self._sync(self._impl_obj.query_selector(selector=selector)) - ) - log_api("<= page.query_selector succeded") - return result - except Exception as e: - log_api("<= page.query_selector failed") - raise e + return mapping.from_impl_nullable( + self._sync(self._impl_obj.query_selector(selector=selector)) + ) def query_selector_all(self, selector: str) -> typing.List["ElementHandle"]: """Page.query_selector_all @@ -5668,16 +4750,9 @@ def query_selector_all(self, selector: str) -> typing.List["ElementHandle"]: List[ElementHandle] """ - try: - log_api("=> page.query_selector_all started") - result = mapping.from_impl_list( - self._sync(self._impl_obj.query_selector_all(selector=selector)) - ) - log_api("<= page.query_selector_all succeded") - return result - except Exception as e: - log_api("<= page.query_selector_all failed") - raise e + return mapping.from_impl_list( + self._sync(self._impl_obj.query_selector_all(selector=selector)) + ) def wait_for_selector( self, @@ -5735,20 +4810,13 @@ def run(playwright): Union[ElementHandle, NoneType] """ - try: - log_api("=> page.wait_for_selector started") - result = mapping.from_impl_nullable( - self._sync( - self._impl_obj.wait_for_selector( - selector=selector, timeout=timeout, state=state - ) + return mapping.from_impl_nullable( + self._sync( + self._impl_obj.wait_for_selector( + selector=selector, timeout=timeout, state=state ) ) - log_api("<= page.wait_for_selector succeded") - return result - except Exception as e: - log_api("<= page.wait_for_selector failed") - raise e + ) def is_checked(self, selector: str, *, timeout: float = None) -> bool: """Page.is_checked @@ -5769,18 +4837,9 @@ def is_checked(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> page.is_checked started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.is_checked(selector=selector, timeout=timeout) - ) - ) - log_api("<= page.is_checked succeded") - return result - except Exception as e: - log_api("<= page.is_checked failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.is_checked(selector=selector, timeout=timeout)) + ) def is_disabled(self, selector: str, *, timeout: float = None) -> bool: """Page.is_disabled @@ -5801,18 +4860,9 @@ def is_disabled(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> page.is_disabled started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.is_disabled(selector=selector, timeout=timeout) - ) - ) - log_api("<= page.is_disabled succeded") - return result - except Exception as e: - log_api("<= page.is_disabled failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.is_disabled(selector=selector, timeout=timeout)) + ) def is_editable(self, selector: str, *, timeout: float = None) -> bool: """Page.is_editable @@ -5833,18 +4883,9 @@ def is_editable(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> page.is_editable started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.is_editable(selector=selector, timeout=timeout) - ) - ) - log_api("<= page.is_editable succeded") - return result - except Exception as e: - log_api("<= page.is_editable failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.is_editable(selector=selector, timeout=timeout)) + ) def is_enabled(self, selector: str, *, timeout: float = None) -> bool: """Page.is_enabled @@ -5865,23 +4906,15 @@ def is_enabled(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> page.is_enabled started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.is_enabled(selector=selector, timeout=timeout) - ) - ) - log_api("<= page.is_enabled succeded") - return result - except Exception as e: - log_api("<= page.is_enabled failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.is_enabled(selector=selector, timeout=timeout)) + ) def is_hidden(self, selector: str, *, timeout: float = None) -> bool: """Page.is_hidden - Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). + Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). `selector` that does not + match any elements is considered hidden. Parameters ---------- @@ -5897,21 +4930,15 @@ def is_hidden(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> page.is_hidden started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.is_hidden(selector=selector, timeout=timeout)) - ) - log_api("<= page.is_hidden succeded") - return result - except Exception as e: - log_api("<= page.is_hidden failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.is_hidden(selector=selector, timeout=timeout)) + ) def is_visible(self, selector: str, *, timeout: float = None) -> bool: """Page.is_visible - Returns whether the element is [visible](./actionability.md#visible). + Returns whether the element is [visible](./actionability.md#visible). `selector` that does not match any elements is + considered not visible. Parameters ---------- @@ -5927,18 +4954,9 @@ def is_visible(self, selector: str, *, timeout: float = None) -> bool: bool """ - try: - log_api("=> page.is_visible started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.is_visible(selector=selector, timeout=timeout) - ) - ) - log_api("<= page.is_visible succeded") - return result - except Exception as e: - log_api("<= page.is_visible failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.is_visible(selector=selector, timeout=timeout)) + ) def dispatch_event( self, @@ -5992,23 +5010,16 @@ def dispatch_event( using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ - try: - log_api("=> page.dispatch_event started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.dispatch_event( - selector=selector, - type=type, - eventInit=mapping.to_impl(event_init), - timeout=timeout, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.dispatch_event( + selector=selector, + type=type, + eventInit=mapping.to_impl(event_init), + timeout=timeout, ) ) - log_api("<= page.dispatch_event succeded") - return result - except Exception as e: - log_api("<= page.dispatch_event failed") - raise e + ) def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any: """Page.evaluate @@ -6053,27 +5064,18 @@ def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any: JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> page.evaluate started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.evaluate( - expression=expression, arg=mapping.to_impl(arg) - ) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.evaluate(expression=expression, arg=mapping.to_impl(arg)) ) - log_api("<= page.evaluate succeded") - return result - except Exception as e: - log_api("<= page.evaluate failed") - raise e + ) def evaluate_handle(self, expression: str, arg: typing.Any = None) -> "JSHandle": """Page.evaluate_handle @@ -6112,27 +5114,20 @@ def evaluate_handle(self, expression: str, arg: typing.Any = None) -> "JSHandle" JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- JSHandle """ - try: - log_api("=> page.evaluate_handle started") - result = mapping.from_impl( - self._sync( - self._impl_obj.evaluate_handle( - expression=expression, arg=mapping.to_impl(arg) - ) + return mapping.from_impl( + self._sync( + self._impl_obj.evaluate_handle( + expression=expression, arg=mapping.to_impl(arg) ) ) - log_api("<= page.evaluate_handle succeded") - return result - except Exception as e: - log_api("<= page.evaluate_handle failed") - raise e + ) def eval_on_selector( self, selector: str, expression: str, arg: typing.Any = None @@ -6163,29 +5158,20 @@ def eval_on_selector( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> page.eval_on_selector started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.eval_on_selector( - selector=selector, - expression=expression, - arg=mapping.to_impl(arg), - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.eval_on_selector( + selector=selector, expression=expression, arg=mapping.to_impl(arg) ) ) - log_api("<= page.eval_on_selector succeded") - return result - except Exception as e: - log_api("<= page.eval_on_selector failed") - raise e + ) def eval_on_selector_all( self, selector: str, expression: str, arg: typing.Any = None @@ -6212,29 +5198,20 @@ def eval_on_selector_all( JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. Returns ------- Any """ - try: - log_api("=> page.eval_on_selector_all started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.eval_on_selector_all( - selector=selector, - expression=expression, - arg=mapping.to_impl(arg), - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.eval_on_selector_all( + selector=selector, expression=expression, arg=mapping.to_impl(arg) ) ) - log_api("<= page.eval_on_selector_all succeded") - return result - except Exception as e: - log_api("<= page.eval_on_selector_all failed") - raise e + ) def add_script_tag( self, @@ -6269,20 +5246,13 @@ def add_script_tag( ElementHandle """ - try: - log_api("=> page.add_script_tag started") - result = mapping.from_impl( - self._sync( - self._impl_obj.add_script_tag( - url=url, path=path, content=content, type=type - ) + return mapping.from_impl( + self._sync( + self._impl_obj.add_script_tag( + url=url, path=path, content=content, type=type ) ) - log_api("<= page.add_script_tag succeded") - return result - except Exception as e: - log_api("<= page.add_script_tag failed") - raise e + ) def add_style_tag( self, @@ -6313,18 +5283,11 @@ def add_style_tag( ElementHandle """ - try: - log_api("=> page.add_style_tag started") - result = mapping.from_impl( - self._sync( - self._impl_obj.add_style_tag(url=url, path=path, content=content) - ) + return mapping.from_impl( + self._sync( + self._impl_obj.add_style_tag(url=url, path=path, content=content) ) - log_api("<= page.add_style_tag succeded") - return result - except Exception as e: - log_api("<= page.add_style_tag failed") - raise e + ) def expose_function(self, name: str, callback: typing.Callable) -> NoneType: """Page.expose_function @@ -6377,20 +5340,13 @@ def run(playwright): Callback function which will be called in Playwright's context. """ - try: - log_api("=> page.expose_function started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.expose_function( - name=name, callback=self._wrap_handler(callback) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.expose_function( + name=name, callback=self._wrap_handler(callback) ) ) - log_api("<= page.expose_function succeded") - return result - except Exception as e: - log_api("<= page.expose_function failed") - raise e + ) def expose_binding( self, name: str, callback: typing.Callable, *, handle: bool = None @@ -6461,20 +5417,13 @@ def print(source, element): supported. When passing by value, multiple arguments are supported. """ - try: - log_api("=> page.expose_binding started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.expose_binding( - name=name, callback=self._wrap_handler(callback), handle=handle - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.expose_binding( + name=name, callback=self._wrap_handler(callback), handle=handle ) ) - log_api("<= page.expose_binding succeded") - return result - except Exception as e: - log_api("<= page.expose_binding failed") - raise e + ) def set_extra_http_headers(self, headers: typing.Dict[str, str]) -> NoneType: """Page.set_extra_http_headers @@ -6489,20 +5438,11 @@ def set_extra_http_headers(self, headers: typing.Dict[str, str]) -> NoneType: An object containing additional HTTP headers to be sent with every request. All header values must be strings. """ - try: - log_api("=> page.set_extra_http_headers started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.set_extra_http_headers( - headers=mapping.to_impl(headers) - ) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.set_extra_http_headers(headers=mapping.to_impl(headers)) ) - log_api("<= page.set_extra_http_headers succeded") - return result - except Exception as e: - log_api("<= page.set_extra_http_headers failed") - raise e + ) def content(self) -> str: """Page.content @@ -6514,14 +5454,7 @@ def content(self) -> str: str """ - try: - log_api("=> page.content started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.content())) - log_api("<= page.content succeded") - return result - except Exception as e: - log_api("<= page.content failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.content())) def set_content( self, @@ -6548,20 +5481,13 @@ def set_content( - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. """ - try: - log_api("=> page.set_content started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.set_content( - html=html, timeout=timeout, waitUntil=wait_until - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.set_content( + html=html, timeout=timeout, waitUntil=wait_until ) ) - log_api("<= page.set_content succeded") - return result - except Exception as e: - log_api("<= page.set_content failed") - raise e + ) def goto( self, @@ -6617,20 +5543,13 @@ def goto( Union[Response, NoneType] """ - try: - log_api("=> page.goto started") - result = mapping.from_impl_nullable( - self._sync( - self._impl_obj.goto( - url=url, timeout=timeout, waitUntil=wait_until, referer=referer - ) + return mapping.from_impl_nullable( + self._sync( + self._impl_obj.goto( + url=url, timeout=timeout, waitUntil=wait_until, referer=referer ) ) - log_api("<= page.goto succeded") - return result - except Exception as e: - log_api("<= page.goto failed") - raise e + ) def reload( self, @@ -6661,16 +5580,9 @@ def reload( Union[Response, NoneType] """ - try: - log_api("=> page.reload started") - result = mapping.from_impl_nullable( - self._sync(self._impl_obj.reload(timeout=timeout, waitUntil=wait_until)) - ) - log_api("<= page.reload succeded") - return result - except Exception as e: - log_api("<= page.reload failed") - raise e + return mapping.from_impl_nullable( + self._sync(self._impl_obj.reload(timeout=timeout, waitUntil=wait_until)) + ) def wait_for_load_state( self, @@ -6716,18 +5628,9 @@ def wait_for_load_state( `page.set_default_timeout()` methods. """ - try: - log_api("=> page.wait_for_load_state started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.wait_for_load_state(state=state, timeout=timeout) - ) - ) - log_api("<= page.wait_for_load_state succeded") - return result - except Exception as e: - log_api("<= page.wait_for_load_state failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.wait_for_load_state(state=state, timeout=timeout)) + ) def wait_for_event( self, event: str, predicate: typing.Callable = None, *, timeout: float = None @@ -6755,22 +5658,15 @@ def wait_for_event( Any """ - try: - log_api("=> page.wait_for_event started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.wait_for_event( - event=event, - predicate=self._wrap_handler(predicate), - timeout=timeout, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.wait_for_event( + event=event, + predicate=self._wrap_handler(predicate), + timeout=timeout, ) ) - log_api("<= page.wait_for_event succeded") - return result - except Exception as e: - log_api("<= page.wait_for_event failed") - raise e + ) def go_back( self, @@ -6803,18 +5699,9 @@ def go_back( Union[Response, NoneType] """ - try: - log_api("=> page.go_back started") - result = mapping.from_impl_nullable( - self._sync( - self._impl_obj.go_back(timeout=timeout, waitUntil=wait_until) - ) - ) - log_api("<= page.go_back succeded") - return result - except Exception as e: - log_api("<= page.go_back failed") - raise e + return mapping.from_impl_nullable( + self._sync(self._impl_obj.go_back(timeout=timeout, waitUntil=wait_until)) + ) def go_forward( self, @@ -6847,18 +5734,9 @@ def go_forward( Union[Response, NoneType] """ - try: - log_api("=> page.go_forward started") - result = mapping.from_impl_nullable( - self._sync( - self._impl_obj.go_forward(timeout=timeout, waitUntil=wait_until) - ) - ) - log_api("<= page.go_forward succeded") - return result - except Exception as e: - log_api("<= page.go_forward failed") - raise e + return mapping.from_impl_nullable( + self._sync(self._impl_obj.go_forward(timeout=timeout, waitUntil=wait_until)) + ) def emulate_media( self, @@ -6906,18 +5784,11 @@ def emulate_media( `null` disables color scheme emulation. """ - try: - log_api("=> page.emulate_media started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.emulate_media(media=media, colorScheme=color_scheme) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.emulate_media(media=media, colorScheme=color_scheme) ) - log_api("<= page.emulate_media succeded") - return result - except Exception as e: - log_api("<= page.emulate_media failed") - raise e + ) def set_viewport_size(self, viewport_size: ViewportSize) -> NoneType: """Page.set_viewport_size @@ -6939,16 +5810,9 @@ def set_viewport_size(self, viewport_size: ViewportSize) -> NoneType: viewport_size : {width: int, height: int} """ - try: - log_api("=> page.set_viewport_size started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.set_viewport_size(viewportSize=viewport_size)) - ) - log_api("<= page.set_viewport_size succeded") - return result - except Exception as e: - log_api("<= page.set_viewport_size failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.set_viewport_size(viewportSize=viewport_size)) + ) def bring_to_front(self) -> NoneType: """Page.bring_to_front @@ -6956,16 +5820,7 @@ def bring_to_front(self) -> NoneType: Brings page to front (activates tab). """ - try: - log_api("=> page.bring_to_front started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.bring_to_front()) - ) - log_api("<= page.bring_to_front succeded") - return result - except Exception as e: - log_api("<= page.bring_to_front failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.bring_to_front())) def add_init_script( self, script: str = None, *, path: typing.Union[str, pathlib.Path] = None @@ -6993,21 +5848,15 @@ def add_init_script( Parameters ---------- script : Union[str, NoneType] + Script to be evaluated in all pages in the browser context. Optional. path : Union[pathlib.Path, str, NoneType] Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional. """ - try: - log_api("=> page.add_init_script started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.add_init_script(script=script, path=path)) - ) - log_api("<= page.add_init_script succeded") - return result - except Exception as e: - log_api("<= page.add_init_script failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.add_init_script(script=script, path=path)) + ) def route( self, @@ -7056,20 +5905,13 @@ def route( handler function to route the request. """ - try: - log_api("=> page.route started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.route( - url=self._wrap_handler(url), handler=self._wrap_handler(handler) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.route( + url=self._wrap_handler(url), handler=self._wrap_handler(handler) ) ) - log_api("<= page.route succeded") - return result - except Exception as e: - log_api("<= page.route failed") - raise e + ) def unroute( self, @@ -7091,20 +5933,13 @@ def unroute( Optional handler function to route the request. """ - try: - log_api("=> page.unroute started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.unroute( - url=self._wrap_handler(url), handler=self._wrap_handler(handler) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.unroute( + url=self._wrap_handler(url), handler=self._wrap_handler(handler) ) ) - log_api("<= page.unroute succeded") - return result - except Exception as e: - log_api("<= page.unroute failed") - raise e + ) def screenshot( self, @@ -7151,26 +5986,19 @@ def screenshot( bytes """ - try: - log_api("=> page.screenshot started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.screenshot( - timeout=timeout, - type=type, - path=path, - quality=quality, - omitBackground=omit_background, - fullPage=full_page, - clip=clip, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.screenshot( + timeout=timeout, + type=type, + path=path, + quality=quality, + omitBackground=omit_background, + fullPage=full_page, + clip=clip, ) ) - log_api("<= page.screenshot succeded") - return result - except Exception as e: - log_api("<= page.screenshot failed") - raise e + ) def title(self) -> str: """Page.title @@ -7182,14 +6010,7 @@ def title(self) -> str: str """ - try: - log_api("=> page.title started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.title())) - log_api("<= page.title succeded") - return result - except Exception as e: - log_api("<= page.title failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.title())) def close(self, *, run_before_unload: bool = None) -> NoneType: """Page.close @@ -7209,16 +6030,9 @@ def close(self, *, run_before_unload: bool = None) -> NoneType: [before unload](https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload) page handlers. """ - try: - log_api("=> page.close started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.close(runBeforeUnload=run_before_unload)) - ) - log_api("<= page.close succeded") - return result - except Exception as e: - log_api("<= page.close failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.close(runBeforeUnload=run_before_unload)) + ) def is_closed(self) -> bool: """Page.is_closed @@ -7230,14 +6044,7 @@ def is_closed(self) -> bool: bool """ - try: - log_api("=> page.is_closed started") - result = mapping.from_maybe_impl(self._impl_obj.is_closed()) - log_api("<= page.is_closed succeded") - return result - except Exception as e: - log_api("<= page.is_closed failed") - raise e + return mapping.from_maybe_impl(self._impl_obj.is_closed()) def click( self, @@ -7297,28 +6104,21 @@ def click( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.click started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.click( - selector=selector, - modifiers=modifiers, - position=position, - delay=delay, - button=button, - clickCount=click_count, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.click( + selector=selector, + modifiers=modifiers, + position=position, + delay=delay, + button=button, + clickCount=click_count, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) ) - log_api("<= page.click succeded") - return result - except Exception as e: - log_api("<= page.click failed") - raise e + ) def dblclick( self, @@ -7378,27 +6178,20 @@ def dblclick( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.dblclick started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.dblclick( - selector=selector, - modifiers=modifiers, - position=position, - delay=delay, - button=button, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.dblclick( + selector=selector, + modifiers=modifiers, + position=position, + delay=delay, + button=button, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) ) - log_api("<= page.dblclick succeded") - return result - except Exception as e: - log_api("<= page.dblclick failed") - raise e + ) def tap( self, @@ -7451,25 +6244,18 @@ def tap( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.tap started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.tap( - selector=selector, - modifiers=modifiers, - position=position, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.tap( + selector=selector, + modifiers=modifiers, + position=position, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) ) - log_api("<= page.tap succeded") - return result - except Exception as e: - log_api("<= page.tap failed") - raise e + ) def fill( self, @@ -7507,23 +6293,16 @@ def fill( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.fill started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.fill( - selector=selector, - value=value, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.fill( + selector=selector, + value=value, + timeout=timeout, + noWaitAfter=no_wait_after, ) ) - log_api("<= page.fill succeded") - return result - except Exception as e: - log_api("<= page.fill failed") - raise e + ) def focus(self, selector: str, *, timeout: float = None) -> NoneType: """Page.focus @@ -7543,16 +6322,9 @@ def focus(self, selector: str, *, timeout: float = None) -> NoneType: using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ - try: - log_api("=> page.focus started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.focus(selector=selector, timeout=timeout)) - ) - log_api("<= page.focus succeded") - return result - except Exception as e: - log_api("<= page.focus failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.focus(selector=selector, timeout=timeout)) + ) def text_content( self, selector: str, *, timeout: float = None @@ -7575,18 +6347,9 @@ def text_content( Union[str, NoneType] """ - try: - log_api("=> page.text_content started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.text_content(selector=selector, timeout=timeout) - ) - ) - log_api("<= page.text_content succeded") - return result - except Exception as e: - log_api("<= page.text_content failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.text_content(selector=selector, timeout=timeout)) + ) def inner_text(self, selector: str, *, timeout: float = None) -> str: """Page.inner_text @@ -7607,18 +6370,9 @@ def inner_text(self, selector: str, *, timeout: float = None) -> str: str """ - try: - log_api("=> page.inner_text started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.inner_text(selector=selector, timeout=timeout) - ) - ) - log_api("<= page.inner_text succeded") - return result - except Exception as e: - log_api("<= page.inner_text failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.inner_text(selector=selector, timeout=timeout)) + ) def inner_html(self, selector: str, *, timeout: float = None) -> str: """Page.inner_html @@ -7639,18 +6393,9 @@ def inner_html(self, selector: str, *, timeout: float = None) -> str: str """ - try: - log_api("=> page.inner_html started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.inner_html(selector=selector, timeout=timeout) - ) - ) - log_api("<= page.inner_html succeded") - return result - except Exception as e: - log_api("<= page.inner_html failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.inner_html(selector=selector, timeout=timeout)) + ) def get_attribute( self, selector: str, name: str, *, timeout: float = None @@ -7675,20 +6420,13 @@ def get_attribute( Union[str, NoneType] """ - try: - log_api("=> page.get_attribute started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.get_attribute( - selector=selector, name=name, timeout=timeout - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.get_attribute( + selector=selector, name=name, timeout=timeout ) ) - log_api("<= page.get_attribute succeded") - return result - except Exception as e: - log_api("<= page.get_attribute failed") - raise e + ) def hover( self, @@ -7734,24 +6472,17 @@ def hover( Whether to bypass the [actionability](./actionability.md) checks. Defaults to `false`. """ - try: - log_api("=> page.hover started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.hover( - selector=selector, - modifiers=modifiers, - position=position, - timeout=timeout, - force=force, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.hover( + selector=selector, + modifiers=modifiers, + position=position, + timeout=timeout, + force=force, ) ) - log_api("<= page.hover succeded") - return result - except Exception as e: - log_api("<= page.hover failed") - raise e + ) def select_option( self, @@ -7812,26 +6543,19 @@ def select_option( List[str] """ - try: - log_api("=> page.select_option started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.select_option( - selector=selector, - value=value, - index=index, - label=label, - element=mapping.to_impl(element), - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.select_option( + selector=selector, + value=value, + index=index, + label=label, + element=mapping.to_impl(element), + timeout=timeout, + noWaitAfter=no_wait_after, ) ) - log_api("<= page.select_option succeded") - return result - except Exception as e: - log_api("<= page.select_option failed") - raise e + ) def set_input_files( self, @@ -7870,23 +6594,16 @@ def set_input_files( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.set_input_files started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.set_input_files( - selector=selector, - files=files, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.set_input_files( + selector=selector, + files=files, + timeout=timeout, + noWaitAfter=no_wait_after, ) ) - log_api("<= page.set_input_files succeded") - return result - except Exception as e: - log_api("<= page.set_input_files failed") - raise e + ) def type( self, @@ -7929,24 +6646,17 @@ def type( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.type started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.type( - selector=selector, - text=text, - delay=delay, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.type( + selector=selector, + text=text, + delay=delay, + timeout=timeout, + noWaitAfter=no_wait_after, ) ) - log_api("<= page.type succeded") - return result - except Exception as e: - log_api("<= page.type failed") - raise e + ) def press( self, @@ -8008,24 +6718,17 @@ def press( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.press started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.press( - selector=selector, - key=key, - delay=delay, - timeout=timeout, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.press( + selector=selector, + key=key, + delay=delay, + timeout=timeout, + noWaitAfter=no_wait_after, ) ) - log_api("<= page.press succeded") - return result - except Exception as e: - log_api("<= page.press failed") - raise e + ) def check( self, @@ -8069,23 +6772,16 @@ def check( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.check started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.check( - selector=selector, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.check( + selector=selector, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) ) - log_api("<= page.check succeded") - return result - except Exception as e: - log_api("<= page.check failed") - raise e + ) def uncheck( self, @@ -8129,23 +6825,16 @@ def uncheck( inaccessible pages. Defaults to `false`. """ - try: - log_api("=> page.uncheck started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.uncheck( - selector=selector, - timeout=timeout, - force=force, - noWaitAfter=no_wait_after, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.uncheck( + selector=selector, + timeout=timeout, + force=force, + noWaitAfter=no_wait_after, ) ) - log_api("<= page.uncheck succeded") - return result - except Exception as e: - log_api("<= page.uncheck failed") - raise e + ) def wait_for_timeout(self, timeout: float) -> NoneType: """Page.wait_for_timeout @@ -8168,16 +6857,9 @@ def wait_for_timeout(self, timeout: float) -> NoneType: A timeout to wait for """ - try: - log_api("=> page.wait_for_timeout started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.wait_for_timeout(timeout=timeout)) - ) - log_api("<= page.wait_for_timeout succeded") - return result - except Exception as e: - log_api("<= page.wait_for_timeout failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.wait_for_timeout(timeout=timeout)) + ) def wait_for_function( self, @@ -8223,7 +6905,7 @@ def run(playwright): JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression. arg : Union[Any, NoneType] - Optional argument to pass to `expression` + Optional argument to pass to `expression`. timeout : Union[float, NoneType] maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_timeout()`. @@ -8236,23 +6918,16 @@ def run(playwright): JSHandle """ - try: - log_api("=> page.wait_for_function started") - result = mapping.from_impl( - self._sync( - self._impl_obj.wait_for_function( - expression=expression, - arg=mapping.to_impl(arg), - timeout=timeout, - polling=polling, - ) + return mapping.from_impl( + self._sync( + self._impl_obj.wait_for_function( + expression=expression, + arg=mapping.to_impl(arg), + timeout=timeout, + polling=polling, ) ) - log_api("<= page.wait_for_function succeded") - return result - except Exception as e: - log_api("<= page.wait_for_function failed") - raise e + ) def pause(self) -> NoneType: """Page.pause @@ -8263,18 +6938,11 @@ def pause(self) -> NoneType: User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from the place it was paused. - > NOTE: This method requires Playwright to be started in a headed mode, with a falsy [`options: headless`] value in the + > NOTE: This method requires Playwright to be started in a headed mode, with a falsy `headless` value in the `browser_type.launch()`. """ - try: - log_api("=> page.pause started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.pause())) - log_api("<= page.pause succeded") - return result - except Exception as e: - log_api("<= page.pause failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.pause())) def pdf( self, @@ -8383,32 +7051,25 @@ def pdf( bytes """ - try: - log_api("=> page.pdf started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.pdf( - scale=scale, - displayHeaderFooter=display_header_footer, - headerTemplate=header_template, - footerTemplate=footer_template, - printBackground=print_background, - landscape=landscape, - pageRanges=page_ranges, - format=format, - width=width, - height=height, - preferCSSPageSize=prefer_css_page_size, - margin=margin, - path=path, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.pdf( + scale=scale, + displayHeaderFooter=display_header_footer, + headerTemplate=header_template, + footerTemplate=footer_template, + printBackground=print_background, + landscape=landscape, + pageRanges=page_ranges, + format=format, + width=width, + height=height, + preferCSSPageSize=prefer_css_page_size, + margin=margin, + path=path, ) ) - log_api("<= page.pdf succeded") - return result - except Exception as e: - log_api("<= page.pdf failed") - raise e + ) def expect_event( self, event: str, predicate: typing.Callable = None, *, timeout: float = None @@ -8453,9 +7114,9 @@ def expect_console_message( ) -> EventContextManager["ConsoleMessage"]: """Page.expect_console_message - Performs action and waits for `console` event to fire. If predicate is provided, it passes `ConsoleMessage` value into - the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is - closed before the worker event is fired. + Performs action and waits for a [ConoleMessage] to be logged by in the page. If predicate is provided, it passes + `ConsoleMessage` value into the `predicate` function and waits for `predicate(message)` to return a truthy value. Will + throw an error if the page is closed before the console event is fired. Parameters ---------- @@ -8484,8 +7145,8 @@ def expect_download( ) -> EventContextManager["Download"]: """Page.expect_download - Performs action and waits for `download` event to fire. If predicate is provided, it passes `Download` value into the - `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is + Performs action and waits for a new `Download`. If predicate is provided, it passes `Download` value into the + `predicate` function and waits for `predicate(download)` to return a truthy value. Will throw an error if the page is closed before the download event is fired. Parameters @@ -8515,9 +7176,9 @@ def expect_file_chooser( ) -> EventContextManager["FileChooser"]: """Page.expect_file_chooser - Performs action and waits for `filechooser` event to fire. If predicate is provided, it passes `FileChooser` value into - the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is - closed before the worker event is fired. + Performs action and waits for a new `FileChooser` to be created. If predicate is provided, it passes `FileChooser` value + into the `predicate` function and waits for `predicate(fileChooser)` to return a truthy value. Will throw an error if + the page is closed before the file chooser is opened. Parameters ---------- @@ -8600,14 +7261,14 @@ def expect_popup( ) -> EventContextManager["Page"]: """Page.expect_popup - Performs action and waits for `popup` event to fire. If predicate is provided, it passes [Popup] value into the - `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is - closed before the popup event is fired. + Performs action and waits for a popup `Page`. If predicate is provided, it passes [Popup] value into the `predicate` + function and waits for `predicate(page)` to return a truthy value. Will throw an error if the page is closed before the + popup event is fired. Parameters ---------- predicate : Union[Callable[[Page], bool], NoneType] - Receives the [Popup] object and resolves to truthy value when the waiting should resolve. + Receives the `Page` object and resolves to truthy value when the waiting should resolve. timeout : Union[float, NoneType] Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_timeout()`. @@ -8709,9 +7370,9 @@ def expect_worker( ) -> EventContextManager["Worker"]: """Page.expect_worker - Performs action and waits for `worker` event to fire. If predicate is provided, it passes `Worker` value into the - `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is - closed before the worker event is fired. + Performs action and waits for a new `Worker`. If predicate is provided, it passes `Worker` value into the `predicate` + function and waits for `predicate(worker)` to return a truthy value. Will throw an error if the page is closed before + the worker event is fired. Parameters ---------- @@ -8785,16 +7446,9 @@ def set_default_navigation_timeout(self, timeout: float) -> NoneType: Maximum navigation time in milliseconds """ - try: - log_api("=> browser_context.set_default_navigation_timeout started") - result = mapping.from_maybe_impl( - self._impl_obj.set_default_navigation_timeout(timeout=timeout) - ) - log_api("<= browser_context.set_default_navigation_timeout succeded") - return result - except Exception as e: - log_api("<= browser_context.set_default_navigation_timeout failed") - raise e + return mapping.from_maybe_impl( + self._impl_obj.set_default_navigation_timeout(timeout=timeout) + ) def set_default_timeout(self, timeout: float) -> NoneType: """BrowserContext.set_default_timeout @@ -8810,16 +7464,9 @@ def set_default_timeout(self, timeout: float) -> NoneType: Maximum time in milliseconds """ - try: - log_api("=> browser_context.set_default_timeout started") - result = mapping.from_maybe_impl( - self._impl_obj.set_default_timeout(timeout=timeout) - ) - log_api("<= browser_context.set_default_timeout succeded") - return result - except Exception as e: - log_api("<= browser_context.set_default_timeout failed") - raise e + return mapping.from_maybe_impl( + self._impl_obj.set_default_timeout(timeout=timeout) + ) def new_page(self) -> "Page": """BrowserContext.new_page @@ -8831,14 +7478,7 @@ def new_page(self) -> "Page": Page """ - try: - log_api("=> browser_context.new_page started") - result = mapping.from_impl(self._sync(self._impl_obj.new_page())) - log_api("<= browser_context.new_page succeded") - return result - except Exception as e: - log_api("<= browser_context.new_page failed") - raise e + return mapping.from_impl(self._sync(self._impl_obj.new_page())) def cookies( self, urls: typing.Union[str, typing.List[str]] = None @@ -8858,16 +7498,7 @@ def cookies( List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}] """ - try: - log_api("=> browser_context.cookies started") - result = mapping.from_impl_list( - self._sync(self._impl_obj.cookies(urls=urls)) - ) - log_api("<= browser_context.cookies succeded") - return result - except Exception as e: - log_api("<= browser_context.cookies failed") - raise e + return mapping.from_impl_list(self._sync(self._impl_obj.cookies(urls=urls))) def add_cookies(self, cookies: typing.List[Cookie]) -> NoneType: """BrowserContext.add_cookies @@ -8884,16 +7515,9 @@ def add_cookies(self, cookies: typing.List[Cookie]) -> NoneType: cookies : List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}] """ - try: - log_api("=> browser_context.add_cookies started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.add_cookies(cookies=cookies)) - ) - log_api("<= browser_context.add_cookies succeded") - return result - except Exception as e: - log_api("<= browser_context.add_cookies failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.add_cookies(cookies=cookies)) + ) def clear_cookies(self) -> NoneType: """BrowserContext.clear_cookies @@ -8901,14 +7525,7 @@ def clear_cookies(self) -> NoneType: Clears context cookies. """ - try: - log_api("=> browser_context.clear_cookies started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.clear_cookies())) - log_api("<= browser_context.clear_cookies succeded") - return result - except Exception as e: - log_api("<= browser_context.clear_cookies failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.clear_cookies())) def grant_permissions( self, permissions: typing.List[str], *, origin: str = None @@ -8942,20 +7559,11 @@ def grant_permissions( The [origin] to grant permissions to, e.g. "https://example.com". """ - try: - log_api("=> browser_context.grant_permissions started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.grant_permissions( - permissions=permissions, origin=origin - ) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.grant_permissions(permissions=permissions, origin=origin) ) - log_api("<= browser_context.grant_permissions succeded") - return result - except Exception as e: - log_api("<= browser_context.grant_permissions failed") - raise e + ) def clear_permissions(self) -> NoneType: """BrowserContext.clear_permissions @@ -8970,16 +7578,7 @@ def clear_permissions(self) -> NoneType: ``` """ - try: - log_api("=> browser_context.clear_permissions started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.clear_permissions()) - ) - log_api("<= browser_context.clear_permissions succeded") - return result - except Exception as e: - log_api("<= browser_context.clear_permissions failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.clear_permissions())) def set_geolocation(self, geolocation: Geolocation = None) -> NoneType: """BrowserContext.set_geolocation @@ -8998,16 +7597,9 @@ def set_geolocation(self, geolocation: Geolocation = None) -> NoneType: geolocation : Union[{latitude: float, longitude: float, accuracy: Union[float, NoneType]}, NoneType] """ - try: - log_api("=> browser_context.set_geolocation started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.set_geolocation(geolocation=geolocation)) - ) - log_api("<= browser_context.set_geolocation succeded") - return result - except Exception as e: - log_api("<= browser_context.set_geolocation failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.set_geolocation(geolocation=geolocation)) + ) def set_extra_http_headers(self, headers: typing.Dict[str, str]) -> NoneType: """BrowserContext.set_extra_http_headers @@ -9024,20 +7616,11 @@ def set_extra_http_headers(self, headers: typing.Dict[str, str]) -> NoneType: An object containing additional HTTP headers to be sent with every request. All header values must be strings. """ - try: - log_api("=> browser_context.set_extra_http_headers started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.set_extra_http_headers( - headers=mapping.to_impl(headers) - ) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.set_extra_http_headers(headers=mapping.to_impl(headers)) ) - log_api("<= browser_context.set_extra_http_headers succeded") - return result - except Exception as e: - log_api("<= browser_context.set_extra_http_headers failed") - raise e + ) def set_offline(self, offline: bool) -> NoneType: """BrowserContext.set_offline @@ -9048,16 +7631,9 @@ def set_offline(self, offline: bool) -> NoneType: Whether to emulate network being offline for the browser context. """ - try: - log_api("=> browser_context.set_offline started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.set_offline(offline=offline)) - ) - log_api("<= browser_context.set_offline succeded") - return result - except Exception as e: - log_api("<= browser_context.set_offline failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.set_offline(offline=offline)) + ) def add_init_script( self, script: str = None, *, path: typing.Union[str, pathlib.Path] = None @@ -9085,21 +7661,15 @@ def add_init_script( Parameters ---------- script : Union[str, NoneType] + Script to be evaluated in all pages in the browser context. Optional. path : Union[pathlib.Path, str, NoneType] Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional. """ - try: - log_api("=> browser_context.add_init_script started") - result = mapping.from_maybe_impl( - self._sync(self._impl_obj.add_init_script(script=script, path=path)) - ) - log_api("<= browser_context.add_init_script succeded") - return result - except Exception as e: - log_api("<= browser_context.add_init_script failed") - raise e + return mapping.from_maybe_impl( + self._sync(self._impl_obj.add_init_script(script=script, path=path)) + ) def expose_binding( self, name: str, callback: typing.Callable, *, handle: bool = None @@ -9168,20 +7738,13 @@ def print(source, element): supported. When passing by value, multiple arguments are supported. """ - try: - log_api("=> browser_context.expose_binding started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.expose_binding( - name=name, callback=self._wrap_handler(callback), handle=handle - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.expose_binding( + name=name, callback=self._wrap_handler(callback), handle=handle ) ) - log_api("<= browser_context.expose_binding succeded") - return result - except Exception as e: - log_api("<= browser_context.expose_binding failed") - raise e + ) def expose_function(self, name: str, callback: typing.Callable) -> NoneType: """BrowserContext.expose_function @@ -9234,20 +7797,13 @@ def run(playwright): Callback function that will be called in the Playwright's context. """ - try: - log_api("=> browser_context.expose_function started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.expose_function( - name=name, callback=self._wrap_handler(callback) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.expose_function( + name=name, callback=self._wrap_handler(callback) ) ) - log_api("<= browser_context.expose_function succeded") - return result - except Exception as e: - log_api("<= browser_context.expose_function failed") - raise e + ) def route( self, @@ -9297,20 +7853,13 @@ def route( handler function to route the request. """ - try: - log_api("=> browser_context.route started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.route( - url=self._wrap_handler(url), handler=self._wrap_handler(handler) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.route( + url=self._wrap_handler(url), handler=self._wrap_handler(handler) ) ) - log_api("<= browser_context.route succeded") - return result - except Exception as e: - log_api("<= browser_context.route failed") - raise e + ) def unroute( self, @@ -9334,20 +7883,13 @@ def unroute( Optional handler function used to register a routing with `browser_context.route()`. """ - try: - log_api("=> browser_context.unroute started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.unroute( - url=self._wrap_handler(url), handler=self._wrap_handler(handler) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.unroute( + url=self._wrap_handler(url), handler=self._wrap_handler(handler) ) ) - log_api("<= browser_context.unroute succeded") - return result - except Exception as e: - log_api("<= browser_context.unroute failed") - raise e + ) def expect_event( self, event: str, predicate: typing.Callable = None, *, timeout: float = None @@ -9392,14 +7934,7 @@ def close(self) -> NoneType: > NOTE: The default browser context cannot be closed. """ - try: - log_api("=> browser_context.close started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.close())) - log_api("<= browser_context.close succeded") - return result - except Exception as e: - log_api("<= browser_context.close failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.close())) def storage_state( self, *, path: typing.Union[str, pathlib.Path] = None @@ -9419,16 +7954,7 @@ def storage_state( {cookies: Union[List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}], NoneType], origins: Union[List[{origin: str, localStorage: List[{name: str, value: str}]}], NoneType]} """ - try: - log_api("=> browser_context.storage_state started") - result = mapping.from_impl( - self._sync(self._impl_obj.storage_state(path=path)) - ) - log_api("<= browser_context.storage_state succeded") - return result - except Exception as e: - log_api("<= browser_context.storage_state failed") - raise e + return mapping.from_impl(self._sync(self._impl_obj.storage_state(path=path))) def wait_for_event( self, event: str, predicate: typing.Callable = None, *, timeout: float = None @@ -9456,22 +7982,15 @@ def wait_for_event( Any """ - try: - log_api("=> browser_context.wait_for_event started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.wait_for_event( - event=event, - predicate=self._wrap_handler(predicate), - timeout=timeout, - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.wait_for_event( + event=event, + predicate=self._wrap_handler(predicate), + timeout=timeout, ) ) - log_api("<= browser_context.wait_for_event succeded") - return result - except Exception as e: - log_api("<= browser_context.wait_for_event failed") - raise e + ) def expect_page( self, @@ -9481,9 +8000,9 @@ def expect_page( ) -> EventContextManager["Page"]: """BrowserContext.expect_page - Performs action and waits for `page` event to fire. If predicate is provided, it passes `Page` value into the - `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is - closed before the worker event is fired. + Performs action and waits for a new `Page` to be created in the context. If predicate is provided, it passes `Page` + value into the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if + the context closes before new `Page` is created. Parameters ---------- @@ -9527,18 +8046,11 @@ def send(self, method: str, params: typing.Dict = None) -> typing.Dict: Dict """ - try: - log_api("=> cdp_session.send started") - result = mapping.from_maybe_impl( - self._sync( - self._impl_obj.send(method=method, params=mapping.to_impl(params)) - ) + return mapping.from_maybe_impl( + self._sync( + self._impl_obj.send(method=method, params=mapping.to_impl(params)) ) - log_api("<= cdp_session.send succeded") - return result - except Exception as e: - log_api("<= cdp_session.send failed") - raise e + ) def detach(self) -> NoneType: """CDPSession.detach @@ -9547,14 +8059,7 @@ def detach(self) -> NoneType: send messages. """ - try: - log_api("=> cdp_session.detach started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.detach())) - log_api("<= cdp_session.detach succeded") - return result - except Exception as e: - log_api("<= cdp_session.detach failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.detach())) mapping.register(CDPSessionImpl, CDPSession) @@ -9603,16 +8108,9 @@ def new_cdp_session(self, page: "Page") -> "CDPSession": CDPSession """ - try: - log_api("=> chromium_browser_context.new_cdp_session started") - result = mapping.from_impl( - self._sync(self._impl_obj.new_cdp_session(page=page._impl_obj)) - ) - log_api("<= chromium_browser_context.new_cdp_session succeded") - return result - except Exception as e: - log_api("<= chromium_browser_context.new_cdp_session failed") - raise e + return mapping.from_impl( + self._sync(self._impl_obj.new_cdp_session(page=page._impl_obj)) + ) mapping.register(ChromiumBrowserContextImpl, ChromiumBrowserContext) @@ -9663,14 +8161,7 @@ def is_connected(self) -> bool: bool """ - try: - log_api("=> browser.is_connected started") - result = mapping.from_maybe_impl(self._impl_obj.is_connected()) - log_api("<= browser.is_connected succeded") - return result - except Exception as e: - log_api("<= browser.is_connected failed") - raise e + return mapping.from_maybe_impl(self._impl_obj.is_connected()) def new_context( self, @@ -9768,7 +8259,9 @@ def new_context( record_video_dir : Union[pathlib.Path, str, NoneType] Path to the directory to put videos into. record_video_size : Union[{width: int, height: int}, NoneType] - Optional dimensions of the recorded videos. If not specified the size will be equal to `viewport`. + Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into + 800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will + be scaled down if necessary to fit the specified size. storage_state : Union[pathlib.Path, str, {cookies: Union[List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}], NoneType], origins: Union[List[{origin: str, localStorage: List[{name: str, value: str}]}], NoneType]}, NoneType] Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via `browser_context.storage_state()`. Either a path to the file with saved storage, or an object with @@ -9779,44 +8272,37 @@ def new_context( BrowserContext """ - try: - log_api("=> browser.new_context started") - result = mapping.from_impl( - self._sync( - self._impl_obj.new_context( - viewport=viewport, - noViewport=no_viewport, - ignoreHTTPSErrors=ignore_https_errors, - javaScriptEnabled=java_script_enabled, - bypassCSP=bypass_csp, - userAgent=user_agent, - locale=locale, - timezoneId=timezone_id, - geolocation=geolocation, - permissions=permissions, - extraHTTPHeaders=mapping.to_impl(extra_http_headers), - offline=offline, - httpCredentials=http_credentials, - deviceScaleFactor=device_scale_factor, - isMobile=is_mobile, - hasTouch=has_touch, - colorScheme=color_scheme, - acceptDownloads=accept_downloads, - defaultBrowserType=default_browser_type, - proxy=proxy, - recordHarPath=record_har_path, - recordHarOmitContent=record_har_omit_content, - recordVideoDir=record_video_dir, - recordVideoSize=record_video_size, - storageState=storage_state, - ) + return mapping.from_impl( + self._sync( + self._impl_obj.new_context( + viewport=viewport, + noViewport=no_viewport, + ignoreHTTPSErrors=ignore_https_errors, + javaScriptEnabled=java_script_enabled, + bypassCSP=bypass_csp, + userAgent=user_agent, + locale=locale, + timezoneId=timezone_id, + geolocation=geolocation, + permissions=permissions, + extraHTTPHeaders=mapping.to_impl(extra_http_headers), + offline=offline, + httpCredentials=http_credentials, + deviceScaleFactor=device_scale_factor, + isMobile=is_mobile, + hasTouch=has_touch, + colorScheme=color_scheme, + acceptDownloads=accept_downloads, + defaultBrowserType=default_browser_type, + proxy=proxy, + recordHarPath=record_har_path, + recordHarOmitContent=record_har_omit_content, + recordVideoDir=record_video_dir, + recordVideoSize=record_video_size, + storageState=storage_state, ) ) - log_api("<= browser.new_context succeded") - return result - except Exception as e: - log_api("<= browser.new_context failed") - raise e + ) def new_page( self, @@ -9909,7 +8395,9 @@ def new_page( record_video_dir : Union[pathlib.Path, str, NoneType] Path to the directory to put videos into. record_video_size : Union[{width: int, height: int}, NoneType] - Optional dimensions of the recorded videos. If not specified the size will be equal to `viewport`. + Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into + 800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will + be scaled down if necessary to fit the specified size. storage_state : Union[pathlib.Path, str, {cookies: Union[List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}], NoneType], origins: Union[List[{origin: str, localStorage: List[{name: str, value: str}]}], NoneType]}, NoneType] Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via `browser_context.storage_state()`. Either a path to the file with saved storage, or an object with @@ -9920,44 +8408,37 @@ def new_page( Page """ - try: - log_api("=> browser.new_page started") - result = mapping.from_impl( - self._sync( - self._impl_obj.new_page( - viewport=viewport, - noViewport=no_viewport, - ignoreHTTPSErrors=ignore_https_errors, - javaScriptEnabled=java_script_enabled, - bypassCSP=bypass_csp, - userAgent=user_agent, - locale=locale, - timezoneId=timezone_id, - geolocation=geolocation, - permissions=permissions, - extraHTTPHeaders=mapping.to_impl(extra_http_headers), - offline=offline, - httpCredentials=http_credentials, - deviceScaleFactor=device_scale_factor, - isMobile=is_mobile, - hasTouch=has_touch, - colorScheme=color_scheme, - acceptDownloads=accept_downloads, - defaultBrowserType=default_browser_type, - proxy=proxy, - recordHarPath=record_har_path, - recordHarOmitContent=record_har_omit_content, - recordVideoDir=record_video_dir, - recordVideoSize=record_video_size, - storageState=storage_state, - ) + return mapping.from_impl( + self._sync( + self._impl_obj.new_page( + viewport=viewport, + noViewport=no_viewport, + ignoreHTTPSErrors=ignore_https_errors, + javaScriptEnabled=java_script_enabled, + bypassCSP=bypass_csp, + userAgent=user_agent, + locale=locale, + timezoneId=timezone_id, + geolocation=geolocation, + permissions=permissions, + extraHTTPHeaders=mapping.to_impl(extra_http_headers), + offline=offline, + httpCredentials=http_credentials, + deviceScaleFactor=device_scale_factor, + isMobile=is_mobile, + hasTouch=has_touch, + colorScheme=color_scheme, + acceptDownloads=accept_downloads, + defaultBrowserType=default_browser_type, + proxy=proxy, + recordHarPath=record_har_path, + recordHarOmitContent=record_har_omit_content, + recordVideoDir=record_video_dir, + recordVideoSize=record_video_size, + storageState=storage_state, ) ) - log_api("<= browser.new_page succeded") - return result - except Exception as e: - log_api("<= browser.new_page failed") - raise e + ) def close(self) -> NoneType: """Browser.close @@ -9971,14 +8452,7 @@ def close(self) -> NoneType: The `Browser` object itself is considered to be disposed and cannot be used anymore. """ - try: - log_api("=> browser.close started") - result = mapping.from_maybe_impl(self._sync(self._impl_obj.close())) - log_api("<= browser.close succeded") - return result - except Exception as e: - log_api("<= browser.close failed") - raise e + return mapping.from_maybe_impl(self._sync(self._impl_obj.close())) mapping.register(BrowserImpl, Browser) @@ -10045,19 +8519,19 @@ def launch( ) ``` - > **Chromium-only** Playwright can also be used to control the Chrome browser, but it works best with the version of - Chromium it is bundled with. There is no guarantee it will work with any other version. Use `executablePath` option with - extreme caution. + > **Chromium-only** Playwright can also be used to control the Google Chrome or Microsoft Edge browsers, but it works + best with the version of Chromium it is bundled with. There is no guarantee it will work with any other version. Use + `executablePath` option with extreme caution. > > If Google Chrome (rather than Chromium) is preferred, a [Chrome Canary](https://www.google.com/chrome/browser/canary.html) or [Dev Channel](https://www.chromium.org/getting-involved/dev-channel) build is suggested. > - > In `browser_type.launch()` above, any mention of Chromium also applies to Chrome. - > - > See [`this article`](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for - a description of the differences between Chromium and Chrome. - [`This article`](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md) + > Stock browsers like Google Chrome and Microsoft Edge are suitable for tests that require proprietary media codecs for + video playback. See + [this article](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for other + differences between Chromium and Chrome. + [This article](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md) describes some differences for Linux users. Parameters @@ -10109,34 +8583,27 @@ def launch( Browser """ - try: - log_api("=> browser_type.launch started") - result = mapping.from_impl( - self._sync( - self._impl_obj.launch( - executablePath=executable_path, - args=args, - ignoreDefaultArgs=ignore_default_args, - handleSIGINT=handle_sigint, - handleSIGTERM=handle_sigterm, - handleSIGHUP=handle_sighup, - timeout=timeout, - env=mapping.to_impl(env), - headless=headless, - devtools=devtools, - proxy=proxy, - downloadsPath=downloads_path, - slowMo=slow_mo, - chromiumSandbox=chromium_sandbox, - firefoxUserPrefs=mapping.to_impl(firefox_user_prefs), - ) + return mapping.from_impl( + self._sync( + self._impl_obj.launch( + executablePath=executable_path, + args=args, + ignoreDefaultArgs=ignore_default_args, + handleSIGINT=handle_sigint, + handleSIGTERM=handle_sigterm, + handleSIGHUP=handle_sighup, + timeout=timeout, + env=mapping.to_impl(env), + headless=headless, + devtools=devtools, + proxy=proxy, + downloadsPath=downloads_path, + slowMo=slow_mo, + chromiumSandbox=chromium_sandbox, + firefoxUserPrefs=mapping.to_impl(firefox_user_prefs), ) ) - log_api("<= browser_type.launch succeded") - return result - except Exception as e: - log_api("<= browser_type.launch failed") - raise e + ) def launch_persistent_context( self, @@ -10280,63 +8747,58 @@ def launch_persistent_context( record_video_dir : Union[pathlib.Path, str, NoneType] Path to the directory to put videos into. record_video_size : Union[{width: int, height: int}, NoneType] - Optional dimensions of the recorded videos. If not specified the size will be equal to `viewport`. + Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into + 800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will + be scaled down if necessary to fit the specified size. Returns ------- BrowserContext """ - try: - log_api("=> browser_type.launch_persistent_context started") - result = mapping.from_impl( - self._sync( - self._impl_obj.launch_persistent_context( - userDataDir=user_data_dir, - executablePath=executable_path, - args=args, - ignoreDefaultArgs=ignore_default_args, - handleSIGINT=handle_sigint, - handleSIGTERM=handle_sigterm, - handleSIGHUP=handle_sighup, - timeout=timeout, - env=mapping.to_impl(env), - headless=headless, - devtools=devtools, - proxy=proxy, - downloadsPath=downloads_path, - slowMo=slow_mo, - viewport=viewport, - noViewport=no_viewport, - ignoreHTTPSErrors=ignore_https_errors, - javaScriptEnabled=java_script_enabled, - bypassCSP=bypass_csp, - userAgent=user_agent, - locale=locale, - timezoneId=timezone_id, - geolocation=geolocation, - permissions=permissions, - extraHTTPHeaders=mapping.to_impl(extra_http_headers), - offline=offline, - httpCredentials=http_credentials, - deviceScaleFactor=device_scale_factor, - isMobile=is_mobile, - hasTouch=has_touch, - colorScheme=color_scheme, - acceptDownloads=accept_downloads, - chromiumSandbox=chromium_sandbox, - recordHarPath=record_har_path, - recordHarOmitContent=record_har_omit_content, - recordVideoDir=record_video_dir, - recordVideoSize=record_video_size, - ) + return mapping.from_impl( + self._sync( + self._impl_obj.launch_persistent_context( + userDataDir=user_data_dir, + executablePath=executable_path, + args=args, + ignoreDefaultArgs=ignore_default_args, + handleSIGINT=handle_sigint, + handleSIGTERM=handle_sigterm, + handleSIGHUP=handle_sighup, + timeout=timeout, + env=mapping.to_impl(env), + headless=headless, + devtools=devtools, + proxy=proxy, + downloadsPath=downloads_path, + slowMo=slow_mo, + viewport=viewport, + noViewport=no_viewport, + ignoreHTTPSErrors=ignore_https_errors, + javaScriptEnabled=java_script_enabled, + bypassCSP=bypass_csp, + userAgent=user_agent, + locale=locale, + timezoneId=timezone_id, + geolocation=geolocation, + permissions=permissions, + extraHTTPHeaders=mapping.to_impl(extra_http_headers), + offline=offline, + httpCredentials=http_credentials, + deviceScaleFactor=device_scale_factor, + isMobile=is_mobile, + hasTouch=has_touch, + colorScheme=color_scheme, + acceptDownloads=accept_downloads, + chromiumSandbox=chromium_sandbox, + recordHarPath=record_har_path, + recordHarOmitContent=record_har_omit_content, + recordVideoDir=record_video_dir, + recordVideoSize=record_video_size, ) ) - log_api("<= browser_type.launch_persistent_context succeded") - return result - except Exception as e: - log_api("<= browser_type.launch_persistent_context failed") - raise e + ) mapping.register(BrowserTypeImpl, BrowserType) @@ -10445,14 +8907,7 @@ def stop(self) -> NoneType: ``` """ - try: - log_api("=> playwright.stop started") - result = mapping.from_maybe_impl(self._impl_obj.stop()) - log_api("<= playwright.stop succeded") - return result - except Exception as e: - log_api("<= playwright.stop failed") - raise e + return mapping.from_maybe_impl(self._impl_obj.stop()) mapping.register(PlaywrightImpl, Playwright) diff --git a/scripts/generate_api.py b/scripts/generate_api.py index 31b16908d..8a8e08012 100644 --- a/scripts/generate_api.py +++ b/scripts/generate_api.py @@ -219,7 +219,6 @@ def return_value(value: Any) -> List[str]: from playwright._impl._playwright import Playwright as PlaywrightImpl from playwright._impl._selectors import Selectors as SelectorsImpl from playwright._impl._video import Video as VideoImpl -from playwright._impl._logger import log_api """ diff --git a/scripts/generate_async_api.py b/scripts/generate_async_api.py index 124229fb6..ff67fa5ab 100755 --- a/scripts/generate_async_api.py +++ b/scripts/generate_async_api.py @@ -18,7 +18,6 @@ from types import FunctionType from typing import Any, get_type_hints # type: ignore -from playwright._impl._helper import to_snake_case from scripts.documentation_provider import DocumentationProvider from scripts.generate_api import ( all_types, @@ -108,14 +107,7 @@ def generate(t: Any) -> None: suffix = ")" + suffix print( f""" - try: - log_api("=> {to_snake_case(class_name)}.{name} started") - result = {prefix}{arguments(value, len(prefix))}{suffix} - log_api("<= {to_snake_case(class_name)}.{name} succeded") - return result - except Exception as e: - log_api("<= {to_snake_case(class_name)}.{name} failed") - raise e""" + return {prefix}{arguments(value, len(prefix))}{suffix}""" ) print("") diff --git a/scripts/generate_sync_api.py b/scripts/generate_sync_api.py index 2b80a5e77..95b58c4ca 100755 --- a/scripts/generate_sync_api.py +++ b/scripts/generate_sync_api.py @@ -18,7 +18,6 @@ from types import FunctionType from typing import Any, get_type_hints # type: ignore -from playwright._impl._helper import to_snake_case from scripts.documentation_provider import DocumentationProvider from scripts.generate_api import ( all_types, @@ -107,14 +106,7 @@ def generate(t: Any) -> None: print( f""" - try: - log_api("=> {to_snake_case(class_name)}.{name} started") - result = {prefix}{arguments(value, len(prefix))}{suffix} - log_api("<= {to_snake_case(class_name)}.{name} succeded") - return result - except Exception as e: - log_api("<= {to_snake_case(class_name)}.{name} failed") - raise e""" + return {prefix}{arguments(value, len(prefix))}{suffix}""" ) print("") diff --git a/setup.py b/setup.py index f9d48dccc..c17ad618a 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ import setuptools from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand -driver_version = "1.9.0-next-1612400196000" +driver_version = "1.9.0-next-1613683796000" with open("README.md", "r", encoding="utf-8") as fh: diff --git a/tests/async/test_click.py b/tests/async/test_click.py index d45852b50..ae85b52b6 100644 --- a/tests/async/test_click.py +++ b/tests/async/test_click.py @@ -226,7 +226,7 @@ async def test_timeout_waiting_for_display_none_to_be_gone(page, server): except Error as e: error = e assert "Timeout 5000ms exceeded" in error.message - assert "waiting for element to be visible, enabled and not moving" in error.message + assert "waiting for element to be visible, enabled and stable" in error.message assert "element is not visible - waiting" in error.message @@ -238,7 +238,7 @@ async def test_timeout_waiting_for_visbility_hidden_to_be_gone(page, server): except Error as e: error = e assert "Timeout 5000ms exceeded" in error.message - assert "waiting for element to be visible, enabled and not moving" in error.message + assert "waiting for element to be visible, enabled and stable" in error.message assert "element is not visible - waiting" in error.message @@ -533,8 +533,8 @@ async def test_timeout_waiting_for_stable_position(page, server): except Error as e: error = e assert "Timeout 5000ms exceeded." in error.message - assert "waiting for element to be visible, enabled and not moving" in error.message - assert "element is moving - waiting" in error.message + assert "waiting for element to be visible, enabled and stable" in error.message + assert "element is not stable - waiting" in error.message async def test_wait_for_becoming_hit_target(page, server): @@ -654,7 +654,7 @@ async def test_timeout_waiting_for_button_to_be_enabled(page, server): error = e assert await page.evaluate("window.__CLICKED") is None assert "Timeout 3000ms exceeded" in error.message - assert "element is disabled - waiting" in error.message + assert "element is not enabled - waiting" in error.message async def test_wait_for_input_to_be_enabled(page, server):