1313# limitations under the License.
1414
1515import base64
16- import mimetypes
1716from pathlib import Path
1817from typing import (
1918 TYPE_CHECKING ,
@@ -122,6 +121,7 @@ async def hover(
122121 noWaitAfter : bool = None ,
123122 force : bool = None ,
124123 trial : bool = None ,
124+ scroll : Literal ["auto" , "none" ] = None ,
125125 ) -> None :
126126 await self ._channel .send (
127127 "hover" , self ._frame ._timeout , locals_to_params (locals ())
@@ -139,6 +139,7 @@ async def click(
139139 noWaitAfter : bool = None ,
140140 trial : bool = None ,
141141 steps : int = None ,
142+ scroll : Literal ["auto" , "none" ] = None ,
142143 ) -> None :
143144 await self ._channel .send (
144145 "click" , self ._frame ._timeout , locals_to_params (locals ())
@@ -155,6 +156,7 @@ async def dblclick(
155156 noWaitAfter : bool = None ,
156157 trial : bool = None ,
157158 steps : int = None ,
159+ scroll : Literal ["auto" , "none" ] = None ,
158160 ) -> None :
159161 await self ._channel .send (
160162 "dblclick" , self ._frame ._timeout , locals_to_params (locals ())
@@ -187,6 +189,7 @@ async def tap(
187189 force : bool = None ,
188190 noWaitAfter : bool = None ,
189191 trial : bool = None ,
192+ scroll : Literal ["auto" , "none" ] = None ,
190193 ) -> None :
191194 await self ._channel .send (
192195 "tap" , self ._frame ._timeout , locals_to_params (locals ())
@@ -267,20 +270,23 @@ async def set_checked(
267270 force : bool = None ,
268271 noWaitAfter : bool = None ,
269272 trial : bool = None ,
273+ scroll : Literal ["auto" , "none" ] = None ,
270274 ) -> None :
271275 if checked :
272276 await self .check (
273277 position = position ,
274278 timeout = timeout ,
275279 force = force ,
276280 trial = trial ,
281+ scroll = scroll ,
277282 )
278283 else :
279284 await self .uncheck (
280285 position = position ,
281286 timeout = timeout ,
282287 force = force ,
283288 trial = trial ,
289+ scroll = scroll ,
284290 )
285291
286292 async def check (
@@ -290,6 +296,7 @@ async def check(
290296 force : bool = None ,
291297 noWaitAfter : bool = None ,
292298 trial : bool = None ,
299+ scroll : Literal ["auto" , "none" ] = None ,
293300 ) -> None :
294301 await self ._channel .send (
295302 "check" , self ._frame ._timeout , locals_to_params (locals ())
@@ -302,6 +309,7 @@ async def uncheck(
302309 force : bool = None ,
303310 noWaitAfter : bool = None ,
304311 trial : bool = None ,
312+ scroll : Literal ["auto" , "none" ] = None ,
305313 ) -> None :
306314 await self ._channel .send (
307315 "uncheck" , self ._frame ._timeout , locals_to_params (locals ())
@@ -313,7 +321,7 @@ async def bounding_box(self) -> Optional[FloatRect]:
313321 async def screenshot (
314322 self ,
315323 timeout : float = None ,
316- type : Literal ["jpeg" , "png" ] = None ,
324+ type : Literal ["jpeg" , "png" , "webp" ] = None ,
317325 path : Union [str , Path ] = None ,
318326 quality : int = None ,
319327 omitBackground : bool = None ,
@@ -457,10 +465,16 @@ def convert_select_option_values(
457465 return dict (options = options , elements = elements )
458466
459467
460- def determine_screenshot_type (path : Union [str , Path ]) -> Literal ["jpeg" , "png" ]:
461- mime_type , _ = mimetypes .guess_type (path )
462- if mime_type == "image/png" :
468+ def determine_screenshot_type (path : Union [str , Path ]) -> Literal ["jpeg" , "png" , "webp" ]:
469+ # Detect by file extension rather than mimetypes.guess_type, whose result is
470+ # OS-dependent (e.g. Windows does not register image/webp), mirroring
471+ # upstream's getMimeTypeForPath extension map:
472+ # https://github.com/microsoft/playwright/blob/e0e814deed7b0a4c4d2bdf98481e6be7419cda16/packages/isomorphic/mimeType.ts#L28
473+ suffix = Path (path ).suffix .lower ()
474+ if suffix == ".png" :
463475 return "png"
464- if mime_type == "image/ jpeg" :
476+ if suffix in ( ". jpeg", ".jpg" ) :
465477 return "jpeg"
466- raise Error (f'Unsupported screenshot mime type for path "{ path } ": { mime_type } ' )
478+ if suffix == ".webp" :
479+ return "webp"
480+ raise Error (f'path: unsupported mime type "{ suffix } "' )
0 commit comments