@dev-blinq/cucumber_client 1.0.1586-dev → 1.0.1587-dev

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.
@@ -303,6 +303,25 @@ export class RemoteBrowserService extends EventEmitter {
303
303
  try {
304
304
  const pageUrl = page.url();
305
305
  this.log("🔍 Getting page ID", { pageUrl });
306
+ // Try to get the CDP target ID directly from the page
307
+ // This is more reliable than URL matching
308
+ try {
309
+ const cdpSession = await page.context().newCDPSession(page);
310
+ const { targetInfo } = await cdpSession.send("Target.getTargetInfo");
311
+ await cdpSession.detach();
312
+ if (targetInfo && targetInfo.targetId) {
313
+ this.log("✅ Got target ID from CDP session", {
314
+ targetId: targetInfo.targetId,
315
+ url: pageUrl,
316
+ });
317
+ return targetInfo.targetId;
318
+ }
319
+ }
320
+ catch (cdpError) {
321
+ this.log("⚠️ Failed to get target ID from CDP session, falling back to URL matching", {
322
+ error: cdpError instanceof Error ? cdpError.message : String(cdpError),
323
+ });
324
+ }
306
325
  const debugData = await this.getDebugURLs();
307
326
  this.log("📊 CDP debug data received", {
308
327
  totalPages: debugData.length,
@@ -417,44 +436,112 @@ export class RemoteBrowserService extends EventEmitter {
417
436
  debugPages: debugData.map((p) => ({ id: p.id, type: p.type, url: p.url })),
418
437
  });
419
438
  const pagesData = [];
420
- for (const [id, page] of this.pages.entries()) {
439
+ const updatedPages = new Map();
440
+ const matchedDebugIds = new Set(); // Track which CDP IDs we've already matched
441
+ let updatedSelectedPageId = this._selectedPageId;
442
+ for (const [oldId, page] of this.pages.entries()) {
421
443
  this.log("🔍 Processing page from internal map", {
422
- id,
444
+ oldId,
423
445
  url: page.url(),
424
446
  });
425
- const debugInfo = debugData.find((d) => d.id === id);
426
- if (debugInfo) {
427
- this.log("✅ Found matching debug info", {
428
- id,
447
+ // Try to get the current CDP target ID directly from the page
448
+ let currentId = null;
449
+ try {
450
+ const cdpSession = await page.context().newCDPSession(page);
451
+ const { targetInfo } = await cdpSession.send("Target.getTargetInfo");
452
+ await cdpSession.detach();
453
+ if (targetInfo && targetInfo.targetId) {
454
+ currentId = targetInfo.targetId;
455
+ this.log("✅ Got current target ID from CDP session", {
456
+ oldId,
457
+ currentId,
458
+ url: page.url(),
459
+ });
460
+ }
461
+ }
462
+ catch (cdpError) {
463
+ this.log("⚠️ Failed to get target ID from CDP session", {
464
+ oldId,
465
+ error: cdpError instanceof Error ? cdpError.message : String(cdpError),
466
+ });
467
+ }
468
+ // If we got the current ID from CDP session, use it
469
+ let debugInfo = currentId ? debugData.find((d) => d.id === currentId) : null;
470
+ // Fallback 1: Try to find by old ID
471
+ if (!debugInfo) {
472
+ debugInfo = debugData.find((d) => d.id === oldId && !matchedDebugIds.has(d.id));
473
+ }
474
+ // Fallback 2: Try to find by URL (only if not already matched)
475
+ if (!debugInfo) {
476
+ this.log("⚠️ Page ID not found in CDP, attempting to match by URL", {
477
+ oldId,
478
+ pageUrl: page.url(),
479
+ });
480
+ debugInfo = debugData.find((d) => d.type === "page" && d.url === page.url() && !matchedDebugIds.has(d.id));
481
+ if (debugInfo) {
482
+ this.log("✅ Found page by URL match, updating ID", {
483
+ oldId,
484
+ newId: debugInfo.id,
485
+ url: page.url(),
486
+ });
487
+ }
488
+ }
489
+ else {
490
+ this.log("✅ Found matching debug info by ID", {
491
+ id: debugInfo.id,
429
492
  debugUrl: debugInfo.url,
430
493
  pageUrl: page.url(),
431
494
  });
495
+ }
496
+ if (debugInfo) {
497
+ // Mark this CDP ID as matched to avoid duplicate matches
498
+ matchedDebugIds.add(debugInfo.id);
499
+ // Update selected page ID if this was the selected page and ID changed
500
+ if (oldId === this._selectedPageId && oldId !== debugInfo.id) {
501
+ updatedSelectedPageId = debugInfo.id;
502
+ this.log("🔄 Updated selected page ID", {
503
+ oldId,
504
+ newId: debugInfo.id,
505
+ });
506
+ }
432
507
  try {
433
508
  const pageData = {
434
- id,
509
+ id: debugInfo.id,
435
510
  title: await page.title(),
436
511
  url: page.url(),
437
512
  wsDebuggerUrl: debugInfo.webSocketDebuggerUrl || "",
438
513
  };
439
514
  pagesData.push(pageData);
515
+ updatedPages.set(debugInfo.id, page);
440
516
  this.log("✅ Page added to state", pageData);
441
517
  }
442
518
  catch (error) {
443
519
  this.log("❌ Error getting page data", {
444
- id,
520
+ id: oldId,
445
521
  error: error instanceof Error ? error.message : String(error),
446
522
  });
447
523
  }
448
524
  }
449
525
  else {
450
- this.log("⚠️ No matching debug info found", {
451
- id,
526
+ this.log("⚠️ No matching debug info found by ID or URL", {
527
+ oldId,
452
528
  pageUrl: page.url(),
453
529
  availableDebugIds: debugData.map((d) => d.id),
454
530
  availableDebugUrls: debugData.map((d) => d.url),
455
531
  });
456
532
  }
457
533
  }
534
+ // Update the internal pages map with current CDP IDs
535
+ if (updatedPages.size !== this.pages.size || updatedSelectedPageId !== this._selectedPageId) {
536
+ this.log("🔄 Updating internal state with new CDP IDs", {
537
+ oldPagesCount: this.pages.size,
538
+ newPagesCount: updatedPages.size,
539
+ oldSelectedId: this._selectedPageId,
540
+ newSelectedId: updatedSelectedPageId,
541
+ });
542
+ this.pages = updatedPages;
543
+ this._selectedPageId = updatedSelectedPageId;
544
+ }
458
545
  const state = {
459
546
  pages: pagesData,
460
547
  selectedPageId: this._selectedPageId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-blinq/cucumber_client",
3
- "version": "1.0.1586-dev",
3
+ "version": "1.0.1587-dev",
4
4
  "description": " ",
5
5
  "main": "bin/index.js",
6
6
  "types": "bin/index.d.ts",