<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>323386</bug_id>
          
          <creation_ts>2026-09-03 16:58:00 -0700</creation_ts>
          <short_desc>WebDriver reports &quot;stale element reference&quot; for a node reference from a different browsing context</short_desc>
          <delta_ts>2026-09-08 14:44:36 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>New Bugs</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=323695</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=230612</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=323692</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=323694</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Brent Fulgham">bfulgham</reporter>
          <assigned_to name="Brent Fulgham">bfulgham</assigned_to>
          <cc>lmoura</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2247102</commentid>
    <comment_count>0</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2026-09-03 16:58:00 -0700</bug_when>
    <thetext>Each frame&apos;s injected WebAutomationSessionProxy.js keeps its own map of node handles. _nodeForIdentifier() throws NodeNotFound whenever a handle is absent from that map, which conflates two different situations:
(1) the node was in this frame and has since been detached (a stale handle)
(2) the node was never in this frame, because it belongs to a different frame or window

CommandResult.cpp maps NodeNotFound to StaleElementReference, so both report stale element reference. Per the spec the second case is no such element (or no such shadow root for a shadow root reference).

_clearStaleNodes() already knows the difference: it evicts exactly those handles whose node is no longer rooted in this document. Recording what it evicts lets _nodeForIdentifier() throw a distinct StaleNode error for the detached case and keep NodeNotFound for the foreign one.

This fix improves 16 subtests across webdriver/tests/classic/execute_script/arguments.py and execute_async_script/arguments.py</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2247103</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2026-09-03 16:58:21 -0700</bug_when>
    <thetext>&lt;rdar://problem/186615759&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2247108</commentid>
    <comment_count>2</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2026-09-03 17:07:22 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/73206</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2247337</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-09-04 09:33:37 -0700</bug_when>
    <thetext>Committed 320518@main (f56eb24b3195): &lt;https://commits.webkit.org/320518@main&gt;

Reviewed commits have been landed. Closing PR #73206 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2248309</commentid>
    <comment_count>4</comment_count>
    <who name="Lauro Moura">lmoura</who>
    <bug_when>2026-09-08 14:44:36 -0700</bug_when>
    <thetext>(I had edited the wrong field, sorry)</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>