@dev-blinq/cucumber_client 1.0.1586-dev → 1.0.1588-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.
- package/bin/client/recorderv3/services.js +113 -22
- package/package.json +1 -1
|
@@ -303,15 +303,16 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
303
303
|
try {
|
|
304
304
|
const pageUrl = page.url();
|
|
305
305
|
this.log("🔍 Getting page ID", { pageUrl });
|
|
306
|
+
// Fetch debug data from /json endpoint (more reliable for matching)
|
|
306
307
|
const debugData = await this.getDebugURLs();
|
|
307
308
|
this.log("📊 CDP debug data received", {
|
|
308
309
|
totalPages: debugData.length,
|
|
309
310
|
pages: debugData.map((p) => ({ id: p.id, type: p.type, url: p.url })),
|
|
310
311
|
});
|
|
311
|
-
// Exact match
|
|
312
|
+
// Exact URL match
|
|
312
313
|
for (const pageData of debugData) {
|
|
313
314
|
if (pageData.type === "page" && pageData.url === pageUrl) {
|
|
314
|
-
this.log("✅ Found exact URL match", {
|
|
315
|
+
this.log("✅ Found exact URL match in /json", {
|
|
315
316
|
id: pageData.id,
|
|
316
317
|
url: pageUrl,
|
|
317
318
|
});
|
|
@@ -319,16 +320,14 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
319
320
|
}
|
|
320
321
|
}
|
|
321
322
|
this.log("⚠️ No exact match found, trying normalized URLs", { pageUrl });
|
|
322
|
-
// Normalized match
|
|
323
|
+
// Normalized URL match
|
|
323
324
|
const normalizeUrl = (url) => {
|
|
324
325
|
try {
|
|
325
326
|
const u = new URL(url);
|
|
326
327
|
const normalized = u.hostname.replace(/^www\./, "") + u.pathname + u.search;
|
|
327
|
-
this.log("🔧 Normalized URL", { original: url, normalized });
|
|
328
328
|
return normalized;
|
|
329
329
|
}
|
|
330
330
|
catch {
|
|
331
|
-
this.log("❌ Failed to normalize URL", { url });
|
|
332
331
|
return url;
|
|
333
332
|
}
|
|
334
333
|
};
|
|
@@ -337,7 +336,7 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
337
336
|
if (pageData.type === "page") {
|
|
338
337
|
const normalizedDebugUrl = normalizeUrl(pageData.url);
|
|
339
338
|
if (normalizedDebugUrl === normalizedPageUrl) {
|
|
340
|
-
this.log("✅ Found normalized URL match", {
|
|
339
|
+
this.log("✅ Found normalized URL match in /json", {
|
|
341
340
|
id: pageData.id,
|
|
342
341
|
pageUrl: normalizedPageUrl,
|
|
343
342
|
debugUrl: normalizedDebugUrl,
|
|
@@ -346,6 +345,35 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
346
345
|
}
|
|
347
346
|
}
|
|
348
347
|
}
|
|
348
|
+
// If still not found, try CDP session as fallback
|
|
349
|
+
this.log("⚠️ Not found in /json, trying CDP Target.getTargetInfo", { pageUrl });
|
|
350
|
+
try {
|
|
351
|
+
const cdpSession = await page.context().newCDPSession(page);
|
|
352
|
+
const { targetInfo } = await cdpSession.send("Target.getTargetInfo");
|
|
353
|
+
await cdpSession.detach();
|
|
354
|
+
if (targetInfo && targetInfo.targetId) {
|
|
355
|
+
// Verify this target ID exists in debug data
|
|
356
|
+
const targetExists = debugData.some((d) => d.id === targetInfo.targetId);
|
|
357
|
+
if (targetExists) {
|
|
358
|
+
this.log("✅ Got target ID from CDP session and verified in /json", {
|
|
359
|
+
targetId: targetInfo.targetId,
|
|
360
|
+
url: pageUrl,
|
|
361
|
+
});
|
|
362
|
+
return targetInfo.targetId;
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
this.log("⚠️ Target ID from CDP session not found in /json (ID mismatch)", {
|
|
366
|
+
cdpTargetId: targetInfo.targetId,
|
|
367
|
+
availableIds: debugData.map((d) => d.id),
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
catch (cdpError) {
|
|
373
|
+
this.log("⚠️ Failed to get target ID from CDP session", {
|
|
374
|
+
error: cdpError instanceof Error ? cdpError.message : String(cdpError),
|
|
375
|
+
});
|
|
376
|
+
}
|
|
349
377
|
this.log("❌ No match found for page", {
|
|
350
378
|
pageUrl,
|
|
351
379
|
normalizedPageUrl,
|
|
@@ -417,44 +445,88 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
417
445
|
debugPages: debugData.map((p) => ({ id: p.id, type: p.type, url: p.url })),
|
|
418
446
|
});
|
|
419
447
|
const pagesData = [];
|
|
420
|
-
|
|
448
|
+
const updatedPages = new Map();
|
|
449
|
+
const matchedDebugIds = new Set(); // Track which CDP IDs we've already matched
|
|
450
|
+
let updatedSelectedPageId = this._selectedPageId;
|
|
451
|
+
for (const [oldId, page] of this.pages.entries()) {
|
|
421
452
|
this.log("🔍 Processing page from internal map", {
|
|
422
|
-
|
|
453
|
+
oldId,
|
|
423
454
|
url: page.url(),
|
|
424
455
|
});
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
456
|
+
// Try to find by old ID first (most common case - ID hasn't changed)
|
|
457
|
+
let debugInfo = debugData.find((d) => d.id === oldId && !matchedDebugIds.has(d.id));
|
|
458
|
+
// Fallback: Try to find by URL (page ID may have changed)
|
|
459
|
+
if (!debugInfo) {
|
|
460
|
+
this.log("⚠️ Page ID not found in CDP, attempting to match by URL", {
|
|
461
|
+
oldId,
|
|
462
|
+
pageUrl: page.url(),
|
|
463
|
+
});
|
|
464
|
+
debugInfo = debugData.find((d) => d.type === "page" && d.url === page.url() && !matchedDebugIds.has(d.id));
|
|
465
|
+
if (debugInfo) {
|
|
466
|
+
this.log("✅ Found page by URL match, updating ID", {
|
|
467
|
+
oldId,
|
|
468
|
+
newId: debugInfo.id,
|
|
469
|
+
url: page.url(),
|
|
470
|
+
});
|
|
471
|
+
// Update selected page ID if this was the selected page and ID changed
|
|
472
|
+
if (oldId === this._selectedPageId) {
|
|
473
|
+
updatedSelectedPageId = debugInfo.id;
|
|
474
|
+
this.log("🔄 Updated selected page ID", {
|
|
475
|
+
oldId,
|
|
476
|
+
newId: debugInfo.id,
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
this.log("✅ Found matching debug info by ID", {
|
|
483
|
+
id: debugInfo.id,
|
|
429
484
|
debugUrl: debugInfo.url,
|
|
430
485
|
pageUrl: page.url(),
|
|
431
486
|
});
|
|
487
|
+
}
|
|
488
|
+
if (debugInfo) {
|
|
489
|
+
// Mark this CDP ID as matched to avoid duplicate matches
|
|
490
|
+
matchedDebugIds.add(debugInfo.id);
|
|
432
491
|
try {
|
|
433
492
|
const pageData = {
|
|
434
|
-
id,
|
|
493
|
+
id: debugInfo.id,
|
|
435
494
|
title: await page.title(),
|
|
436
495
|
url: page.url(),
|
|
437
496
|
wsDebuggerUrl: debugInfo.webSocketDebuggerUrl || "",
|
|
438
497
|
};
|
|
439
498
|
pagesData.push(pageData);
|
|
499
|
+
updatedPages.set(debugInfo.id, page);
|
|
440
500
|
this.log("✅ Page added to state", pageData);
|
|
441
501
|
}
|
|
442
502
|
catch (error) {
|
|
443
503
|
this.log("❌ Error getting page data", {
|
|
444
|
-
id,
|
|
504
|
+
id: oldId,
|
|
445
505
|
error: error instanceof Error ? error.message : String(error),
|
|
446
506
|
});
|
|
447
507
|
}
|
|
448
508
|
}
|
|
449
509
|
else {
|
|
450
|
-
this.log("⚠️ No matching debug info found", {
|
|
451
|
-
|
|
510
|
+
this.log("⚠️ No matching debug info found by ID or URL", {
|
|
511
|
+
oldId,
|
|
452
512
|
pageUrl: page.url(),
|
|
453
513
|
availableDebugIds: debugData.map((d) => d.id),
|
|
454
514
|
availableDebugUrls: debugData.map((d) => d.url),
|
|
515
|
+
alreadyMatched: Array.from(matchedDebugIds),
|
|
455
516
|
});
|
|
456
517
|
}
|
|
457
518
|
}
|
|
519
|
+
// Update the internal pages map with current CDP IDs
|
|
520
|
+
if (updatedPages.size !== this.pages.size || updatedSelectedPageId !== this._selectedPageId) {
|
|
521
|
+
this.log("🔄 Updating internal state with new CDP IDs", {
|
|
522
|
+
oldPagesCount: this.pages.size,
|
|
523
|
+
newPagesCount: updatedPages.size,
|
|
524
|
+
oldSelectedId: this._selectedPageId,
|
|
525
|
+
newSelectedId: updatedSelectedPageId,
|
|
526
|
+
});
|
|
527
|
+
this.pages = updatedPages;
|
|
528
|
+
this._selectedPageId = updatedSelectedPageId;
|
|
529
|
+
}
|
|
458
530
|
const state = {
|
|
459
531
|
pages: pagesData,
|
|
460
532
|
selectedPageId: this._selectedPageId,
|
|
@@ -472,11 +544,27 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
472
544
|
await page.goto(url, { waitUntil: "domcontentloaded" });
|
|
473
545
|
this.log("✅ Navigation complete", { finalUrl: page.url() });
|
|
474
546
|
}
|
|
475
|
-
// Wait for CDP to register the page
|
|
476
|
-
this.log("⏳ Waiting for CDP registration...");
|
|
477
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
478
|
-
|
|
479
|
-
|
|
547
|
+
// Wait longer for CDP to register and stabilize the page
|
|
548
|
+
this.log("⏳ Waiting for CDP registration and stabilization...");
|
|
549
|
+
await new Promise((resolve) => setTimeout(resolve, 1000)); // Increased to 1 second
|
|
550
|
+
// Try multiple times to get a stable page ID
|
|
551
|
+
let id = null;
|
|
552
|
+
let attempts = 0;
|
|
553
|
+
const maxAttempts = 5;
|
|
554
|
+
while (!id && attempts < maxAttempts) {
|
|
555
|
+
attempts++;
|
|
556
|
+
this.log(`🔍 Attempt ${attempts}/${maxAttempts} to get page ID`);
|
|
557
|
+
id = await this.getPageId(page);
|
|
558
|
+
if (!id) {
|
|
559
|
+
this.log(`⏳ Page ID not found, waiting 500ms before retry...`);
|
|
560
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
this.log("🔍 Retrieved page ID after retries", {
|
|
564
|
+
id,
|
|
565
|
+
url: page.url(),
|
|
566
|
+
attempts,
|
|
567
|
+
});
|
|
480
568
|
if (id) {
|
|
481
569
|
this.pages.set(id, page);
|
|
482
570
|
this._selectedPageId = id;
|
|
@@ -489,7 +577,10 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
489
577
|
});
|
|
490
578
|
}
|
|
491
579
|
else {
|
|
492
|
-
this.log("❌ Failed to get page ID for new tab", {
|
|
580
|
+
this.log("❌ Failed to get page ID for new tab after all retries", {
|
|
581
|
+
url: page.url(),
|
|
582
|
+
attempts,
|
|
583
|
+
});
|
|
493
584
|
// Try to get debug data to see what's available
|
|
494
585
|
const debugData = await this.getDebugURLs();
|
|
495
586
|
this.log("🔍 Current CDP state after failed ID retrieval", {
|