@dev-blinq/cucumber_client 1.0.1627-dev โ 1.0.1629-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.
|
@@ -244,6 +244,20 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
244
244
|
const timestamp = new Date().toISOString();
|
|
245
245
|
console.log(`[${timestamp}] [RemoteBrowserService] ${message}`, data ? JSON.stringify(data, null, 2) : "");
|
|
246
246
|
}
|
|
247
|
+
isTransientPageDataError(error) {
|
|
248
|
+
const message = error instanceof Error ? error.message : typeof error === "string" ? error : undefined;
|
|
249
|
+
if (!message) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
const transientIndicators = [
|
|
253
|
+
"Execution context was destroyed",
|
|
254
|
+
"Execution context is not available",
|
|
255
|
+
"Cannot find context with specified id",
|
|
256
|
+
"Target closed",
|
|
257
|
+
"Navigation interrupted",
|
|
258
|
+
];
|
|
259
|
+
return transientIndicators.some((indicator) => message.includes(indicator));
|
|
260
|
+
}
|
|
247
261
|
/**
|
|
248
262
|
* Gets the CDP Target ID for a page *directly* from the page.
|
|
249
263
|
* This is the only reliable method during restarts.
|
|
@@ -277,7 +291,13 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
277
291
|
for (const page of existingPages) {
|
|
278
292
|
const stableTabId = uuidv4();
|
|
279
293
|
const cdpTargetId = await this.getCdpTargetId(page);
|
|
280
|
-
this.pages.set(stableTabId, {
|
|
294
|
+
this.pages.set(stableTabId, {
|
|
295
|
+
page,
|
|
296
|
+
cdpTargetId,
|
|
297
|
+
lastKnownTitle: undefined,
|
|
298
|
+
lastKnownUrl: page.url(),
|
|
299
|
+
lastKnownWsDebuggerUrl: cdpTargetId ? `${this.wsUrlBase}${cdpTargetId}` : undefined,
|
|
300
|
+
});
|
|
281
301
|
this.log("โ
Existing page added to map", { stableTabId, cdpTargetId, url: page.url() });
|
|
282
302
|
this.attachPageLifecycleListeners(page, stableTabId);
|
|
283
303
|
this.log("๐ Attached lifecycle listeners to existing page", { stableTabId });
|
|
@@ -291,7 +311,13 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
291
311
|
this.log("๐ New page event triggered", { stableTabId, url: page.url() });
|
|
292
312
|
// We get the ID immediately, but it might be null if the page is too new
|
|
293
313
|
const cdpTargetId = await this.getCdpTargetId(page);
|
|
294
|
-
this.pages.set(stableTabId, {
|
|
314
|
+
this.pages.set(stableTabId, {
|
|
315
|
+
page,
|
|
316
|
+
cdpTargetId,
|
|
317
|
+
lastKnownTitle: undefined,
|
|
318
|
+
lastKnownUrl: page.url(),
|
|
319
|
+
lastKnownWsDebuggerUrl: cdpTargetId ? `${this.wsUrlBase}${cdpTargetId}` : undefined,
|
|
320
|
+
});
|
|
295
321
|
if (cdpTargetId) {
|
|
296
322
|
this.log("โ
Page mapped to CDP ID", { stableTabId, cdpTargetId });
|
|
297
323
|
}
|
|
@@ -336,6 +362,12 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
336
362
|
const pagesData = [];
|
|
337
363
|
const pagesToDelete = []; // To clean up closed pages
|
|
338
364
|
for (const [stableTabId, pageInfo] of this.pages.entries()) {
|
|
365
|
+
const pageData = {
|
|
366
|
+
id: stableTabId,
|
|
367
|
+
title: pageInfo.lastKnownTitle ?? "",
|
|
368
|
+
url: pageInfo.lastKnownUrl ?? pageInfo.page.url(),
|
|
369
|
+
wsDebuggerUrl: pageInfo.lastKnownWsDebuggerUrl ?? "",
|
|
370
|
+
};
|
|
339
371
|
try {
|
|
340
372
|
if (pageInfo.page.isClosed()) {
|
|
341
373
|
this.log("๐งน Found closed page during getState, marking for deletion", { stableTabId });
|
|
@@ -349,23 +381,37 @@ export class RemoteBrowserService extends EventEmitter {
|
|
|
349
381
|
pageInfo.cdpTargetId = currentCdpId; // Update our internal reference
|
|
350
382
|
}
|
|
351
383
|
// Manually construct the WebSocket URL
|
|
352
|
-
const wsDebuggerUrl = currentCdpId
|
|
384
|
+
const wsDebuggerUrl = currentCdpId
|
|
385
|
+
? `${this.wsUrlBase}${currentCdpId}`
|
|
386
|
+
: (pageInfo.lastKnownWsDebuggerUrl ?? "");
|
|
353
387
|
if (!wsDebuggerUrl) {
|
|
354
388
|
this.log("โ ๏ธ Could not get CDP ID, wsDebuggerUrl will be empty", { stableTabId });
|
|
355
389
|
}
|
|
356
390
|
const title = await pageInfo.page.title();
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
391
|
+
const currentUrl = pageInfo.page.url();
|
|
392
|
+
pageData.title = title;
|
|
393
|
+
pageData.url = currentUrl;
|
|
394
|
+
pageData.wsDebuggerUrl = wsDebuggerUrl; // Use the constructed URL
|
|
395
|
+
pageInfo.lastKnownTitle = title;
|
|
396
|
+
pageInfo.lastKnownUrl = currentUrl;
|
|
397
|
+
pageInfo.lastKnownWsDebuggerUrl = wsDebuggerUrl;
|
|
398
|
+
this.log("๐ฅPage data", pageData);
|
|
364
399
|
}
|
|
365
400
|
catch (error) {
|
|
366
|
-
|
|
367
|
-
|
|
401
|
+
const message = error instanceof Error ? error.message : JSON.stringify(error);
|
|
402
|
+
if (this.isTransientPageDataError(error)) {
|
|
403
|
+
this.log("โณ Transient error getting page data, will retry", { stableTabId, message });
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
this.log("โ Error getting page data", { stableTabId, message });
|
|
407
|
+
pagesToDelete.push(stableTabId); // Mark for deletion
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (!pageData.title) {
|
|
412
|
+
pageData.title = pageInfo.page.url() === "about:blank" ? "" : "Loading...";
|
|
368
413
|
}
|
|
414
|
+
pagesData.push(pageData);
|
|
369
415
|
}
|
|
370
416
|
pagesToDelete.forEach((id) => this.pages.delete(id));
|
|
371
417
|
if (this._selectedPageId && !this.pages.has(this._selectedPageId)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dev-blinq/cucumber_client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1629-dev",
|
|
4
4
|
"description": " ",
|
|
5
5
|
"main": "bin/index.js",
|
|
6
6
|
"types": "bin/index.d.ts",
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"mocha": "^10.2.0",
|
|
69
69
|
"ncp": "^2.0.0",
|
|
70
70
|
"readline-sync": "^1.4.10",
|
|
71
|
+
"ts-node": "^10.9.2",
|
|
71
72
|
"tsup": "^8.5.0",
|
|
72
73
|
"typescript": "^5.9.2"
|
|
73
74
|
}
|