MCPcopy Create free account
hub / github.com/THUDM/AutoWebGLM / ScriptBrowserEnv

Class ScriptBrowserEnv

webarena/browser_env/envs.py:69–319  ·  view source on GitHub ↗

The goal of this environment is to produce a prototype of a browser environment. In the end, we want to support a fully configurable browser environment with wide range of action spaces and observation spaces, both structured and unstructured. But in this prototype, we just support

Source from the content-addressed store, hash-verified

67
68
69class ScriptBrowserEnv(Env[dict[str, Observation], Action]):
70 """
71 The goal of this environment is to produce a prototype of a browser environment.
72 In the end, we want to support a fully configurable browser environment with wide
73 range of action spaces and observation spaces, both structured and unstructured.
74 But in this prototype, we just support action space specified by Playwright script,
75 and observation space is the html content of the page.
76 """
77
78 @beartype
79 def __init__(
80 self,
81 max_page_length: int = 8192,
82 headless: bool = True,
83 slow_mo: int = 0,
84 observation_type: str = "html",
85 current_viewport_only: bool = False,
86 viewport_size: ViewportSize = {"width": 1280, "height": 720},
87 save_trace_enabled: bool = False,
88 sleep_after_execution: float = 0.0,
89 ):
90 # TODO: make Space[Action] = ActionSpace
91 self.action_space = get_action_space() # type: ignore[assignment]
92 self.headless = headless
93 self.slow_mo = slow_mo
94 self.current_viewport_only = current_viewport_only
95 self.reset_finished = False
96 self.viewport_size = viewport_size
97 self.save_trace_enabled = save_trace_enabled
98 self.sleep_after_execution = sleep_after_execution
99
100 match observation_type:
101 case "html" | "accessibility_tree":
102 self.text_observation_type = observation_type
103 self.image_observation_type = ""
104 self.main_observation_type = "text"
105 case "image":
106 self.image_observation_type = observation_type
107 self.text_observation_type = "" # type: ignore[assignment]
108 self.main_observation_type = "image"
109 case _:
110 raise ValueError(
111 f"Unsupported observation type: {observation_type}"
112 )
113
114 self.observation_handler = ObservationHandler(
115 self.main_observation_type,
116 self.text_observation_type,
117 self.image_observation_type,
118 self.current_viewport_only,
119 self.viewport_size,
120 )
121
122 self.observation_space = (
123 self.observation_handler.get_observation_space()
124 )
125
126 @beartype

Calls

no outgoing calls