MCPcopy
hub / github.com/garrytan/gstack / getActiveFrameOrPage

Method getActiveFrameOrPage

browse/src/tab-session.ts:151–164  ·  view source on GitHub ↗

* Returns the active frame if set, otherwise the current page. * Use this for operations that work on both Page and Frame (locator, evaluate, etc.).

()

Source from the content-addressed store, hash-verified

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

Callers 5

handleWriteCommandFunction · 0.45
handleReadCommandFunction · 0.45
handleSnapshotFunction · 0.45

Calls 1

clearRefsMethod · 0.95

Tested by

no test coverage detected