* Returns the active frame if set, otherwise the current page. * Use this for operations that work on both Page and Frame (locator, evaluate, etc.).
()
| 149 | * Use this for operations that work on both Page and Frame (locator, evaluate, etc.). |
| 150 | */ |
| 151 | getActiveFrameOrPage(): Page | Frame { |
| 152 | // Auto-recover from detached frames (iframe removed/navigated). Clear |
| 153 | // refs alongside the activeFrame — same staleness condition as |
| 154 | // onMainFrameNavigated() below: refs were captured against a frame |
| 155 | // that no longer exists. Without this, refMap entries linger against |
| 156 | // a dead frame after silently falling back to the main page; the |
| 157 | // next snapshot's role+name keys collide with stale entries and the |
| 158 | // resolver picks one at random. |
| 159 | if (this.activeFrame?.isDetached()) { |
| 160 | this.activeFrame = null; |
| 161 | this.clearRefs(); |
| 162 | } |
| 163 | return this.activeFrame ?? this.page; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Called on main-frame navigation to clear stale refs, frame context, and any |
no test coverage detected