MCPcopy Index your code
hub / github.com/garrytan/gstack / getOrCreateCdpSession

Function getOrCreateCdpSession

browse/src/cdp-bridge.ts:79–94  ·  view source on GitHub ↗
(
  page: Page,
  cache: WeakMap<Page, any>,
)

Source from the content-addressed store, hash-verified

77 * `framenavigated` because DOM/CSS domain state is tied to the document).
78 */
79export async function getOrCreateCdpSession(
80 page: Page,
81 cache: WeakMap<Page, any>,
82): Promise<any> {
83 let session = cache.get(page);
84 if (session) return session;
85 session = await page.context().newCDPSession(page);
86 cache.set(page, session);
87 page.once('close', () => {
88 cache.delete(page);
89 session.detach().catch(() => {
90 // Best-effort cleanup — see withCdpSession finally block.
91 });
92 });
93 return session;
94}
95
96// ─── $B cdp bridge ─────────────────────────────────────────────
97

Callers 3

getOrCreateSessionFunction · 0.90
getCdpSessionFunction · 0.85

Calls 2

setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected