[V3]: fix xpath building logic for coordinates inside of iframes

Merged
SE
3mo ago
+55-16

why

coordinate based targeting can resolve elements inside iframes differently depending on chrome's frame site isolation behavior. when chrome reports the inner frame directly, stagehand was returning the element path inside the iframe without the owning iframe path from the parent page. this caused the xpath-for-location-deep.spec.ts test to fail

this showed up in when using the --disable-features=SitePerProcess chrome flag

this PR also replaces the incorrect -disable-features=site-per-process flag with the correct --disable-features=SitePerProcess flag

what changed

  • updated coordinate xpath resolution to handle direct child frame hits from chrome
  • when DOM.getNodeForLocation reports a different frameId, stagehand now looks up that frame's owning iframe with DOM.getFrameOwner
  • the owning iframe is added to the xpath chain before resolving the inner-frame node
  • this keeps coordinate based iframe targeting consistent across same-process and isolated iframe behavior

test plan

  • e2e test for resolveNodeForLocationDeep now passes

Summary by cubic

Fixes coordinate-based iframe targeting so XPath resolution stays consistent when DOM.getNodeForLocation reports a frame other than the current one, including nested iframes.

  • Resolves each intermediate owning iframe via DOM.getFrameOwner and prepends them to the XPath chain.
  • Returns no XPath when the reported frame's ancestry can't be fully traced to the current frame.
  • Replaces the incorrect --site-per-process flag with --disable-features=SitePerProcess.