diff --git a/api.json b/api.json index df57be420..807be6d17 100644 --- a/api.json +++ b/api.json @@ -9481,7 +9481,7 @@ "name": "string", "properties": {} }, - "comment": "URL of the resource if available.", + "comment": "Optional URL of the resource if available.", "returnComment": "", "required": false, "templates": [] @@ -9493,7 +9493,7 @@ "name": "number", "properties": {} }, - "comment": "0-based line number in the resource if available.", + "comment": "Optional 0-based line number in the resource if available.", "returnComment": "", "required": false, "templates": [] @@ -9505,7 +9505,7 @@ "name": "number", "properties": {} }, - "comment": "0-based column number in the resource if available.", + "comment": "Optional 0-based column number in the resource if available.", "returnComment": "", "required": false, "templates": [] @@ -9703,7 +9703,7 @@ "name": "string", "properties": {} }, - "comment": "Path where the download should be saved. The directory structure MUST exist as `saveAs` will not create it.", + "comment": "Path where the download should be saved.", "returnComment": "", "required": true, "templates": [] @@ -10632,7 +10632,7 @@ "kind": "method", "name": "headers", "type": { - "name": "Object", + "name": "Object", "properties": {} }, "comment": "", @@ -12216,7 +12216,7 @@ "kind": "property", "name": "viewport", "type": { - "name": "null|Object", + "name": "?Object", "properties": { "width": { "kind": "property", @@ -12358,7 +12358,7 @@ "name": "number", "properties": {} }, - "comment": "Non-negative accuracy value. Defaults to `0`.", + "comment": "Optional non-negative accuracy value. Defaults to `0`.", "returnComment": "", "required": false, "templates": [] diff --git a/playwright/accessibility.py b/playwright/accessibility.py index 7e4d5ed8d..ceefb1c1e 100644 --- a/playwright/accessibility.py +++ b/playwright/accessibility.py @@ -12,14 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Any, Dict, Optional +from typing import Dict, Optional from playwright.connection import Channel from playwright.element_handle import ElementHandle from playwright.helper import locals_to_params -def _ax_node_from_protocol(axNode: Dict[str, Any]) -> Dict[str, Any]: +def _ax_node_from_protocol(axNode: Dict) -> Dict: result = {**axNode} if "valueNumber" in axNode: result["value"] = axNode["valueNumber"] @@ -60,7 +60,7 @@ def __init__(self, channel: Channel) -> None: async def snapshot( self, interestingOnly: bool = None, root: ElementHandle = None - ) -> Optional[Dict[str, Any]]: + ) -> Optional[Dict]: params = locals_to_params(locals()) if root: params["root"] = root._channel diff --git a/playwright/async_api.py b/playwright/async_api.py index efbaa86a8..27942e4c3 100644 --- a/playwright/async_api.py +++ b/playwright/async_api.py @@ -40,9 +40,17 @@ from playwright.frame import Frame as FrameImpl from playwright.helper import ( ConsoleMessageLocation, + Credentials, DeviceDescriptor, Error, FilePayload, + FloatRect, + Geolocation, + IntSize, + MousePosition, + PdfMargins, + ProxyServer, + RequestFailure, SelectOption, Viewport, ) @@ -106,7 +114,7 @@ def postData(self) -> typing.Union[str, NoneType]: Returns ------- - typing.Union[str, NoneType] + Optional[str] Request's post body, if any. """ return mapping.from_maybe_impl(self._impl_obj.postData) @@ -117,7 +125,7 @@ def headers(self) -> typing.Dict[str, str]: Returns ------- - typing.Dict[str, str] + Dict[str, str] An object with HTTP headers associated with the request. All header names are lower-case. """ return mapping.from_maybe_impl(self._impl_obj.headers) @@ -143,7 +151,7 @@ def redirectedFrom(self) -> typing.Union["Request", NoneType]: Returns ------- - typing.Union[Request, NoneType] + Optional[Request] Request that was redirected by the server to this one, if any. """ return mapping.from_impl_nullable(self._impl_obj.redirectedFrom) @@ -156,13 +164,13 @@ def redirectedTo(self) -> typing.Union["Request", NoneType]: Returns ------- - typing.Union[Request, NoneType] + Optional[Request] New request issued by the browser if the server responded with redirect. """ return mapping.from_impl_nullable(self._impl_obj.redirectedTo) @property - def failure(self) -> typing.Union[str, NoneType]: + def failure(self) -> typing.Union[RequestFailure, NoneType]: """Request.failure The method returns `null` unless this request has failed, as reported by @@ -171,7 +179,7 @@ def failure(self) -> typing.Union[str, NoneType]: Returns ------- - typing.Union[str, NoneType] + Optional[{"errorText": str}] Object describing request failure, if any """ return mapping.from_maybe_impl(self._impl_obj.failure) @@ -181,7 +189,7 @@ async def response(self) -> typing.Union["Response", NoneType]: Returns ------- - typing.Union[Response, NoneType] + Optional[Response] A matching Response object, or `null` if the response was not received due to error. """ return mapping.from_impl_nullable(await self._impl_obj.response()) @@ -259,7 +267,7 @@ def headers(self) -> typing.Dict[str, str]: Returns ------- - typing.Dict[str, str] + Dict[str, str] An object with HTTP headers associated with the response. All header names are lower-case. """ return mapping.from_maybe_impl(self._impl_obj.headers) @@ -291,7 +299,7 @@ async def finished(self) -> typing.Union[Error, NoneType]: Returns ------- - typing.Union[Error, NoneType] + Optional[Error] Waits for this response to finish, returns failure error if request failed. """ return mapping.from_maybe_impl(await self._impl_obj.finished()) @@ -323,7 +331,7 @@ async def json(self) -> typing.Union[typing.Dict, typing.List]: Returns ------- - typing.Union[typing.Dict, typing.List] + Union[Dict, List] Promise which resolves to a JSON representation of response body. """ return mapping.from_maybe_impl(await self._impl_obj.json()) @@ -393,11 +401,11 @@ async def fulfill( ---------- status : Optional[int] Response status code, defaults to `200`. - headers : Optional[typing.Dict[str, str]] + headers : Optional[Dict[str, str]] Optional response headers. Header values will be converted to a string. - body : Optional[str, bytes] + body : Union[str, bytes, NoneType] Optional response body. - path : Optional[str, pathlib.Path] + path : Union[str, pathlib.Path, NoneType] Optional file path to respond with. The content type will be inferred from file extension. If `path` is a relative path, then it is resolved relative to current working directory. contentType : Optional[str] If set, equals to setting `Content-Type` response header. @@ -426,9 +434,9 @@ async def continue_( ---------- method : Optional[str] If set changes the request method (e.g. GET or POST) - headers : Optional[typing.Dict[str, str]] + headers : Optional[Dict[str, str]] If set changes the request HTTP headers. Header values will be converted to a string. - postData : Optional[str, bytes] + postData : Union[str, bytes, NoneType] If set changes the post data of request """ return mapping.from_maybe_impl( @@ -562,7 +570,7 @@ async def down( Parameters ---------- - button : Optional[typing.Literal['left', 'right', 'middle']] + button : Optional[Literal['left', 'right', 'middle']] Defaults to `left`. clickCount : Optional[int] defaults to 1. See UIEvent.detail. @@ -580,7 +588,7 @@ async def up( Parameters ---------- - button : Optional[typing.Literal['left', 'right', 'middle']] + button : Optional[Literal['left', 'right', 'middle']] Defaults to `left`. clickCount : Optional[int] defaults to 1. See UIEvent.detail. @@ -607,7 +615,7 @@ async def click( y : float delay : Optional[int] Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - button : Optional[typing.Literal['left', 'right', 'middle']] + button : Optional[Literal['left', 'right', 'middle']] Defaults to `left`. clickCount : Optional[int] defaults to 1. See UIEvent.detail. @@ -635,7 +643,7 @@ async def dblclick( y : float delay : Optional[int] Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - button : Optional[typing.Literal['left', 'right', 'middle']] + button : Optional[Literal['left', 'right', 'middle']] Defaults to `left`. """ return mapping.from_maybe_impl( @@ -665,12 +673,12 @@ async def evaluate( Function to be evaluated in browser context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` Returns ------- - typing.Any + Any Promise which resolves to the return value of `pageFunction` """ return mapping.from_maybe_impl( @@ -695,7 +703,7 @@ async def evaluateHandle( Function to be evaluated force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` Returns @@ -734,7 +742,7 @@ async def getProperties(self) -> typing.Dict[str, "JSHandle"]: Returns ------- - typing.Dict[str, JSHandle] + Dict[str, JSHandle] """ return mapping.from_impl_dict(await self._impl_obj.getProperties()) @@ -745,7 +753,7 @@ def asElement(self) -> typing.Union["ElementHandle", NoneType]: Returns ------- - typing.Union[ElementHandle, NoneType] + Optional[ElementHandle] """ return mapping.from_impl_nullable(self._impl_obj.asElement()) @@ -767,7 +775,7 @@ async def jsonValue(self) -> typing.Any: Returns ------- - typing.Any + Any """ return mapping.from_maybe_impl(await self._impl_obj.jsonValue()) @@ -786,7 +794,7 @@ def asElement(self) -> typing.Union["ElementHandle", NoneType]: Returns ------- - typing.Union[ElementHandle, NoneType] + Optional[ElementHandle] """ return mapping.from_impl_nullable(self._impl_obj.asElement()) @@ -795,7 +803,7 @@ async def ownerFrame(self) -> typing.Union["Frame", NoneType]: Returns ------- - typing.Union[Frame, NoneType] + Optional[Frame] Returns the frame containing the given element. """ return mapping.from_impl_nullable(await self._impl_obj.ownerFrame()) @@ -805,7 +813,7 @@ async def contentFrame(self) -> typing.Union["Frame", NoneType]: Returns ------- - typing.Union[Frame, NoneType] + Optional[Frame] Resolves to the content frame for element handles referencing iframe nodes, or `null` otherwise """ return mapping.from_impl_nullable(await self._impl_obj.contentFrame()) @@ -822,7 +830,7 @@ async def getAttribute(self, name: str) -> typing.Union[str, NoneType]: Returns ------- - typing.Union[str, NoneType] + Optional[str] """ return mapping.from_maybe_impl(await self._impl_obj.getAttribute(name=name)) @@ -831,7 +839,7 @@ async def textContent(self) -> typing.Union[str, NoneType]: Returns ------- - typing.Union[str, NoneType] + Optional[str] Resolves to the `node.textContent`. """ return mapping.from_maybe_impl(await self._impl_obj.textContent()) @@ -877,7 +885,7 @@ async def dispatchEvent(self, type: str, eventInit: typing.Dict = None) -> NoneT ---------- type : str DOM event type: `"click"`, `"dragstart"`, etc. - eventInit : Optional[typing.Dict] + eventInit : Optional[Dict] event-specific initialization properties. """ return mapping.from_maybe_impl( @@ -906,7 +914,7 @@ async def hover( modifiers: typing.Union[ typing.List[Literal["Alt", "Control", "Meta", "Shift"]] ] = None, - position: typing.Dict = None, + position: MousePosition = None, timeout: int = None, force: bool = None, ) -> NoneType: @@ -917,9 +925,9 @@ async def hover( Parameters ---------- - modifiers : Optional[typing.List[typing.Literal['Alt', 'Control', 'Meta', 'Shift']]] + modifiers : Optional[List[Literal['Alt', 'Control', 'Meta', 'Shift']]] Modifier keys to press. Ensures that only these modifiers are pressed during the hover, and then restores current modifiers back. If not specified, currently pressed modifiers are used. - position : Optional[typing.Dict] + position : Optional[{"x": float, "y": float}] A point to hover relative to the top-left corner of element padding box. If not specified, hovers over some visible point of the element. timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. @@ -928,10 +936,7 @@ async def hover( """ return mapping.from_maybe_impl( await self._impl_obj.hover( - modifiers=modifiers, - position=mapping.to_impl(position), - timeout=timeout, - force=force, + modifiers=modifiers, position=position, timeout=timeout, force=force ) ) @@ -940,7 +945,7 @@ async def click( modifiers: typing.Union[ typing.List[Literal["Alt", "Control", "Meta", "Shift"]] ] = None, - position: typing.Dict = None, + position: MousePosition = None, delay: int = None, button: Literal["left", "right", "middle"] = None, clickCount: int = None, @@ -955,13 +960,13 @@ async def click( Parameters ---------- - modifiers : Optional[typing.List[typing.Literal['Alt', 'Control', 'Meta', 'Shift']]] + modifiers : Optional[List[Literal['Alt', 'Control', 'Meta', 'Shift']]] Modifier keys to press. Ensures that only these modifiers are pressed during the click, and then restores current modifiers back. If not specified, currently pressed modifiers are used. - position : Optional[typing.Dict] + position : Optional[{"x": float, "y": float}] A point to click relative to the top-left corner of element padding box. If not specified, clicks to some visible point of the element. delay : Optional[int] Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - button : Optional[typing.Literal['left', 'right', 'middle']] + button : Optional[Literal['left', 'right', 'middle']] Defaults to `left`. clickCount : Optional[int] defaults to 1. See UIEvent.detail. @@ -975,7 +980,7 @@ async def click( return mapping.from_maybe_impl( await self._impl_obj.click( modifiers=modifiers, - position=mapping.to_impl(position), + position=position, delay=delay, button=button, clickCount=clickCount, @@ -990,7 +995,7 @@ async def dblclick( modifiers: typing.Union[ typing.List[Literal["Alt", "Control", "Meta", "Shift"]] ] = None, - position: typing.Dict = None, + position: MousePosition = None, delay: int = None, button: Literal["left", "right", "middle"] = None, timeout: int = None, @@ -1007,13 +1012,13 @@ async def dblclick( Parameters ---------- - modifiers : Optional[typing.List[typing.Literal['Alt', 'Control', 'Meta', 'Shift']]] + modifiers : Optional[List[Literal['Alt', 'Control', 'Meta', 'Shift']]] Modifier keys to press. Ensures that only these modifiers are pressed during the double click, and then restores current modifiers back. If not specified, currently pressed modifiers are used. - position : Optional[typing.Dict] + position : Optional[{"x": float, "y": float}] A point to double click relative to the top-left corner of element padding box. If not specified, double clicks to some visible point of the element. delay : Optional[int] Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - button : Optional[typing.Literal['left', 'right', 'middle']] + button : Optional[Literal['left', 'right', 'middle']] Defaults to `left`. timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. @@ -1025,7 +1030,7 @@ async def dblclick( return mapping.from_maybe_impl( await self._impl_obj.dblclick( modifiers=modifiers, - position=mapping.to_impl(position), + position=position, delay=delay, button=button, timeout=timeout, @@ -1054,7 +1059,7 @@ async def selectOption( Parameters ---------- - values : Optional[str, ElementHandle, SelectOption, typing.List[str], typing.List[ElementHandle], typing.List[SelectOption]] + values : Union[str, ElementHandle, {"value": Optional[str], "label": Optional[str], "index": Optional[str]}, List[str], List[ElementHandle], List[{"value": Optional[str], "label": Optional[str], "index": Optional[str]}], NoneType] Options to select. If the `` has the `multiple` attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are equivalent to `{value:'string'}`. Option is considered matching if all specified properties match. timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. @@ -2368,7 +2373,7 @@ async def selectOption( Returns ------- - typing.List[str] + List[str] An array of option values that have been successfully selected. """ return mapping.from_maybe_impl( @@ -2403,7 +2408,7 @@ async def setInputFiles( ---------- selector : str A selector to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked. See working with selectors for more details. - files : typing.Union[str, pathlib.Path, FilePayload, typing.List[str], typing.List[pathlib.Path], typing.List[FilePayload]] + files : Union[str, pathlib.Path, {"name": str, "mimeType": str, "buffer": Union[bytes, str]}, List[str], List[pathlib.Path], List[{"name": str, "mimeType": str, "buffer": Union[bytes, str]}]] timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. noWaitAfter : Optional[bool] @@ -2584,11 +2589,11 @@ async def waitForFunction( Function to be evaluated in browser context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` timeout : Optional[int] 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 browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. - polling : Optional[int, typing.Literal['raf']] + polling : Union[int, 'raf', NoneType] If `polling` is `'raf'`, then `pageFunction` is constantly executed in `requestAnimationFrame` callback. If `polling` is a number, then it is treated as an interval in milliseconds at which the function would be executed. Defaults to `raf`. Returns @@ -2665,12 +2670,12 @@ async def evaluate( Function to be evaluated in the worker context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` Returns ------- - typing.Any + Any Promise which resolves to the return value of `pageFunction` """ return mapping.from_maybe_impl( @@ -2693,7 +2698,7 @@ async def evaluateHandle( Function to be evaluated in the page context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` Returns @@ -2777,7 +2782,7 @@ def args(self) -> typing.List["JSHandle"]: Returns ------- - typing.List[JSHandle] + List[JSHandle] """ return mapping.from_impl_list(self._impl_obj.args) @@ -2787,7 +2792,7 @@ def location(self) -> ConsoleMessageLocation: Returns ------- - ConsoleMessageLocation + {"url": Optional[str], "lineNumber": Optional[int], "columnNumber": Optional[int]} """ return mapping.from_maybe_impl(self._impl_obj.location) @@ -2895,7 +2900,7 @@ async def failure(self) -> typing.Union[str, NoneType]: Returns ------- - typing.Union[str, NoneType] + Optional[str] """ return mapping.from_maybe_impl(await self._impl_obj.failure()) @@ -2906,7 +2911,7 @@ async def path(self) -> typing.Union[str, NoneType]: Returns ------- - typing.Union[str, NoneType] + Optional[str] """ return mapping.from_maybe_impl(await self._impl_obj.path()) @@ -2992,7 +2997,7 @@ def frames(self) -> typing.List["Frame"]: Returns ------- - typing.List[Frame] + List[Frame] An array of all frames attached to the page. """ return mapping.from_impl_list(self._impl_obj.frames) @@ -3017,7 +3022,7 @@ def workers(self) -> typing.List["Worker"]: Returns ------- - typing.List[Worker] + List[Worker] This method returns all of the dedicated WebWorkers associated with the page. """ return mapping.from_impl_list(self._impl_obj.workers) @@ -3027,7 +3032,7 @@ async def opener(self) -> typing.Union["Page", NoneType]: Returns ------- - typing.Union[Page, NoneType] + Optional[Page] Promise which resolves to the opener for popup pages and `null` for others. If the opener has been closed already the promise may resolve to `null`. """ return mapping.from_impl_nullable(await self._impl_obj.opener()) @@ -3045,12 +3050,12 @@ def frame( ---------- name : Optional[str] frame name specified in the `iframe`'s `name` attribute - url : Optional[str, typing.Pattern, typing.Callable[[str], bool]] + url : Union[str, Pattern, typing.Callable[[str], bool], NoneType] A glob pattern, regex pattern or predicate receiving frame's `url` as a URL object. Returns ------- - typing.Union[Frame, NoneType] + Optional[Frame] frame matching the criteria. Returns `null` if no frame matches. """ return mapping.from_impl_nullable( @@ -3111,7 +3116,7 @@ async def querySelector( Returns ------- - typing.Union[ElementHandle, NoneType] + Optional[ElementHandle] """ return mapping.from_impl_nullable( await self._impl_obj.querySelector(selector=selector) @@ -3130,7 +3135,7 @@ async def querySelectorAll(self, selector: str) -> typing.List["ElementHandle"]: Returns ------- - typing.List[ElementHandle] + List[ElementHandle] """ return mapping.from_impl_list( await self._impl_obj.querySelectorAll(selector=selector) @@ -3155,7 +3160,7 @@ async def waitForSelector( A selector of an element to wait for. See working with selectors for more details. timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. - state : Optional[typing.Literal['attached', 'detached', 'visible', 'hidden']] + state : Optional[Literal['attached', 'detached', 'visible', 'hidden']] Defaults to `'visible'`. Can be either: - `'attached'` - wait for element to be present in DOM. - `'detached'` - wait for element to not be present in DOM. @@ -3164,7 +3169,7 @@ async def waitForSelector( Returns ------- - typing.Union[ElementHandle, NoneType] + Optional[ElementHandle] Promise which resolves when element specified by selector satisfies `state` option. Resolves to `null` if waiting for `hidden` or `detached`. """ return mapping.from_impl_nullable( @@ -3202,7 +3207,7 @@ async def dispatchEvent( A selector to search for element to use. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details. type : str DOM event type: `"click"`, `"dragstart"`, etc. - eventInit : Optional[typing.Dict] + eventInit : Optional[Dict] event-specific initialization properties. timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. @@ -3234,12 +3239,12 @@ async def evaluate( Function to be evaluated in the page context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` Returns ------- - typing.Any + Any Promise which resolves to the return value of `pageFunction` """ return mapping.from_maybe_impl( @@ -3264,7 +3269,7 @@ async def evaluateHandle( Function to be evaluated in the page context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` Returns @@ -3300,12 +3305,12 @@ async def evalOnSelector( Function to be evaluated in browser context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` Returns ------- - typing.Any + Any Promise which resolves to the return value of `pageFunction` """ return mapping.from_maybe_impl( @@ -3338,12 +3343,12 @@ async def evalOnSelectorAll( Function to be evaluated in browser context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` Returns ------- - typing.Any + Any Promise which resolves to the return value of `pageFunction` """ return mapping.from_maybe_impl( @@ -3429,7 +3434,7 @@ async def exposeFunction(self, name: str, binding: typing.Callable) -> NoneType: ---------- name : str Name of the function on the window object - binding : typing.Callable + binding : Callable Callback function which will be called in Playwright's context. """ return mapping.from_maybe_impl( @@ -3456,7 +3461,7 @@ async def exposeBinding(self, name: str, binding: typing.Callable) -> NoneType: ---------- name : str Name of the function on the window object. - binding : typing.Callable + binding : Callable Callback function that will be called in the Playwright's context. """ return mapping.from_maybe_impl( @@ -3465,7 +3470,7 @@ async def exposeBinding(self, name: str, binding: typing.Callable) -> NoneType: ) ) - async def setExtraHTTPHeaders(self, headers: typing.Dict) -> NoneType: + async def setExtraHTTPHeaders(self, headers: typing.Dict[str, str]) -> NoneType: """Page.setExtraHTTPHeaders The extra HTTP headers will be sent with every request the page initiates. @@ -3474,7 +3479,7 @@ async def setExtraHTTPHeaders(self, headers: typing.Dict) -> NoneType: Parameters ---------- - headers : typing.Dict + headers : Dict[str, str] An object containing additional HTTP headers to be sent with every request. All header values must be strings. """ return mapping.from_maybe_impl( @@ -3506,7 +3511,7 @@ async def setContent( HTML markup to assign to the page. timeout : Optional[int] Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultNavigationTimeout(timeout), browserContext.setDefaultTimeout(timeout), page.setDefaultNavigationTimeout(timeout) or page.setDefaultTimeout(timeout) methods. - waitUntil : Optional[typing.Literal['load', 'domcontentloaded', 'networkidle']] + waitUntil : Optional[Literal['load', 'domcontentloaded', 'networkidle']] When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either: - `'load'` - consider setting content to be finished when the `load` event is fired. - `'domcontentloaded'` - consider setting content to be finished when the `DOMContentLoaded` event is fired. @@ -3549,7 +3554,7 @@ async def goto( URL to navigate page to. The url should include scheme, e.g. `https://`. timeout : Optional[int] Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultNavigationTimeout(timeout), browserContext.setDefaultTimeout(timeout), page.setDefaultNavigationTimeout(timeout) or page.setDefaultTimeout(timeout) methods. - waitUntil : Optional[typing.Literal['load', 'domcontentloaded', 'networkidle']] + waitUntil : Optional[Literal['load', 'domcontentloaded', 'networkidle']] When to consider navigation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider navigation to be finished when the `load` event is fired. @@ -3559,7 +3564,7 @@ async def goto( Returns ------- - typing.Union[Response, NoneType] + Optional[Response] Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. """ return mapping.from_impl_nullable( @@ -3579,7 +3584,7 @@ async def reload( ---------- timeout : Optional[int] Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultNavigationTimeout(timeout), browserContext.setDefaultTimeout(timeout), page.setDefaultNavigationTimeout(timeout) or page.setDefaultTimeout(timeout) methods. - waitUntil : Optional[typing.Literal['load', 'domcontentloaded', 'networkidle']] + waitUntil : Optional[Literal['load', 'domcontentloaded', 'networkidle']] When to consider navigation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider navigation to be finished when the `load` event is fired. @@ -3587,7 +3592,7 @@ async def reload( Returns ------- - typing.Union[Response, NoneType] + Optional[Response] Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. """ return mapping.from_impl_nullable( @@ -3606,7 +3611,7 @@ async def waitForLoadState( Parameters ---------- - state : Optional[typing.Literal['load', 'domcontentloaded', 'networkidle']] + state : Optional[Literal['load', 'domcontentloaded', 'networkidle']] Load state to wait for, defaults to `load`. If the state has been already reached while loading current document, the method resolves immediately. - `'load'` - wait for the `load` event to be fired. - `'domcontentloaded'` - wait for the `DOMContentLoaded` event to be fired. @@ -3633,9 +3638,9 @@ async def waitForNavigation( Parameters ---------- - url : Optional[str, typing.Pattern, typing.Callable[[str], bool]] + url : Union[str, Pattern, typing.Callable[[str], bool], NoneType] A glob pattern, regex pattern or predicate receiving URL to match while waiting for the navigation. - waitUntil : Optional[typing.Literal['load', 'domcontentloaded', 'networkidle']] + waitUntil : Optional[Literal['load', 'domcontentloaded', 'networkidle']] When to consider navigation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider navigation to be finished when the `load` event is fired. @@ -3645,7 +3650,7 @@ async def waitForNavigation( Returns ------- - typing.Union[Response, NoneType] + Optional[Response] Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to History API usage, the navigation will resolve with `null`. """ return mapping.from_impl_nullable( @@ -3665,7 +3670,7 @@ async def waitForRequest( Parameters ---------- - url : Optional[str, typing.Pattern, typing.Callable[[str], bool]] + url : Union[str, Pattern, typing.Callable[[str], bool], NoneType] Request URL string, regex or predicate receiving Request object. timeout : Optional[int] Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be changed by using the page.setDefaultTimeout(timeout) method. @@ -3694,7 +3699,7 @@ async def waitForResponse( Parameters ---------- - url : Optional[str, typing.Pattern, typing.Callable[[str], bool]] + url : Union[str, Pattern, typing.Callable[[str], bool], NoneType] Request URL string, regex or predicate receiving Response object. timeout : Optional[int] Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. @@ -3730,7 +3735,7 @@ async def waitForEvent( Returns ------- - typing.Any + Any Promise which resolves to the event data value. """ return mapping.from_maybe_impl( @@ -3752,7 +3757,7 @@ async def goBack( ---------- timeout : Optional[int] Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultNavigationTimeout(timeout), browserContext.setDefaultTimeout(timeout), page.setDefaultNavigationTimeout(timeout) or page.setDefaultTimeout(timeout) methods. - waitUntil : Optional[typing.Literal['load', 'domcontentloaded', 'networkidle']] + waitUntil : Optional[Literal['load', 'domcontentloaded', 'networkidle']] When to consider navigation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider navigation to be finished when the `load` event is fired. @@ -3760,7 +3765,7 @@ async def goBack( Returns ------- - typing.Union[Response, NoneType] + Optional[Response] Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. If can not go back, resolves to `null`. """ @@ -3781,7 +3786,7 @@ async def goForward( ---------- timeout : Optional[int] Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultNavigationTimeout(timeout), browserContext.setDefaultTimeout(timeout), page.setDefaultNavigationTimeout(timeout) or page.setDefaultTimeout(timeout) methods. - waitUntil : Optional[typing.Literal['load', 'domcontentloaded', 'networkidle']] + waitUntil : Optional[Literal['load', 'domcontentloaded', 'networkidle']] When to consider navigation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider navigation to be finished when the `load` event is fired. @@ -3789,7 +3794,7 @@ async def goForward( Returns ------- - typing.Union[Response, NoneType] + Optional[Response] Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. If can not go forward, resolves to `null`. """ @@ -3807,9 +3812,9 @@ async def emulateMedia( Parameters ---------- - media : Optional[typing.Literal['screen', 'print']] + media : Optional[Literal['screen', 'print']] Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null` disables CSS media emulation. Omitting `media` or passing `undefined` does not change the emulated value. - colorScheme : Optional[typing.Literal['light', 'dark', 'no-preference']] + colorScheme : Optional[Literal['light', 'dark', 'no-preference']] Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. Passing `null` disables color scheme emulation. Omitting `colorScheme` or passing `undefined` does not change the emulated value. """ return mapping.from_maybe_impl( @@ -3838,7 +3843,7 @@ def viewportSize(self) -> typing.Union[Viewport, NoneType]: Returns ------- - typing.Union[Viewport, NoneType] + Optional[{"width": int, "height": int}] """ return mapping.from_maybe_impl(self._impl_obj.viewportSize()) @@ -3888,9 +3893,9 @@ async def route( Parameters ---------- - url : typing.Union[str, typing.Pattern, typing.Callable[[str], bool]] + url : Union[str, Pattern, typing.Callable[[str], bool]] A glob pattern, regex pattern or predicate receiving URL to match while routing. - handler : typing.Callable[[Route, Request], typing.Any] + handler : typing.Callable[[playwright.network.Route, playwright.network.Request], typing.Any] handler function to route the request. """ return mapping.from_maybe_impl( @@ -3910,9 +3915,9 @@ async def unroute( Parameters ---------- - url : typing.Union[str, typing.Pattern, typing.Callable[[str], bool]] + url : Union[str, Pattern, typing.Callable[[str], bool]] A glob pattern, regex pattern or predicate receiving URL to match while routing. - handler : Optional[typing.Callable[[Route, Request], typing.Any]] + handler : Optional[typing.Callable[[playwright.network.Route, playwright.network.Request], typing.Any]] Handler function to route the request. """ return mapping.from_maybe_impl( @@ -3929,7 +3934,7 @@ async def screenshot( quality: int = None, omitBackground: bool = None, fullPage: bool = None, - clip: typing.Dict = None, + clip: FloatRect = None, ) -> bytes: """Page.screenshot @@ -3939,7 +3944,7 @@ async def screenshot( ---------- timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. - type : Optional[typing.Literal['png', 'jpeg']] + type : Optional[Literal['png', 'jpeg']] Specify screenshot type, defaults to `png`. path : Optional[str] The file path to save the image to. The screenshot type will be inferred from file extension. If `path` is a relative path, then it is resolved relative to current working directory. If no path is provided, the image won't be saved to the disk. @@ -3949,7 +3954,7 @@ async def screenshot( Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images. Defaults to `false`. fullPage : Optional[bool] When true, takes a screenshot of the full scrollable page, instead of the currently visibvle viewport. Defaults to `false`. - clip : Optional[typing.Dict] + clip : Optional[{"x": float, "y": float, "width": float, "height": float}] An object which specifies clipping of the resulting image. Should have the following fields: Returns @@ -3965,7 +3970,7 @@ async def screenshot( quality=quality, omitBackground=omitBackground, fullPage=fullPage, - clip=mapping.to_impl(clip), + clip=clip, ) ) @@ -4017,7 +4022,7 @@ async def click( modifiers: typing.Union[ typing.List[Literal["Alt", "Control", "Meta", "Shift"]] ] = None, - position: typing.Dict = None, + position: MousePosition = None, delay: int = None, button: Literal["left", "right", "middle"] = None, clickCount: int = None, @@ -4035,13 +4040,13 @@ async def click( ---------- selector : str A selector to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked. See working with selectors for more details. - modifiers : Optional[typing.List[typing.Literal['Alt', 'Control', 'Meta', 'Shift']]] + modifiers : Optional[List[Literal['Alt', 'Control', 'Meta', 'Shift']]] Modifier keys to press. Ensures that only these modifiers are pressed during the click, and then restores current modifiers back. If not specified, currently pressed modifiers are used. - position : Optional[typing.Dict] + position : Optional[{"x": float, "y": float}] A point to click relative to the top-left corner of element padding box. If not specified, clicks to some visible point of the element. delay : Optional[int] Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - button : Optional[typing.Literal['left', 'right', 'middle']] + button : Optional[Literal['left', 'right', 'middle']] Defaults to `left`. clickCount : Optional[int] defaults to 1. See UIEvent.detail. @@ -4056,7 +4061,7 @@ async def click( await self._impl_obj.click( selector=selector, modifiers=modifiers, - position=mapping.to_impl(position), + position=position, delay=delay, button=button, clickCount=clickCount, @@ -4072,7 +4077,7 @@ async def dblclick( modifiers: typing.Union[ typing.List[Literal["Alt", "Control", "Meta", "Shift"]] ] = None, - position: typing.Dict = None, + position: MousePosition = None, delay: int = None, button: Literal["left", "right", "middle"] = None, timeout: int = None, @@ -4092,13 +4097,13 @@ async def dblclick( ---------- selector : str A selector to search for element to double click. If there are multiple elements satisfying the selector, the first will be double clicked. See working with selectors for more details. - modifiers : Optional[typing.List[typing.Literal['Alt', 'Control', 'Meta', 'Shift']]] + modifiers : Optional[List[Literal['Alt', 'Control', 'Meta', 'Shift']]] Modifier keys to press. Ensures that only these modifiers are pressed during the double click, and then restores current modifiers back. If not specified, currently pressed modifiers are used. - position : Optional[typing.Dict] + position : Optional[{"x": float, "y": float}] A point to double click relative to the top-left corner of element padding box. If not specified, double clicks to some visible point of the element. delay : Optional[int] Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - button : Optional[typing.Literal['left', 'right', 'middle']] + button : Optional[Literal['left', 'right', 'middle']] Defaults to `left`. timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. @@ -4109,7 +4114,7 @@ async def dblclick( await self._impl_obj.dblclick( selector=selector, modifiers=modifiers, - position=mapping.to_impl(position), + position=position, delay=delay, button=button, timeout=timeout, @@ -4179,7 +4184,7 @@ async def textContent( Returns ------- - typing.Union[str, NoneType] + Optional[str] """ return mapping.from_maybe_impl( await self._impl_obj.textContent(selector=selector, timeout=timeout) @@ -4243,7 +4248,7 @@ async def getAttribute( Returns ------- - typing.Union[str, NoneType] + Optional[str] """ return mapping.from_maybe_impl( await self._impl_obj.getAttribute( @@ -4257,7 +4262,7 @@ async def hover( modifiers: typing.Union[ typing.List[Literal["Alt", "Control", "Meta", "Shift"]] ] = None, - position: typing.Dict = None, + position: MousePosition = None, timeout: int = None, force: bool = None, ) -> NoneType: @@ -4271,9 +4276,9 @@ async def hover( ---------- selector : str A selector to search for element to hover. If there are multiple elements satisfying the selector, the first will be hovered. See working with selectors for more details. - modifiers : Optional[typing.List[typing.Literal['Alt', 'Control', 'Meta', 'Shift']]] + modifiers : Optional[List[Literal['Alt', 'Control', 'Meta', 'Shift']]] Modifier keys to press. Ensures that only these modifiers are pressed during the hover, and then restores current modifiers back. If not specified, currently pressed modifiers are used. - position : Optional[typing.Dict] + position : Optional[{"x": float, "y": float}] A point to hover relative to the top-left corner of element padding box. If not specified, hovers over some visible point of the element. timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. @@ -4284,7 +4289,7 @@ async def hover( await self._impl_obj.hover( selector=selector, modifiers=modifiers, - position=mapping.to_impl(position), + position=position, timeout=timeout, force=force, ) @@ -4315,7 +4320,7 @@ async def selectOption( ---------- selector : str A selector to query page for. See working with selectors for more details. - values : Optional[str, ElementHandle, SelectOption, typing.List[str], typing.List[ElementHandle], typing.List[SelectOption]] + values : Union[str, ElementHandle, {"value": Optional[str], "label": Optional[str], "index": Optional[str]}, List[str], List[ElementHandle], List[{"value": Optional[str], "label": Optional[str], "index": Optional[str]}], NoneType] Options to select. If the `` has the `multiple` attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are equivalent to `{value:'string'}`. Option is considered matching if all specified properties match. timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. @@ -1093,7 +1098,7 @@ def selectOption( Returns ------- - typing.List[str] + List[str] An array of option values that have been successfully selected. """ return mapping.from_maybe_impl( @@ -1166,7 +1171,7 @@ def setInputFiles( Parameters ---------- - files : typing.Union[str, pathlib.Path, FilePayload, typing.List[str], typing.List[pathlib.Path], typing.List[FilePayload]] + files : Union[str, pathlib.Path, {"name": str, "mimeType": str, "buffer": Union[bytes, str]}, List[str], List[pathlib.Path], List[{"name": str, "mimeType": str, "buffer": Union[bytes, str]}]] timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. noWaitAfter : Optional[bool] @@ -1299,14 +1304,14 @@ def uncheck( ) ) - def boundingBox(self) -> typing.Dict[str, float]: + def boundingBox(self) -> typing.Union[FloatRect, NoneType]: """ElementHandle.boundingBox This method returns the bounding box of the element (relative to the main frame), or `null` if the element is not visible. Returns ------- - typing.Dict[str, float] + Optional[{"x": float, "y": float, "width": float, "height": float}] """ return mapping.from_maybe_impl(self._sync(self._impl_obj.boundingBox())) @@ -1326,7 +1331,7 @@ def screenshot( ---------- timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. - type : Optional[typing.Literal['png', 'jpeg']] + type : Optional[Literal['png', 'jpeg']] Specify screenshot type, defaults to `png`. path : Optional[str] The file path to save the image to. The screenshot type will be inferred from file extension. If `path` is a relative path, then it is resolved relative to current working directory. If no path is provided, the image won't be saved to the disk. @@ -1364,7 +1369,7 @@ def querySelector(self, selector: str) -> typing.Union["ElementHandle", NoneType Returns ------- - typing.Union[ElementHandle, NoneType] + Optional[ElementHandle] """ return mapping.from_impl_nullable( self._sync(self._impl_obj.querySelector(selector=selector)) @@ -1382,7 +1387,7 @@ def querySelectorAll(self, selector: str) -> typing.List["ElementHandle"]: Returns ------- - typing.List[ElementHandle] + List[ElementHandle] """ return mapping.from_impl_list( self._sync(self._impl_obj.querySelectorAll(selector=selector)) @@ -1409,12 +1414,12 @@ def evalOnSelector( Function to be evaluated in browser context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` Returns ------- - typing.Any + Any Promise which resolves to the return value of `pageFunction` """ return mapping.from_maybe_impl( @@ -1455,12 +1460,12 @@ def evalOnSelectorAll( Function to be evaluated in browser context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` Returns ------- - typing.Any + Any Promise which resolves to the return value of `pageFunction` """ return mapping.from_maybe_impl( @@ -1484,7 +1489,7 @@ def __init__(self, obj: AccessibilityImpl): def snapshot( self, interestingOnly: bool = None, root: "ElementHandle" = None - ) -> typing.Union[typing.Dict[str, typing.Any], NoneType]: + ) -> typing.Union[typing.Dict, NoneType]: """Accessibility.snapshot Captures the current state of the accessibility tree. The returned object represents the root accessible node of the page. @@ -1505,7 +1510,7 @@ def snapshot( Returns ------- - typing.Union[typing.Dict[str, typing.Any], NoneType] + Optional[Dict] An AXNode object with the following properties: """ return mapping.from_maybe_impl( @@ -1574,7 +1579,7 @@ def setFiles( Parameters ---------- - files : typing.Union[str, FilePayload, typing.List[str], typing.List[FilePayload]] + files : Union[str, {"name": str, "mimeType": str, "buffer": Union[bytes, str]}, List[str], List[{"name": str, "mimeType": str, "buffer": Union[bytes, str]}]] timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. noWaitAfter : Optional[bool] @@ -1629,7 +1634,7 @@ def parentFrame(self) -> typing.Union["Frame", NoneType]: Returns ------- - typing.Union[Frame, NoneType] + Optional[Frame] Parent frame, if any. Detached frames and main frames return `null`. """ return mapping.from_impl_nullable(self._impl_obj.parentFrame) @@ -1640,7 +1645,7 @@ def childFrames(self) -> typing.List["Frame"]: Returns ------- - typing.List[Frame] + List[Frame] """ return mapping.from_impl_list(self._impl_obj.childFrames) @@ -1673,7 +1678,7 @@ def goto( URL to navigate frame to. The url should include scheme, e.g. `https://`. timeout : Optional[int] Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultNavigationTimeout(timeout), browserContext.setDefaultTimeout(timeout), page.setDefaultNavigationTimeout(timeout) or page.setDefaultTimeout(timeout) methods. - waitUntil : Optional[typing.Literal['load', 'domcontentloaded', 'networkidle']] + waitUntil : Optional[Literal['load', 'domcontentloaded', 'networkidle']] When to consider navigation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider navigation to be finished when the `load` event is fired. @@ -1683,7 +1688,7 @@ def goto( Returns ------- - typing.Union[Response, NoneType] + Optional[Response] Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. """ return mapping.from_impl_nullable( @@ -1708,9 +1713,9 @@ def waitForNavigation( Parameters ---------- - url : Optional[str, typing.Pattern, typing.Callable[[str], bool]] + url : Union[str, Pattern, typing.Callable[[str], bool], NoneType] URL string, URL regex pattern or predicate receiving URL to match while waiting for the navigation. - waitUntil : Optional[typing.Literal['load', 'domcontentloaded', 'networkidle']] + waitUntil : Optional[Literal['load', 'domcontentloaded', 'networkidle']] When to consider navigation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider navigation to be finished when the `load` event is fired. @@ -1720,7 +1725,7 @@ def waitForNavigation( Returns ------- - typing.Union[Response, NoneType] + Optional[Response] Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to History API usage, the navigation will resolve with `null`. """ return mapping.from_impl_nullable( @@ -1742,7 +1747,7 @@ def waitForLoadState( Parameters ---------- - state : Optional[typing.Literal['load', 'domcontentloaded', 'networkidle']] + state : Optional[Literal['load', 'domcontentloaded', 'networkidle']] Load state to wait for, defaults to `load`. If the state has been already reached while loading current document, the method resolves immediately. - `'load'` - wait for the `load` event to be fired. - `'domcontentloaded'` - wait for the `DOMContentLoaded` event to be fired. @@ -1783,12 +1788,12 @@ def evaluate( Function to be evaluated in browser context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` Returns ------- - typing.Any + Any Promise which resolves to the return value of `pageFunction` """ return mapping.from_maybe_impl( @@ -1817,7 +1822,7 @@ def evaluateHandle( Function to be evaluated in the page context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` Returns @@ -1847,7 +1852,7 @@ def querySelector(self, selector: str) -> typing.Union["ElementHandle", NoneType Returns ------- - typing.Union[ElementHandle, NoneType] + Optional[ElementHandle] Promise which resolves to ElementHandle pointing to the frame element. """ return mapping.from_impl_nullable( @@ -1866,7 +1871,7 @@ def querySelectorAll(self, selector: str) -> typing.List["ElementHandle"]: Returns ------- - typing.List[ElementHandle] + List[ElementHandle] Promise which resolves to ElementHandles pointing to the frame elements. """ return mapping.from_impl_list( @@ -1890,7 +1895,7 @@ def waitForSelector( A selector of an element to wait for. See working with selectors for more details. timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. - state : Optional[typing.Literal['attached', 'detached', 'visible', 'hidden']] + state : Optional[Literal['attached', 'detached', 'visible', 'hidden']] Defaults to `'visible'`. Can be either: - `'attached'` - wait for element to be present in DOM. - `'detached'` - wait for element to not be present in DOM. @@ -1899,7 +1904,7 @@ def waitForSelector( Returns ------- - typing.Union[ElementHandle, NoneType] + Optional[ElementHandle] Promise which resolves when element specified by selector satisfies `state` option. Resolves to `null` if waiting for `hidden` or `detached`. """ return mapping.from_impl_nullable( @@ -1939,7 +1944,7 @@ def dispatchEvent( A selector to search for element to use. If there are multiple elements satisfying the selector, the first will be double clicked. See working with selectors for more details. type : str DOM event type: `"click"`, `"dragstart"`, etc. - eventInit : Optional[typing.Dict] + eventInit : Optional[Dict] event-specific initialization properties. timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. @@ -1976,12 +1981,12 @@ def evalOnSelector( Function to be evaluated in browser context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` Returns ------- - typing.Any + Any Promise which resolves to the return value of `pageFunction` """ return mapping.from_maybe_impl( @@ -2016,12 +2021,12 @@ def evalOnSelectorAll( Function to be evaluated in browser context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` Returns ------- - typing.Any + Any Promise which resolves to the return value of `pageFunction` """ return mapping.from_maybe_impl( @@ -2060,7 +2065,7 @@ def setContent( HTML markup to assign to the page. timeout : Optional[int] Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultNavigationTimeout(timeout), browserContext.setDefaultTimeout(timeout), page.setDefaultNavigationTimeout(timeout) or page.setDefaultTimeout(timeout) methods. - waitUntil : Optional[typing.Literal['load', 'domcontentloaded', 'networkidle']] + waitUntil : Optional[Literal['load', 'domcontentloaded', 'networkidle']] When to consider navigation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider setting content to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider setting content to be finished when the `load` event is fired. @@ -2147,7 +2152,7 @@ def click( modifiers: typing.Union[ typing.List[Literal["Alt", "Control", "Meta", "Shift"]] ] = None, - position: typing.Dict = None, + position: MousePosition = None, delay: int = None, button: Literal["left", "right", "middle"] = None, clickCount: int = None, @@ -2164,13 +2169,13 @@ def click( ---------- selector : str A selector to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked. See working with selectors for more details. - modifiers : Optional[typing.List[typing.Literal['Alt', 'Control', 'Meta', 'Shift']]] + modifiers : Optional[List[Literal['Alt', 'Control', 'Meta', 'Shift']]] Modifier keys to press. Ensures that only these modifiers are pressed during the click, and then restores current modifiers back. If not specified, currently pressed modifiers are used. - position : Optional[typing.Dict] + position : Optional[{"x": float, "y": float}] A point to click relative to the top-left corner of element padding box. If not specified, clicks to some visible point of the element. delay : Optional[int] Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - button : Optional[typing.Literal['left', 'right', 'middle']] + button : Optional[Literal['left', 'right', 'middle']] Defaults to `left`. clickCount : Optional[int] defaults to 1. See UIEvent.detail. @@ -2186,7 +2191,7 @@ def click( self._impl_obj.click( selector=selector, modifiers=modifiers, - position=mapping.to_impl(position), + position=position, delay=delay, button=button, clickCount=clickCount, @@ -2203,7 +2208,7 @@ def dblclick( modifiers: typing.Union[ typing.List[Literal["Alt", "Control", "Meta", "Shift"]] ] = None, - position: typing.Dict = None, + position: MousePosition = None, delay: int = None, button: Literal["left", "right", "middle"] = None, timeout: int = None, @@ -2221,13 +2226,13 @@ def dblclick( ---------- selector : str A selector to search for element to double click. If there are multiple elements satisfying the selector, the first will be double clicked. See working with selectors for more details. - modifiers : Optional[typing.List[typing.Literal['Alt', 'Control', 'Meta', 'Shift']]] + modifiers : Optional[List[Literal['Alt', 'Control', 'Meta', 'Shift']]] Modifier keys to press. Ensures that only these modifiers are pressed during the double click, and then restores current modifiers back. If not specified, currently pressed modifiers are used. - position : Optional[typing.Dict] + position : Optional[{"x": float, "y": float}] A point to double click relative to the top-left corner of element padding box. If not specified, double clicks to some visible point of the element. delay : Optional[int] Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - button : Optional[typing.Literal['left', 'right', 'middle']] + button : Optional[Literal['left', 'right', 'middle']] Defaults to `left`. timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. @@ -2239,7 +2244,7 @@ def dblclick( self._impl_obj.dblclick( selector=selector, modifiers=modifiers, - position=mapping.to_impl(position), + position=position, delay=delay, button=button, timeout=timeout, @@ -2313,7 +2318,7 @@ def textContent( Returns ------- - typing.Union[str, NoneType] + Optional[str] """ return mapping.from_maybe_impl( self._sync(self._impl_obj.textContent(selector=selector, timeout=timeout)) @@ -2377,7 +2382,7 @@ def getAttribute( Returns ------- - typing.Union[str, NoneType] + Optional[str] """ return mapping.from_maybe_impl( self._sync( @@ -2393,7 +2398,7 @@ def hover( modifiers: typing.Union[ typing.List[Literal["Alt", "Control", "Meta", "Shift"]] ] = None, - position: typing.Dict = None, + position: MousePosition = None, timeout: int = None, force: bool = None, ) -> NoneType: @@ -2406,9 +2411,9 @@ def hover( ---------- selector : str A selector to search for element to hover. If there are multiple elements satisfying the selector, the first will be hovered. See working with selectors for more details. - modifiers : Optional[typing.List[typing.Literal['Alt', 'Control', 'Meta', 'Shift']]] + modifiers : Optional[List[Literal['Alt', 'Control', 'Meta', 'Shift']]] Modifier keys to press. Ensures that only these modifiers are pressed during the hover, and then restores current modifiers back. If not specified, currently pressed modifiers are used. - position : Optional[typing.Dict] + position : Optional[{"x": float, "y": float}] A point to hover relative to the top-left corner of element padding box. If not specified, hovers over some visible point of the element. timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. @@ -2420,7 +2425,7 @@ def hover( self._impl_obj.hover( selector=selector, modifiers=modifiers, - position=mapping.to_impl(position), + position=position, timeout=timeout, force=force, ) @@ -2450,7 +2455,7 @@ def selectOption( ---------- selector : str A selector to query frame for. See working with selectors for more details. - values : Optional[str, ElementHandle, SelectOption, typing.List[str], typing.List[ElementHandle], typing.List[SelectOption]] + values : Union[str, ElementHandle, {"value": Optional[str], "label": Optional[str], "index": Optional[str]}, List[str], List[ElementHandle], List[{"value": Optional[str], "label": Optional[str], "index": Optional[str]}], NoneType] Options to select. If the `` has the `multiple` attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are equivalent to `{value:'string'}`. Option is considered matching if all specified properties match. timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. @@ -4507,7 +4512,7 @@ def selectOption( Returns ------- - typing.List[str] + List[str] An array of option values that have been successfully selected. """ return mapping.from_maybe_impl( @@ -4539,7 +4544,7 @@ def setInputFiles( ---------- selector : str A selector to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked. See working with selectors for more details. - files : typing.Union[str, FilePayload, typing.List[str], typing.List[FilePayload]] + files : Union[str, {"name": str, "mimeType": str, "buffer": Union[bytes, str]}, List[str], List[{"name": str, "mimeType": str, "buffer": Union[bytes, str]}]] timeout : Optional[int] Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods. noWaitAfter : Optional[bool] @@ -4745,11 +4750,11 @@ def waitForFunction( Function to be evaluated in browser context force_expr : bool Whether to treat given expression as JavaScript evaluate expression, even though it looks like an arrow function - arg : Optional[typing.Any] + arg : Optional[Any] Optional argument to pass to `pageFunction` timeout : Optional[int] 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 page.setDefaultTimeout(timeout) method. - polling : Optional[int, typing.Literal['raf']] + polling : Union[int, 'raf', NoneType] If `polling` is `'raf'`, then `pageFunction` is constantly executed in `requestAnimationFrame` callback. If `polling` is a number, then it is treated as an interval in milliseconds at which the function would be executed. Defaults to `raf`. Returns @@ -4782,7 +4787,7 @@ def pdf( width: typing.Union[str, float] = None, height: typing.Union[str, float] = None, preferCSSPageSize: bool = None, - margin: typing.Dict = None, + margin: PdfMargins = None, path: str = None, ) -> bytes: """Page.pdf @@ -4849,13 +4854,13 @@ def pdf( Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages. format : Optional[str] Paper format. If set, takes priority over `width` or `height` options. Defaults to 'Letter'. - width : Optional[str, float] + width : Union[str, float, NoneType] Paper width, accepts values labeled with units. - height : Optional[str, float] + height : Union[str, float, NoneType] Paper height, accepts values labeled with units. preferCSSPageSize : Optional[bool] Give any CSS `@page` size declared in the page priority over what is declared in `width` and `height` or `format` options. Defaults to `false`, which will scale the content to fit the paper size. - margin : Optional[typing.Dict] + margin : Optional[{"top": Union[str, int, NoneType], "right": Union[str, int, NoneType], "bottom": Union[str, int, NoneType], "left": Union[str, int, NoneType]}] Paper margins, defaults to none. path : Optional[str] The file path to save the PDF to. If `path` is a relative path, then it is resolved relative to current working directory. If no path is provided, the PDF won't be saved to the disk. @@ -4879,7 +4884,7 @@ def pdf( width=width, height=height, preferCSSPageSize=preferCSSPageSize, - margin=mapping.to_impl(margin), + margin=margin, path=path, ) ) @@ -5008,7 +5013,7 @@ def pages(self) -> typing.List["Page"]: Returns ------- - typing.List[Page] + List[Page] All open pages in the context. Non visible pages, such as `"background_page"`, will not be listed here. You can find them using chromiumBrowserContext.backgroundPages(). """ return mapping.from_impl_list(self._impl_obj.pages) @@ -5073,11 +5078,11 @@ def cookies( Parameters ---------- - urls : Optional[str, typing.List[str]] + urls : Union[str, List[str], NoneType] Returns ------- - typing.List[typing.Dict] + List[Dict] """ return mapping.from_maybe_impl(self._sync(self._impl_obj.cookies(urls=urls))) @@ -5087,7 +5092,7 @@ def addCookies(self, cookies: typing.List[typing.Dict]) -> NoneType: Parameters ---------- - cookies : typing.List[typing.Dict] + cookies : List[Dict] """ return mapping.from_maybe_impl( self._sync(self._impl_obj.addCookies(cookies=mapping.to_impl(cookies))) @@ -5109,7 +5114,7 @@ def grantPermissions( Parameters ---------- - permissions : typing.List[str] + permissions : List[str] A permission or an array of permissions to grant. Permissions can be one of the following values: - `'*'` - `'geolocation'` @@ -5144,7 +5149,7 @@ def clearPermissions(self) -> NoneType: """ return mapping.from_maybe_impl(self._sync(self._impl_obj.clearPermissions())) - def setGeolocation(self, geolocation: typing.Dict = None) -> NoneType: + def setGeolocation(self, geolocation: Geolocation = None) -> NoneType: """BrowserContext.setGeolocation Sets the context's geolocation. Passing `null` or `undefined` emulates position unavailable. @@ -5153,15 +5158,13 @@ def setGeolocation(self, geolocation: typing.Dict = None) -> NoneType: Parameters ---------- - geolocation : Optional[typing.Dict] + geolocation : Optional[{"latitude": float, "longitude": float, "accuracy": Optional[float]}] """ return mapping.from_maybe_impl( - self._sync( - self._impl_obj.setGeolocation(geolocation=mapping.to_impl(geolocation)) - ) + self._sync(self._impl_obj.setGeolocation(geolocation=geolocation)) ) - def setExtraHTTPHeaders(self, headers: typing.Dict) -> NoneType: + def setExtraHTTPHeaders(self, headers: typing.Dict[str, str]) -> NoneType: """BrowserContext.setExtraHTTPHeaders The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged with page-specific extra HTTP headers set with page.setExtraHTTPHeaders(). If page overrides a particular header, page-specific header value will be used instead of the browser context header value. @@ -5170,7 +5173,7 @@ def setExtraHTTPHeaders(self, headers: typing.Dict) -> NoneType: Parameters ---------- - headers : typing.Dict + headers : Dict[str, str] An object containing additional HTTP headers to be sent with every request. All header values must be strings. """ return mapping.from_maybe_impl( @@ -5228,7 +5231,7 @@ def exposeBinding(self, name: str, binding: typing.Callable) -> NoneType: ---------- name : str Name of the function on the window object. - binding : typing.Callable + binding : Callable Callback function that will be called in the Playwright's context. """ return mapping.from_maybe_impl( @@ -5252,7 +5255,7 @@ def exposeFunction(self, name: str, binding: typing.Callable) -> NoneType: ---------- name : str Name of the function on the window object. - binding : typing.Callable + binding : Callable Callback function that will be called in the Playwright's context. """ return mapping.from_maybe_impl( @@ -5280,9 +5283,9 @@ def route( Parameters ---------- - url : typing.Union[str, typing.Pattern, typing.Callable[[str], bool]] + url : Union[str, Pattern, typing.Callable[[str], bool]] A glob pattern, regex pattern or predicate receiving URL to match while routing. - handler : typing.Callable[[Route, Request], typing.Any] + handler : typing.Callable[[playwright.network.Route, playwright.network.Request], typing.Any] handler function to route the request. """ return mapping.from_maybe_impl( @@ -5304,9 +5307,9 @@ def unroute( Parameters ---------- - url : typing.Union[str, typing.Pattern, typing.Callable[[str], bool]] + url : Union[str, Pattern, typing.Callable[[str], bool]] A glob pattern, regex pattern or predicate receiving URL used to register a routing with browserContext.route(url, handler). - handler : Optional[typing.Callable[[Route, Request], typing.Any]] + handler : Optional[typing.Callable[[playwright.network.Route, playwright.network.Request], typing.Any]] Handler function used to register a routing with browserContext.route(url, handler). """ return mapping.from_maybe_impl( @@ -5335,7 +5338,7 @@ def waitForEvent( Returns ------- - typing.Any + Any Promise which resolves to the event data value. """ return mapping.from_maybe_impl( @@ -5393,12 +5396,12 @@ def send(self, method: str, params: typing.Dict = None) -> typing.Dict: ---------- method : str protocol method name - params : Optional[typing.Dict] + params : Optional[Dict] Optional method parameters Returns ------- - typing.Dict + Dict """ return mapping.from_maybe_impl( self._sync( @@ -5427,7 +5430,7 @@ def backgroundPages(self) -> typing.List["Page"]: Returns ------- - typing.List[Page] + List[Page] All existing background pages in the context. """ return mapping.from_impl_list(self._impl_obj.backgroundPages()) @@ -5437,7 +5440,7 @@ def serviceWorkers(self) -> typing.List["Worker"]: Returns ------- - typing.List[Worker] + List[Worker] All existing service workers in the context. """ return mapping.from_impl_list(self._impl_obj.serviceWorkers()) @@ -5476,7 +5479,7 @@ def contexts(self) -> typing.List["BrowserContext"]: Returns ------- - typing.List[BrowserContext] + List[BrowserContext] """ return mapping.from_impl_list(self._impl_obj.contexts) @@ -5493,18 +5496,18 @@ def isConnected(self) -> bool: def newContext( self, - viewport: typing.Union[typing.Dict, Literal[0]] = None, + viewport: typing.Union[IntSize, Literal[0]] = None, ignoreHTTPSErrors: bool = None, javaScriptEnabled: bool = None, bypassCSP: bool = None, userAgent: str = None, locale: str = None, timezoneId: str = None, - geolocation: typing.Dict = None, + geolocation: Geolocation = None, permissions: typing.List[str] = None, extraHTTPHeaders: typing.Union[typing.Dict[str, str]] = None, offline: bool = None, - httpCredentials: typing.Dict = None, + httpCredentials: Credentials = None, deviceScaleFactor: int = None, isMobile: bool = None, hasTouch: bool = None, @@ -5517,7 +5520,7 @@ def newContext( Parameters ---------- - viewport : Optional[typing.Dict, typing.Literal[0]] + viewport : Union[{"width": int, "height": int}, '0', NoneType] Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `null` disables the default viewport. ignoreHTTPSErrors : Optional[bool] Whether to ignore HTTPS errors during navigation. Defaults to `false`. @@ -5531,14 +5534,14 @@ def newContext( Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules. timezoneId : Optional[str] Changes the timezone of the context. See ICU’s `metaZones.txt` for a list of supported timezone IDs. - geolocation : Optional[typing.Dict] - permissions : Optional[typing.List[str]] + geolocation : Optional[{"latitude": float, "longitude": float, "accuracy": Optional[float]}] + permissions : Optional[List[str]] A list of permissions to grant to all pages in this context. See browserContext.grantPermissions for more details. - extraHTTPHeaders : Optional[typing.Dict[str, str]] + extraHTTPHeaders : Optional[Dict[str, str]] An object containing additional HTTP headers to be sent with every request. All header values must be strings. offline : Optional[bool] Whether to emulate network being offline. Defaults to `false`. - httpCredentials : Optional[typing.Dict] + httpCredentials : Optional[{"username": str, "password": str}] Credentials for HTTP authentication. deviceScaleFactor : Optional[int] Specify device scale factor (can be thought of as dpr). Defaults to `1`. @@ -5546,7 +5549,7 @@ def newContext( Whether the `meta viewport` tag is taken into account and touch events are enabled. Defaults to `false`. Not supported in Firefox. hasTouch : Optional[bool] Specifies if viewport supports touch events. Defaults to false. - colorScheme : Optional[typing.Literal['light', 'dark', 'no-preference']] + colorScheme : Optional[Literal['light', 'dark', 'no-preference']] Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See page.emulateMedia(options) for more details. Defaults to '`light`'. acceptDownloads : Optional[bool] Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled. @@ -5558,18 +5561,18 @@ def newContext( return mapping.from_impl( self._sync( self._impl_obj.newContext( - viewport=mapping.to_impl(viewport), + viewport=viewport, ignoreHTTPSErrors=ignoreHTTPSErrors, javaScriptEnabled=javaScriptEnabled, bypassCSP=bypassCSP, userAgent=userAgent, locale=locale, timezoneId=timezoneId, - geolocation=mapping.to_impl(geolocation), + geolocation=geolocation, permissions=permissions, extraHTTPHeaders=mapping.to_impl(extraHTTPHeaders), offline=offline, - httpCredentials=mapping.to_impl(httpCredentials), + httpCredentials=httpCredentials, deviceScaleFactor=deviceScaleFactor, isMobile=isMobile, hasTouch=hasTouch, @@ -5581,18 +5584,18 @@ def newContext( def newPage( self, - viewport: typing.Union[typing.Dict, Literal[0]] = None, + viewport: typing.Union[IntSize, Literal[0]] = None, ignoreHTTPSErrors: bool = None, javaScriptEnabled: bool = None, bypassCSP: bool = None, userAgent: str = None, locale: str = None, timezoneId: str = None, - geolocation: typing.Dict = None, + geolocation: Geolocation = None, permissions: typing.List[str] = None, extraHTTPHeaders: typing.Union[typing.Dict[str, str]] = None, offline: bool = None, - httpCredentials: typing.Dict = None, + httpCredentials: Credentials = None, deviceScaleFactor: int = None, isMobile: bool = None, hasTouch: bool = None, @@ -5606,7 +5609,7 @@ def newPage( Parameters ---------- - viewport : Optional[typing.Dict, typing.Literal[0]] + viewport : Union[{"width": int, "height": int}, '0', NoneType] Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `null` disables the default viewport. ignoreHTTPSErrors : Optional[bool] Whether to ignore HTTPS errors during navigation. Defaults to `false`. @@ -5620,14 +5623,14 @@ def newPage( Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules. timezoneId : Optional[str] Changes the timezone of the context. See ICU’s `metaZones.txt` for a list of supported timezone IDs. - geolocation : Optional[typing.Dict] - permissions : Optional[typing.List[str]] + geolocation : Optional[{"latitude": float, "longitude": float, "accuracy": Optional[float]}] + permissions : Optional[List[str]] A list of permissions to grant to all pages in this context. See browserContext.grantPermissions for more details. - extraHTTPHeaders : Optional[typing.Dict[str, str]] + extraHTTPHeaders : Optional[Dict[str, str]] An object containing additional HTTP headers to be sent with every request. All header values must be strings. offline : Optional[bool] Whether to emulate network being offline. Defaults to `false`. - httpCredentials : Optional[typing.Dict] + httpCredentials : Optional[{"username": str, "password": str}] Credentials for HTTP authentication. deviceScaleFactor : Optional[int] Specify device scale factor (can be thought of as dpr). Defaults to `1`. @@ -5635,7 +5638,7 @@ def newPage( Whether the `meta viewport` tag is taken into account and touch events are enabled. Defaults to `false`. Not supported in Firefox. hasTouch : Optional[bool] Specifies if viewport supports touch events. Defaults to false. - colorScheme : Optional[typing.Literal['light', 'dark', 'no-preference']] + colorScheme : Optional[Literal['light', 'dark', 'no-preference']] Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See page.emulateMedia(options) for more details. Defaults to '`light`'. acceptDownloads : Optional[bool] Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled. @@ -5647,18 +5650,18 @@ def newPage( return mapping.from_impl( self._sync( self._impl_obj.newPage( - viewport=mapping.to_impl(viewport), + viewport=viewport, ignoreHTTPSErrors=ignoreHTTPSErrors, javaScriptEnabled=javaScriptEnabled, bypassCSP=bypassCSP, userAgent=userAgent, locale=locale, timezoneId=timezoneId, - geolocation=mapping.to_impl(geolocation), + geolocation=geolocation, permissions=permissions, extraHTTPHeaders=mapping.to_impl(extraHTTPHeaders), offline=offline, - httpCredentials=mapping.to_impl(httpCredentials), + httpCredentials=httpCredentials, deviceScaleFactor=deviceScaleFactor, isMobile=isMobile, hasTouch=hasTouch, @@ -5762,15 +5765,15 @@ def launch( self, executablePath: str = None, args: typing.List[str] = None, - ignoreDefaultArgs: typing.List[str] = None, + ignoreDefaultArgs: typing.Union[bool, typing.List[str]] = None, handleSIGINT: bool = None, handleSIGTERM: bool = None, handleSIGHUP: bool = None, timeout: int = None, - env: typing.Dict = None, + env: typing.Union[typing.Dict[str, typing.Union[str, int, bool]]] = None, headless: bool = None, devtools: bool = None, - proxy: typing.Dict = None, + proxy: ProxyServer = None, downloadsPath: str = None, slowMo: int = None, chromiumSandbox: bool = None, @@ -5788,9 +5791,9 @@ def launch( ---------- executablePath : Optional[str] Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to current working directory. Note that Playwright only works with the bundled Chromium, Firefox or WebKit, use at your own risk. - args : Optional[typing.List[str]] + args : Optional[List[str]] Additional arguments to pass to the browser instance. The list of Chromium flags can be found here. - ignoreDefaultArgs : Optional[typing.List[str]] + ignoreDefaultArgs : Union[bool, List[str], NoneType] If `true`, Playwright does not pass its own configurations args and only uses the ones from `args`. If an array is given, then filters out the given default arguments. Dangerous option; use with care. Defaults to `false`. handleSIGINT : Optional[bool] Close the browser process on Ctrl-C. Defaults to `true`. @@ -5800,13 +5803,13 @@ def launch( Close the browser process on SIGHUP. Defaults to `true`. timeout : Optional[int] Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - env : Optional[typing.Dict] + env : Optional[Dict[str, Union[str, int, bool]]] Specify environment variables that will be visible to the browser. Defaults to `process.env`. headless : Optional[bool] Whether to run browser in headless mode. More details for Chromium and Firefox. Defaults to `true` unless the `devtools` option is `true`. devtools : Optional[bool] **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless` option will be set `false`. - proxy : Optional[typing.Dict] + proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}] Network proxy settings. downloadsPath : Optional[str] If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed. @@ -5833,7 +5836,7 @@ def launch( env=mapping.to_impl(env), headless=headless, devtools=devtools, - proxy=mapping.to_impl(proxy), + proxy=proxy, downloadsPath=downloadsPath, slowMo=slowMo, chromiumSandbox=chromiumSandbox, @@ -5845,19 +5848,19 @@ def launchServer( self, executablePath: str = None, args: typing.List[str] = None, - ignoreDefaultArgs: typing.List[str] = None, + ignoreDefaultArgs: typing.Union[bool, typing.List[str]] = None, handleSIGINT: bool = None, handleSIGTERM: bool = None, handleSIGHUP: bool = None, timeout: int = None, - env: typing.Dict = None, + env: typing.Union[typing.Dict[str, typing.Union[str, int, bool]]] = None, headless: bool = None, devtools: bool = None, - proxy: typing.Dict = None, + proxy: ProxyServer = None, downloadsPath: str = None, port: int = None, chromiumSandbox: bool = None, - ) -> "Browser": + ) -> "BrowserServer": """BrowserType.launchServer Launches browser server that client can connect to. An example of launching a browser executable and connecting to it later: @@ -5866,9 +5869,9 @@ def launchServer( ---------- executablePath : Optional[str] Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to current working directory. **BEWARE**: Playwright is only guaranteed to work with the bundled Chromium, Firefox or WebKit, use at your own risk. - args : Optional[typing.List[str]] + args : Optional[List[str]] Additional arguments to pass to the browser instance. The list of Chromium flags can be found here. - ignoreDefaultArgs : Optional[typing.List[str]] + ignoreDefaultArgs : Union[bool, List[str], NoneType] If `true`, then do not use any of the default arguments. If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to `false`. handleSIGINT : Optional[bool] Close the browser process on Ctrl-C. Defaults to `true`. @@ -5878,13 +5881,13 @@ def launchServer( Close the browser process on SIGHUP. Defaults to `true`. timeout : Optional[int] Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - env : Optional[typing.Dict] + env : Optional[Dict[str, Union[str, int, bool]]] Specify environment variables that will be visible to the browser. Defaults to `process.env`. headless : Optional[bool] Whether to run browser in headless mode. More details for Chromium and Firefox. Defaults to `true` unless the `devtools` option is `true`. devtools : Optional[bool] **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless` option will be set `false`. - proxy : Optional[typing.Dict] + proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}] Network proxy settings. downloadsPath : Optional[str] If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed. @@ -5895,7 +5898,7 @@ def launchServer( Returns ------- - Browser + BrowserServer Promise which resolves to the browser app instance. """ return mapping.from_impl( @@ -5911,7 +5914,7 @@ def launchServer( env=mapping.to_impl(env), headless=headless, devtools=devtools, - proxy=mapping.to_impl(proxy), + proxy=proxy, downloadsPath=downloadsPath, port=port, chromiumSandbox=chromiumSandbox, @@ -5924,29 +5927,29 @@ def launchPersistentContext( userDataDir: str, executablePath: str = None, args: typing.List[str] = None, - ignoreDefaultArgs: typing.List[str] = None, + ignoreDefaultArgs: typing.Union[bool, typing.List[str]] = None, handleSIGINT: bool = None, handleSIGTERM: bool = None, handleSIGHUP: bool = None, timeout: int = None, - env: typing.Dict = None, + env: typing.Union[typing.Dict[str, typing.Union[str, int, bool]]] = None, headless: bool = None, devtools: bool = None, - proxy: typing.Dict = None, + proxy: ProxyServer = None, downloadsPath: str = None, slowMo: int = None, - viewport: typing.Dict = None, + viewport: IntSize = None, ignoreHTTPSErrors: bool = None, javaScriptEnabled: bool = None, bypassCSP: bool = None, userAgent: str = None, locale: str = None, timezoneId: str = None, - geolocation: typing.Dict = None, + geolocation: Geolocation = None, permissions: typing.List[str] = None, extraHTTPHeaders: typing.Union[typing.Dict[str, str]] = None, offline: bool = None, - httpCredentials: typing.Dict = None, + httpCredentials: Credentials = None, deviceScaleFactor: int = None, isMobile: bool = None, hasTouch: bool = None, @@ -5964,9 +5967,9 @@ def launchPersistentContext( Path to a User Data Directory, which stores browser session data like cookies and local storage. More details for Chromium and Firefox. executablePath : Optional[str] Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to current working directory. **BEWARE**: Playwright is only guaranteed to work with the bundled Chromium, Firefox or WebKit, use at your own risk. - args : Optional[typing.List[str]] + args : Optional[List[str]] Additional arguments to pass to the browser instance. The list of Chromium flags can be found here. - ignoreDefaultArgs : Optional[typing.List[str]] + ignoreDefaultArgs : Union[bool, List[str], NoneType] If `true`, then do not use any of the default arguments. If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to `false`. handleSIGINT : Optional[bool] Close the browser process on Ctrl-C. Defaults to `true`. @@ -5976,19 +5979,19 @@ def launchPersistentContext( Close the browser process on SIGHUP. Defaults to `true`. timeout : Optional[int] Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - env : Optional[typing.Dict] + env : Optional[Dict[str, Union[str, int, bool]]] Specify environment variables that will be visible to the browser. Defaults to `process.env`. headless : Optional[bool] Whether to run browser in headless mode. More details for Chromium and Firefox. Defaults to `true` unless the `devtools` option is `true`. devtools : Optional[bool] **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless` option will be set `false`. - proxy : Optional[typing.Dict] + proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}] Network proxy settings. downloadsPath : Optional[str] If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed. slowMo : Optional[int] Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on. Defaults to 0. - viewport : Optional[typing.Dict] + viewport : Optional[{"width": int, "height": int}] Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `null` disables the default viewport. ignoreHTTPSErrors : Optional[bool] Whether to ignore HTTPS errors during navigation. Defaults to `false`. @@ -6002,14 +6005,14 @@ def launchPersistentContext( Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules. timezoneId : Optional[str] Changes the timezone of the context. See ICU’s `metaZones.txt` for a list of supported timezone IDs. - geolocation : Optional[typing.Dict] - permissions : Optional[typing.List[str]] + geolocation : Optional[{"latitude": float, "longitude": float, "accuracy": Optional[float]}] + permissions : Optional[List[str]] A list of permissions to grant to all pages in this context. See browserContext.grantPermissions for more details. - extraHTTPHeaders : Optional[typing.Dict[str, str]] + extraHTTPHeaders : Optional[Dict[str, str]] An object containing additional HTTP headers to be sent with every request. All header values must be strings. offline : Optional[bool] Whether to emulate network being offline. Defaults to `false`. - httpCredentials : Optional[typing.Dict] + httpCredentials : Optional[{"username": str, "password": str}] Credentials for HTTP authentication. deviceScaleFactor : Optional[int] Specify device scale factor (can be thought of as dpr). Defaults to `1`. @@ -6017,7 +6020,7 @@ def launchPersistentContext( Whether the `meta viewport` tag is taken into account and touch events are enabled. Defaults to `false`. Not supported in Firefox. hasTouch : Optional[bool] Specifies if viewport supports touch events. Defaults to false. - colorScheme : Optional[typing.Literal['light', 'dark', 'no-preference']] + colorScheme : Optional[Literal['light', 'dark', 'no-preference']] Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See page.emulateMedia(options) for more details. Defaults to '`light`'. acceptDownloads : Optional[bool] Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled. @@ -6043,21 +6046,21 @@ def launchPersistentContext( env=mapping.to_impl(env), headless=headless, devtools=devtools, - proxy=mapping.to_impl(proxy), + proxy=proxy, downloadsPath=downloadsPath, slowMo=slowMo, - viewport=mapping.to_impl(viewport), + viewport=viewport, ignoreHTTPSErrors=ignoreHTTPSErrors, javaScriptEnabled=javaScriptEnabled, bypassCSP=bypassCSP, userAgent=userAgent, locale=locale, timezoneId=timezoneId, - geolocation=mapping.to_impl(geolocation), + geolocation=geolocation, permissions=permissions, extraHTTPHeaders=mapping.to_impl(extraHTTPHeaders), offline=offline, - httpCredentials=mapping.to_impl(httpCredentials), + httpCredentials=httpCredentials, deviceScaleFactor=deviceScaleFactor, isMobile=isMobile, hasTouch=hasTouch, diff --git a/scripts/documentation_provider.py b/scripts/documentation_provider.py index 390793dee..0cb259c34 100644 --- a/scripts/documentation_provider.py +++ b/scripts/documentation_provider.py @@ -15,11 +15,34 @@ import json import re from sys import stderr -from typing import Any, Dict, List +from typing import ( # type: ignore + Any, + Dict, + List, + Union, + get_args, + get_origin, + get_type_hints, +) enum_regex = r"^\"[^\"]+\"(?:\|\"[^\"]+\")+$" union_regex = r"^[^\|]+(?:\|[^\|]+)+$" +exceptions = { + "Route.fulfill(path=)": { + "doc": "Optional[str]", + "code": "Union[str, pathlib.Path, NoneType]", + }, + "Browser.newContext(viewport=)": { + "doc": 'Optional[{"width": int, "height": int}]', + "code": 'Union[{"width": int, "height": int}, \'0\', NoneType]', + }, + "Browser.newPage(viewport=)": { + "doc": 'Optional[{"width": int, "height": int}]', + "code": 'Union[{"width": int, "height": int}, \'0\', NoneType]', + }, +} + class DocumentationProvider: def __init__(self) -> None: @@ -91,11 +114,9 @@ def print_entry( file=stderr, ) else: - code_type = self.normalize_class_type(value) + code_type = self.serialize_python_type(value) - print( - f"{indent}{original_name} : {self.beautify_code_type(code_type)}" - ) + print(f"{indent}{original_name} : {code_type}") if doc_value["comment"]: print( f"{indent} {self.indent_paragraph(doc_value['comment'], f'{indent} ')}" @@ -112,13 +133,12 @@ def print_entry( and str(signature["return"]) != "" ): value = signature["return"] - code_type = self.normalize_class_type(value) doc_value = method - self.compare_types(code_type, doc_value, f"{fqname}(return=)") + self.compare_types(value, doc_value, f"{fqname}(return=)") print("") print(" Returns") print(" -------") - print(f" {self.normalize_class_type(signature['return'])}") + print(f" {self.serialize_python_type(value)}") if method["returnComment"]: print( f" {self.indent_paragraph(method['returnComment'], ' ')}" @@ -132,12 +152,6 @@ def print_entry( file=stderr, ) - def normalize_class_type(self, value: Any) -> str: - code_type = str(value) - code_type = re.sub(r"", r"\1", code_type) - code_type = re.sub(r"playwright\.[\w]+\.([\w]+)", r"\1", code_type) - return code_type - def indent_paragraph(self, p: str, indent: str) -> str: lines = p.split("\n") result = [lines[0]] @@ -165,84 +179,177 @@ def beautify_method_comment(self, comment: str, indent: str) -> str: in_example = False return self.indent_paragraph("\n".join(result), indent) - def beautify_code_type(self, code_type: str) -> str: - return re.sub(r"^typing.Union\[(.*), NoneType\]$", r"Optional[\1]", code_type) + def make_optional(self, text: str) -> str: + if text.startswith("Union["): + return text[:-1] + ", NoneType]" + if text.startswith("Optional["): + return text + return f"Optional[{text}]" - def compare_types(self, code_type: str, doc_value: Any, fqname: str) -> None: - type_name = doc_value["type"]["name"] - doc_type = self.serialize_doc_type(type_name, fqname) + def compare_types(self, value: Any, doc_value: Any, fqname: str) -> None: + if "(arg=)" in fqname or "(pageFunction=)" in fqname: + return + code_type = self.serialize_python_type(value) + doc_type = self.serialize_doc_type( + doc_value["type"]["name"], fqname, doc_value["type"], + ) if not doc_value["required"]: - doc_type = f"typing.Union[{doc_type}, NoneType]" + doc_type = self.make_optional(doc_type) + if ( + fqname in exceptions + and exceptions[fqname]["doc"] == doc_type + and exceptions[fqname]["code"] == code_type + ): + return + if doc_type != code_type: print( f"Parameter type mismatch in {fqname}: documented as {doc_type}, code has {code_type}", file=stderr, ) - def serialize_doc_type(self, doc_value: Any, fqname: str) -> str: - if doc_value == "string": + def serialize_python_type(self, value: Any) -> str: + str_value = str(value) + if str_value == "": + return "Error" + match = re.match(r"^$", str_value) + if match: + return match.group(1) + match = re.match(r"^$", str_value) + if match and "helper" not in str_value: + return match.group(1) + + match = re.match(r"^typing\.(\w+)$", str_value) + if match: + return match.group(1) + + origin = get_origin(value) + args = get_args(value) + hints = None + try: + hints = get_type_hints(value) + except Exception: + pass + if hints: + signature: List[str] = [] + for [name, value] in hints.items(): + signature.append(f'"{name}": {self.serialize_python_type(value)}') + return f"{{{', '.join(signature)}}}" + if origin == Union: + args = get_args(value) + if len(args) == 2 and "None" in str(args[1]): + return self.make_optional(self.serialize_python_type(args[0])) + return f"Union[{', '.join(list(map(lambda a: self.serialize_python_type(a), args)))}]" + if str(origin) == "": + args = get_args(value) + return f"Dict[{', '.join(list(map(lambda a: self.serialize_python_type(a), args)))}]" + if str(origin) == "": + args = get_args(value) + return f"List[{', '.join(list(map(lambda a: self.serialize_python_type(a), args)))}]" + if str(origin) == "typing.Literal": + args = get_args(value) + if len(args) == 1: + return "'" + self.serialize_python_type(args[0]) + "'" + body = ", ".join( + list(map(lambda a: "'" + self.serialize_python_type(a) + "'", args)) + ) + return f"Literal[{body}]" + return str_value + + def serialize_doc_type( + self, type_name: Any, fqname: str, doc_type: Any = None + ) -> str: + type_name = re.sub(r"^Promise<(.*)>$", r"\1", type_name) + + if type_name == "string": return "str" - if doc_value == "Buffer": + if type_name == "Buffer": return "bytes" - if doc_value == "boolean": + if type_name == "Array": + return "List" + + if type_name == "boolean": return "bool" - if doc_value == "number": + if type_name == "number": if "Mouse" in fqname and ("(x=)" in fqname or "(y=)" in fqname): return "float" - elif fqname == "Page.pdf(width=)" or fqname == "Page.pdf(height=)": + if ( + "(position=)" in fqname + or "(geolocation=)" in fqname + or ".boundingBox(" in fqname + ): return "float" - else: - return "int" - - if doc_value == "Object": - return "typing.Dict" - - if doc_value == "?Object": - return "typing.Union[typing.Dict, NoneType]" + if "screenshot(clip=)" in fqname: + return "float" + if fqname == "Page.pdf(width=)" or fqname == "Page.pdf(height=)": + return "float" + return "int" + + if type_name == "Serializable": + return "Any" + + if type_name == "Object" or type_name == "?Object": + intermediate = "Dict" + if doc_type and len(doc_type["properties"]): + signature: List[str] = [] + for [name, value] in doc_type["properties"].items(): + value_type = self.serialize_doc_type( + value["type"]["name"], fqname, value["type"] + ) + signature.append( + f"\"{name}\": {value_type if value['required'] else self.make_optional(value_type)}" + ) + intermediate = f"{{{', '.join(signature)}}}" + return ( + intermediate + if type_name == "Object" + else self.make_optional(intermediate) + ) - if doc_value == "function": - return "typing.Callable" + if type_name == "function": + return "Callable" - match = re.match(r"^Object<([^,]+),\s*([^)]+)>$", doc_value) + match = re.match(r"^Object<([^,]+),\s*([^)]+)>$", type_name) if match: - return f"typing.Dict[{self.serialize_doc_type(match.group(1), fqname)}, {self.serialize_doc_type(match.group(2), fqname)}]" + return f"Dict[{self.serialize_doc_type(match.group(1), fqname)}, {self.serialize_doc_type(match.group(2), fqname)}]" - match = re.match(r"^Promise<(.*)>$", doc_value) + match = re.match(r"^Map<([^,]+),\s*([^)]+)>$", type_name) if match: - return self.serialize_doc_type(match.group(1), fqname) + return f"Dict[{self.serialize_doc_type(match.group(1), fqname)}, {self.serialize_doc_type(match.group(2), fqname)}]" - if re.match(enum_regex, doc_value): - result = f"typing.Literal[{', '.join(doc_value.split('|'))}]" + if re.match(enum_regex, type_name): + result = f"Literal[{', '.join(type_name.split('|'))}]" return result.replace('"', "'") - match = re.match(r"^Array<(.*)>$", doc_value) + match = re.match(r"^Array<(.*)>$", type_name) if match: - return f"typing.List[{self.serialize_doc_type(match.group(1), fqname)}]" + return f"List[{self.serialize_doc_type(match.group(1), fqname)}]" - match = re.match(r"^\?(.*)$", doc_value) + match = re.match(r"^\?(.*)$", type_name) if match: - return f"typing.Union[{self.serialize_doc_type(match.group(1), fqname)}, NoneType]" + return self.make_optional(self.serialize_doc_type(match.group(1), fqname)) - match = re.match(r"^null\|(.*)$", doc_value) + match = re.match(r"^null\|(.*)$", type_name) if match: - return f"typing.Union[{self.serialize_doc_type(match.group(1), fqname)}, NoneType]" + return self.make_optional(self.serialize_doc_type(match.group(1), fqname)) # Union detection is greedy - if re.match(union_regex, doc_value): + if re.match(union_regex, type_name): result = ", ".join( list( map( lambda a: self.serialize_doc_type(a, fqname), - doc_value.split("|"), + type_name.split("|"), ) ) ) - return result.replace('"', "'") + body = result.replace('"', "'") + return f"Union[{body}]" - return doc_value + return type_name def rewrite_param_name(self, fqname: str, method_name: str, name: str) -> str: if name == "expression": diff --git a/scripts/generate_api.py b/scripts/generate_api.py index bd242dc9b..30e1f25a0 100644 --- a/scripts/generate_api.py +++ b/scripts/generate_api.py @@ -39,7 +39,7 @@ from playwright.file_chooser import FileChooser from playwright.frame import Frame from playwright.input import Keyboard, Mouse -from playwright.js_handle import JSHandle +from playwright.js_handle import JSHandle, Serializable from playwright.network import Request, Response, Route from playwright.page import BindingCall, Page, Worker from playwright.playwright import Playwright @@ -164,7 +164,7 @@ def return_value(value: Any) -> List[str]: from playwright.element_handle import ElementHandle as ElementHandleImpl from playwright.file_chooser import FileChooser as FileChooserImpl from playwright.frame import Frame as FrameImpl -from playwright.helper import ConsoleMessageLocation, Error, FilePayload, SelectOption, Viewport, DeviceDescriptor +from playwright.helper import ConsoleMessageLocation, Credentials, MousePosition, Error, FilePayload, SelectOption, RequestFailure, Viewport, DeviceDescriptor, IntSize, FloatRect, Geolocation, ProxyServer, PdfMargins from playwright.input import Keyboard as KeyboardImpl, Mouse as MouseImpl from playwright.js_handle import JSHandle as JSHandleImpl from playwright.network import Request as RequestImpl, Response as ResponseImpl, Route as RouteImpl @@ -202,3 +202,4 @@ def return_value(value: Any) -> List[str]: api_globals = globals() assert ValuesToSelect +assert Serializable diff --git a/tests/async/test_interception.py b/tests/async/test_interception.py index b188be488..817a400ad 100644 --- a/tests/async/test_interception.py +++ b/tests/async/test_interception.py @@ -257,11 +257,11 @@ async def test_page_route_should_be_abortable_with_custom_error_codes( assert len(failed_requests) == 1 failed_request = failed_requests[0] if is_webkit: - assert failed_request.failure == "Request intercepted" + assert failed_request.failure["errorText"] == "Request intercepted" elif is_firefox: - assert failed_request.failure == "NS_ERROR_OFFLINE" + assert failed_request.failure["errorText"] == "NS_ERROR_OFFLINE" else: - assert failed_request.failure == "net::ERR_INTERNET_DISCONNECTED" + assert failed_request.failure["errorText"] == "net::ERR_INTERNET_DISCONNECTED" async def test_page_route_should_send_referer(page, server): diff --git a/tests/async/test_network.py b/tests/async/test_network.py index 90ae4415b..7d64f3614 100644 --- a/tests/async/test_network.py +++ b/tests/async/test_network.py @@ -336,19 +336,22 @@ def handle_request(request): assert await failed_requests[0].response() is None assert failed_requests[0].resourceType == "stylesheet" if is_chromium: - assert failed_requests[0].failure == "net::ERR_EMPTY_RESPONSE" + assert failed_requests[0].failure["errorText"] == "net::ERR_EMPTY_RESPONSE" elif is_webkit: if is_mac: - assert failed_requests[0].failure == "The network connection was lost." + assert ( + failed_requests[0].failure["errorText"] + == "The network connection was lost." + ) elif is_win: assert ( - failed_requests[0].failure + failed_requests[0].failure["errorText"] == "Server returned nothing (no headers, no data)" ) else: - assert failed_requests[0].failure == "Message Corrupt" + assert failed_requests[0].failure["errorText"] == "Message Corrupt" else: - assert failed_requests[0].failure == "NS_ERROR_NET_RESET" + assert failed_requests[0].failure["errorText"] == "NS_ERROR_NET_RESET" assert failed_requests[0].frame