@apmantza/greedysearch-pi 1.8.9 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cdp.mjs CHANGED
@@ -365,10 +365,23 @@ async function captureMainContext(cdp, sid) {
365
365
  // Always disable Runtime after capturing
366
366
  await cdp.send("Runtime.disable", {}, sid).catch(() => {});
367
367
 
368
- // Find the main world context
369
- const main = contexts.find(
368
+ // Get the root frame ID so we can prefer its context when multiple
369
+ // isDefault contexts exist (e.g. Gemini embeds _/bscframe as a child
370
+ // frame whose context fires first and would otherwise be picked instead).
371
+ let rootFrameId = null;
372
+ try {
373
+ const ft = await cdp.send("Page.getFrameTree", {}, sid);
374
+ rootFrameId = ft?.frameTree?.frame?.id ?? null;
375
+ } catch {}
376
+
377
+ const defaults = contexts.filter(
370
378
  (ctx) => ctx.auxData?.isDefault && ctx.auxData?.type === "default",
371
379
  );
380
+ // Prefer the context whose frameId matches the root frame
381
+ const main =
382
+ (rootFrameId && defaults.find((ctx) => ctx.auxData?.frameId === rootFrameId)) ||
383
+ defaults[0] ||
384
+ null;
372
385
  return main?.id ?? null;
373
386
  }
374
387