@@ -163,7 +163,9 @@ async def _get_contents_with_browser(self, url: str, browser: Browser) -> str:
163163 finally :
164164 await page .close ()
165165
166- def cast [T : msgspec .Struct ](self , url : str , * , to : type [T ]) -> T :
166+ def cast [T : msgspec .Struct ](
167+ self , url : str , * , to : type [T ], browser : Browser | None = None
168+ ) -> T :
167169 """
168170 Synchronously casts a webpage's content into a structured output.
169171
@@ -185,9 +187,11 @@ def cast[T: msgspec.Struct](self, url: str, *, to: type[T]) -> T:
185187 >>> data = webson.cast("https://example.com", to=PageData)
186188 >>> print(data.title)
187189 """
188- return run_sync (self .cast_async , url , to = to )
190+ return run_sync (self .cast_async , url , to = to , browser = browser )
189191
190- async def cast_async [T : msgspec .Struct ](self , url : str , * , to : type [T ]) -> T :
192+ async def cast_async [T : msgspec .Struct ](
193+ self , url : str , * , to : type [T ], browser : Browser | None = None
194+ ) -> T :
191195 """
192196 Asynchronously casts a webpage's content into a structured output.
193197
@@ -208,7 +212,7 @@ async def cast_async[T: msgspec.Struct](self, url: str, *, to: type[T]) -> T:
208212 >>> print(structured_data)
209213 """
210214 # Retrieve the raw HTML page contents asynchronously.
211- page_contents = await self .get_contents_async (url )
215+ page_contents = await self .get_contents_async (url , browser = browser )
212216
213217 # Convert the HTML to markdown for easier parsing.
214218 page_md = cast (str , md (page_contents ))
0 commit comments