1313from playwright .sync_api import Page
1414
1515from .browser import AsyncSentienceBrowser , SentienceBrowser
16+ from .sentience_methods import SentienceMethod
1617
1718
1819class BrowserEvaluator :
@@ -126,18 +127,18 @@ async def _gather_diagnostics_async(page: AsyncPage) -> dict[str, Any]:
126127 return {"error" : "Could not gather diagnostics" }
127128
128129 @staticmethod
129- def call_sentience_method (
130+ def invoke (
130131 page : Page ,
131- method_name : str ,
132+ method : SentienceMethod | str ,
132133 * args : Any ,
133134 ** kwargs : Any ,
134135 ) -> Any :
135136 """
136- Call a window.sentience method with error handling.
137+ Invoke a window.sentience method with error handling (sync) .
137138
138139 Args:
139140 page: Playwright Page instance (sync)
140- method_name: Name of the method (e.g., "snapshot", "click ")
141+ method: SentienceMethod enum value or method name string (e.g., SentienceMethod.SNAPSHOT or "snapshot ")
141142 *args: Positional arguments to pass to the method
142143 **kwargs: Keyword arguments to pass to the method
143144
@@ -146,7 +147,16 @@ def call_sentience_method(
146147
147148 Raises:
148149 RuntimeError: If method is not available or call fails
150+
151+ Example:
152+ ```python
153+ result = BrowserEvaluator.invoke(page, SentienceMethod.SNAPSHOT, limit=50)
154+ success = BrowserEvaluator.invoke(page, SentienceMethod.CLICK, element_id)
155+ ```
149156 """
157+ # Convert enum to string if needed
158+ method_name = method .value if isinstance (method , SentienceMethod ) else method
159+
150160 # Build JavaScript call
151161 if args and kwargs :
152162 # Both args and kwargs - use object spread
@@ -184,18 +194,18 @@ def call_sentience_method(
184194 return result
185195
186196 @staticmethod
187- async def call_sentience_method_async (
197+ async def invoke_async (
188198 page : AsyncPage ,
189- method_name : str ,
199+ method : SentienceMethod | str ,
190200 * args : Any ,
191201 ** kwargs : Any ,
192202 ) -> Any :
193203 """
194- Call a window.sentience method with error handling (async).
204+ Invoke a window.sentience method with error handling (async).
195205
196206 Args:
197207 page: Playwright AsyncPage instance
198- method_name: Name of the method (e.g., "snapshot", "click ")
208+ method: SentienceMethod enum value or method name string (e.g., SentienceMethod.SNAPSHOT or "snapshot ")
199209 *args: Positional arguments to pass to the method
200210 **kwargs: Keyword arguments to pass to the method
201211
@@ -204,7 +214,16 @@ async def call_sentience_method_async(
204214
205215 Raises:
206216 RuntimeError: If method is not available or call fails
217+
218+ Example:
219+ ```python
220+ result = await BrowserEvaluator.invoke_async(page, SentienceMethod.SNAPSHOT, limit=50)
221+ success = await BrowserEvaluator.invoke_async(page, SentienceMethod.CLICK, element_id)
222+ ```
207223 """
224+ # Convert enum to string if needed
225+ method_name = method .value if isinstance (method , SentienceMethod ) else method
226+
208227 # Build JavaScript call
209228 if args and kwargs :
210229 js_code = f"""
@@ -240,18 +259,19 @@ async def call_sentience_method_async(
240259 @staticmethod
241260 def verify_method_exists (
242261 page : Page ,
243- method_name : str ,
262+ method : SentienceMethod | str ,
244263 ) -> bool :
245264 """
246265 Verify that a window.sentience method exists.
247266
248267 Args:
249268 page: Playwright Page instance (sync)
250- method_name: Name of the method to check
269+ method: SentienceMethod enum value or method name string
251270
252271 Returns:
253272 True if method exists, False otherwise
254273 """
274+ method_name = method .value if isinstance (method , SentienceMethod ) else method
255275 try :
256276 return page .evaluate (f"typeof window.sentience.{ method_name } !== 'undefined'" )
257277 except Exception :
@@ -260,18 +280,19 @@ def verify_method_exists(
260280 @staticmethod
261281 async def verify_method_exists_async (
262282 page : AsyncPage ,
263- method_name : str ,
283+ method : SentienceMethod | str ,
264284 ) -> bool :
265285 """
266286 Verify that a window.sentience method exists (async).
267287
268288 Args:
269289 page: Playwright AsyncPage instance
270- method_name: Name of the method to check
290+ method: SentienceMethod enum value or method name string
271291
272292 Returns:
273293 True if method exists, False otherwise
274294 """
295+ method_name = method .value if isinstance (method , SentienceMethod ) else method
275296 try :
276297 return await page .evaluate (f"typeof window.sentience.{ method_name } !== 'undefined'" )
277298 except Exception :
0 commit comments