Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/browsergym/workarena/tasks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,19 @@ def setup(self, page: playwright.sync_api.Page, do_start=True) -> tuple[str, dic
goal, info = self.setup_goal(page=page)

# Load a few utility functions for init scripts
page.context.add_init_script(path=SNOW_JS_UTILS_FILEPATH)

# Add the initialization scripts to the page context
for script in self.get_init_scripts():
page.context.add_init_script(script)
with open(SNOW_JS_UTILS_FILEPATH, "r") as f:
utils_script = f.read()

# Merge all init scripts in a single file so they're guaranteed to be
# executed in order and in a shared context.
init_scripts = [utils_script] + self.get_init_scripts()
init_script_js = "\n".join(init_scripts)
# Install initialization scripts in existing pages, and register them
# in the page context so that future pages will run them on creation.
page.context.add_init_script(init_script_js)
page.evaluate(init_script_js)
for f in page.frames:
f.evaluate(init_script_js)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the evaluate lines should be removed


# Start the task if requested
if do_start:
Expand Down