@dev-blinq/cucumber_client 1.0.1587-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.
|
@@ -303,34 +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
|
-
//
|
|
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
|
+
// Fetch debug data from /json endpoint (more reliable for matching)
|
|
325
307
|
const debugData = await this.getDebugURLs();
|
|
326
308
|
this.log("📊 CDP debug data received", {
|
|
327
309
|
totalPages: debugData.length,
|
|
328
310
|
pages: debugData.map((p) => ({ id: p.id, type: p.type, url: p.url })),
|
|
329
311
|
});
|
|
330
|
-
// Exact match
|
|
312
|
+
// Exact URL match
|
|
331
313
|
for (const pageData of debugData) {
|
|
332
314
|
if (pageData.type === "page" && pageData.url === pageUrl) {
|
|
333
|
-
this.log("✅ Found exact URL match", {
|
|
315
|
+
this.log("✅ Found exact URL match in /json", {
|
|
334
316
|
id: pageData.id,
|
|
335
317
|
url: pageUrl,
|
|
336
318
|
});
|
|
@@ -338,16 +320,14 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
338
320
|
}
|
|
339
321
|
}
|
|
340
322
|
this.log("⚠️ No exact match found, trying normalized URLs", { pageUrl });
|
|
341
|
-
// Normalized match
|
|
323
|
+
// Normalized URL match
|
|
342
324
|
const normalizeUrl = (url) => {
|
|
343
325
|
try {
|
|
344
326
|
const u = new URL(url);
|
|
345
327
|
const normalized = u.hostname.replace(/^www\./, "") + u.pathname + u.search;
|
|
346
|
-
this.log("🔧 Normalized URL", { original: url, normalized });
|
|
347
328
|
return normalized;
|
|
348
329
|
}
|
|
349
330
|
catch {
|
|
350
|
-
this.log("❌ Failed to normalize URL", { url });
|
|
351
331
|
return url;
|
|
352
332
|
}
|
|
353
333
|
};
|
|
@@ -356,7 +336,7 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
356
336
|
if (pageData.type === "page") {
|
|
357
337
|
const normalizedDebugUrl = normalizeUrl(pageData.url);
|
|
358
338
|
if (normalizedDebugUrl === normalizedPageUrl) {
|
|
359
|
-
this.log("✅ Found normalized URL match", {
|
|
339
|
+
this.log("✅ Found normalized URL match in /json", {
|
|
360
340
|
id: pageData.id,
|
|
361
341
|
pageUrl: normalizedPageUrl,
|
|
362
342
|
debugUrl: normalizedDebugUrl,
|
|
@@ -365,6 +345,35 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
365
345
|
}
|
|
366
346
|
}
|
|
367
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
|
+
}
|
|
368
377
|
this.log("❌ No match found for page", {
|
|
369
378
|
pageUrl,
|
|
370
379
|
normalizedPageUrl,
|
|
@@ -444,34 +453,9 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
444
453
|
oldId,
|
|
445
454
|
url: page.url(),
|
|
446
455
|
});
|
|
447
|
-
// Try to
|
|
448
|
-
let
|
|
449
|
-
|
|
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)
|
|
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)
|
|
475
459
|
if (!debugInfo) {
|
|
476
460
|
this.log("⚠️ Page ID not found in CDP, attempting to match by URL", {
|
|
477
461
|
oldId,
|
|
@@ -484,6 +468,14 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
484
468
|
newId: debugInfo.id,
|
|
485
469
|
url: page.url(),
|
|
486
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
|
+
}
|
|
487
479
|
}
|
|
488
480
|
}
|
|
489
481
|
else {
|
|
@@ -496,14 +488,6 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
496
488
|
if (debugInfo) {
|
|
497
489
|
// Mark this CDP ID as matched to avoid duplicate matches
|
|
498
490
|
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
|
-
}
|
|
507
491
|
try {
|
|
508
492
|
const pageData = {
|
|
509
493
|
id: debugInfo.id,
|
|
@@ -528,6 +512,7 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
528
512
|
pageUrl: page.url(),
|
|
529
513
|
availableDebugIds: debugData.map((d) => d.id),
|
|
530
514
|
availableDebugUrls: debugData.map((d) => d.url),
|
|
515
|
+
alreadyMatched: Array.from(matchedDebugIds),
|
|
531
516
|
});
|
|
532
517
|
}
|
|
533
518
|
}
|
|
@@ -559,11 +544,27 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
559
544
|
await page.goto(url, { waitUntil: "domcontentloaded" });
|
|
560
545
|
this.log("✅ Navigation complete", { finalUrl: page.url() });
|
|
561
546
|
}
|
|
562
|
-
// Wait for CDP to register the page
|
|
563
|
-
this.log("⏳ Waiting for CDP registration...");
|
|
564
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
565
|
-
|
|
566
|
-
|
|
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
|
+
});
|
|
567
568
|
if (id) {
|
|
568
569
|
this.pages.set(id, page);
|
|
569
570
|
this._selectedPageId = id;
|
|
@@ -576,7 +577,10 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
576
577
|
});
|
|
577
578
|
}
|
|
578
579
|
else {
|
|
579
|
-
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
|
+
});
|
|
580
584
|
// Try to get debug data to see what's available
|
|
581
585
|
const debugData = await this.getDebugURLs();
|
|
582
586
|
this.log("🔍 Current CDP state after failed ID retrieval", {
|