@@ -284,3 +284,41 @@ def set_locale_override(
284284 params ["userContexts" ] = user_contexts
285285
286286 self .conn .execute (command_builder ("emulation.setLocaleOverride" , params ))
287+
288+ def set_scripting_enabled (
289+ self ,
290+ enabled : Union [bool , None ] = False ,
291+ contexts : Optional [list [str ]] = None ,
292+ user_contexts : Optional [list [str ]] = None ,
293+ ) -> None :
294+ """Set scripting enabled override for the given contexts or user contexts.
295+
296+ Parameters:
297+ -----------
298+ enabled: False to disable scripting, None to clear the override.
299+ Note: Only emulation of disabled JavaScript is supported.
300+ contexts: List of browsing context IDs to apply the override to.
301+ user_contexts: List of user context IDs to apply the override to.
302+
303+ Raises:
304+ ------
305+ ValueError: If both contexts and user_contexts are provided, or if neither
306+ contexts nor user_contexts are provided, or if enabled is True.
307+ """
308+ if enabled :
309+ raise ValueError ("Only emulation of disabled JavaScript is supported (enabled must be False or None)" )
310+
311+ if contexts is not None and user_contexts is not None :
312+ raise ValueError ("Cannot specify both contexts and userContexts" )
313+
314+ if contexts is None and user_contexts is None :
315+ raise ValueError ("Must specify either contexts or userContexts" )
316+
317+ params : dict [str , Any ] = {"enabled" : enabled }
318+
319+ if contexts is not None :
320+ params ["contexts" ] = contexts
321+ elif user_contexts is not None :
322+ params ["userContexts" ] = user_contexts
323+
324+ self .conn .execute (command_builder ("emulation.setScriptingEnabled" , params ))
0 commit comments