BrowserGym icon indicating copy to clipboard operation
BrowserGym copied to clipboard

WebArena-Lite program_html evaluator navigates the agent's tab after every step

Open JYunth opened this issue 3 weeks ago • 0 comments

GenericWebArenaTask.validate() runs the evaluator after every step, not only when the agent stops; on the other steps it passes a NONE action. WebArenaLiteTask inherits this. In WebArena-Lite's HTMLContentEvaluator, when a target URL isn't "last", the evaluator calls page.goto(target_url) on the page it was passed, which is the agent's active tab:

https://github.com/ServiceNow/BrowserGym/blob/27a90ce815098f43414e93491e06907af468e45b/browsergym/webarenalite/src/browsergym/webarenalite/evaluators.py#L270-L272

libwebarena's version of this evaluator opens a separate tab (page.context.new_page()) and closes it afterwards. libvisualwebarena does the same, so WebArena and VisualWebArena aren't affected.

The observation is extracted after validate(), so the agent's next observation shows wherever the evaluator went. 50 of the 165 WebArena-Lite tasks have such a target:

  • 38 go to a fixed URL, for example the user profile for "Change my reddit bio to ..."
  • 3 go to the latest order URL from shopping_get_latest_order_url()
  • 9 use reddit_get_post_url('__last_url__'). That usually returns the agent's current URL, so on those tasks the page gets reloaded every step and any unsubmitted input is lost.

Repro. You don't need a WebArena instance: the script stubs out logins and uses any HTTP server as the backend. Start one in another terminal, from an empty directory:

python -m http.server 8765
import os

for site in ["SHOPPING", "SHOPPING_ADMIN", "REDDIT", "GITLAB", "WIKIPEDIA", "MAP", "HOMEPAGE"]:
    os.environ[f"WA_{site}"] = f"http://localhost:8765/{site.lower()}"

import gymnasium as gym
import browsergym.webarenalite
from browsergym.webarena.instance import WebArenaInstance

WebArenaInstance.ui_login = lambda self, site, page: None  # skip logins, no real instance

env = gym.make("browsergym/webarenalite.401", headless=True)  # "Change my reddit bio to ..."
obs, _ = env.reset(seed=0)
print("after reset:", obs["url"])
obs, *_ = env.step('goto("http://localhost:8765/reddit/forums")')
print("after goto :", obs["url"])
env.close()
after reset: http://localhost:8765/reddit
after goto : http://localhost:8765/reddit/user/MarvelsGrantMan136

Expected: the agent stays on /reddit/forums. That's what happens with browsergym/webarena.401 under the same setup.

Actual: the agent is moved to the evaluator's target page after every step. On task 601, one of the reddit_get_post_url ones, text entered with fill() is gone after the step. webarena.601 keeps it.

Proposed fix: do what libwebarena does. Open the target in a new tab, and close it in a finally so a goto timeout can't leave the tab open. Keep the networkidle wait from #408. BrowserEnv._task_validate already restores env.page and page_history if the temporary tab gets activated. I tried this locally: the repro above stays on /reddit/forums, and a target page that contains the expected bio still scores 1.0.

test_slow_navigation_waits_appropriately, added in #408, asserts goto on the page passed into the evaluator, so it would need to assert on the new tab instead. I'd also add tests that the agent's page is never navigated and that the tab gets closed even when goto raises.

The fix will change WebArena-Lite scores on these tasks, which is why I'm opening an issue first. Happy to send a PR.

JYunth avatar Nov 07 '26 12:11 JYunth