@ricsam/isolate-client 0.1.10 → 0.1.12
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/dist/cjs/connection.cjs
CHANGED
|
@@ -435,6 +435,10 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
435
435
|
callbacks.custom = registerCustomFunctions(state, options.customFunctions);
|
|
436
436
|
}
|
|
437
437
|
let playwrightHandler;
|
|
438
|
+
const browserConsoleLogs = [];
|
|
439
|
+
const networkRequests = [];
|
|
440
|
+
const networkResponses = [];
|
|
441
|
+
const pageListenerCleanups = [];
|
|
438
442
|
if (options.playwright) {
|
|
439
443
|
playwrightHandler = import_client.createPlaywrightHandler(options.playwright.page, {
|
|
440
444
|
timeout: options.playwright.timeout,
|
|
@@ -446,65 +450,67 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
446
450
|
const result2 = await playwrightHandler(op);
|
|
447
451
|
return JSON.stringify(result2);
|
|
448
452
|
});
|
|
449
|
-
const
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
453
|
+
const page = options.playwright.page;
|
|
454
|
+
const onConsole = (msg) => {
|
|
455
|
+
const entry = {
|
|
456
|
+
level: msg.type(),
|
|
457
|
+
stdout: msg.text(),
|
|
458
|
+
timestamp: Date.now()
|
|
459
|
+
};
|
|
460
|
+
browserConsoleLogs.push(entry);
|
|
461
|
+
if (options.playwright.onEvent) {
|
|
462
|
+
options.playwright.onEvent({
|
|
463
|
+
type: "browserConsoleLog",
|
|
464
|
+
...entry
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
if (options.playwright.console && options.console?.onEntry) {
|
|
468
|
+
options.console.onEntry({
|
|
469
|
+
type: "browserOutput",
|
|
470
|
+
...entry
|
|
471
|
+
});
|
|
472
|
+
} else if (options.playwright.console) {
|
|
473
|
+
const prefix = entry.level === "error" ? "[browser:error]" : "[browser]";
|
|
474
|
+
console.log(prefix, entry.stdout);
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
const onRequest = (request2) => {
|
|
478
|
+
const info = {
|
|
479
|
+
url: request2.url(),
|
|
480
|
+
method: request2.method(),
|
|
481
|
+
headers: request2.headers(),
|
|
482
|
+
timestamp: Date.now()
|
|
483
|
+
};
|
|
484
|
+
networkRequests.push(info);
|
|
485
|
+
if (options.playwright.onEvent) {
|
|
477
486
|
options.playwright.onEvent({
|
|
478
487
|
type: "networkRequest",
|
|
479
|
-
|
|
480
|
-
method: reqInfo.method,
|
|
481
|
-
headers: reqInfo.headers,
|
|
482
|
-
postData: reqInfo.postData,
|
|
483
|
-
resourceType: reqInfo.resourceType,
|
|
484
|
-
timestamp: reqInfo.timestamp
|
|
488
|
+
...info
|
|
485
489
|
});
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
const onResponse = (response) => {
|
|
493
|
+
const info = {
|
|
494
|
+
url: response.url(),
|
|
495
|
+
status: response.status(),
|
|
496
|
+
headers: response.headers(),
|
|
497
|
+
timestamp: Date.now()
|
|
498
|
+
};
|
|
499
|
+
networkResponses.push(info);
|
|
500
|
+
if (options.playwright.onEvent) {
|
|
492
501
|
options.playwright.onEvent({
|
|
493
502
|
type: "networkResponse",
|
|
494
|
-
|
|
495
|
-
status: resInfo.status,
|
|
496
|
-
statusText: resInfo.statusText,
|
|
497
|
-
headers: resInfo.headers,
|
|
498
|
-
timestamp: resInfo.timestamp
|
|
503
|
+
...info
|
|
499
504
|
});
|
|
500
|
-
}
|
|
501
|
-
}
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
page.on("console", onConsole);
|
|
508
|
+
page.on("request", onRequest);
|
|
509
|
+
page.on("response", onResponse);
|
|
510
|
+
pageListenerCleanups.push(() => page.removeListener("console", onConsole), () => page.removeListener("request", onRequest), () => page.removeListener("response", onResponse));
|
|
502
511
|
callbacks.playwright = {
|
|
503
512
|
handlerCallbackId,
|
|
504
|
-
console: options.playwright.console && !options.console?.onEntry
|
|
505
|
-
onBrowserConsoleLogCallbackId: browserConsoleLogCallbackId,
|
|
506
|
-
onNetworkRequestCallbackId: networkRequestCallbackId,
|
|
507
|
-
onNetworkResponseCallbackId: networkResponseCallbackId
|
|
513
|
+
console: options.playwright.console && !options.console?.onEntry
|
|
508
514
|
};
|
|
509
515
|
}
|
|
510
516
|
let testEnvironmentOption;
|
|
@@ -762,29 +768,23 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
762
768
|
}
|
|
763
769
|
};
|
|
764
770
|
const playwrightHandle = {
|
|
765
|
-
|
|
771
|
+
getCollectedData() {
|
|
766
772
|
if (!playwrightEnabled) {
|
|
767
773
|
throw new Error("Playwright not configured. Provide playwright.page in createRuntime options.");
|
|
768
774
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
isolateId
|
|
775
|
+
return {
|
|
776
|
+
browserConsoleLogs: [...browserConsoleLogs],
|
|
777
|
+
networkRequests: [...networkRequests],
|
|
778
|
+
networkResponses: [...networkResponses]
|
|
774
779
|
};
|
|
775
|
-
return sendRequest(state, req);
|
|
776
780
|
},
|
|
777
|
-
|
|
781
|
+
clearCollectedData() {
|
|
778
782
|
if (!playwrightEnabled) {
|
|
779
783
|
throw new Error("Playwright not configured. Provide playwright.page in createRuntime options.");
|
|
780
784
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
requestId: reqId,
|
|
785
|
-
isolateId
|
|
786
|
-
};
|
|
787
|
-
await sendRequest(state, req);
|
|
785
|
+
browserConsoleLogs.length = 0;
|
|
786
|
+
networkRequests.length = 0;
|
|
787
|
+
networkResponses.length = 0;
|
|
788
788
|
}
|
|
789
789
|
};
|
|
790
790
|
return {
|
|
@@ -811,6 +811,9 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
811
811
|
await sendRequest(state, req);
|
|
812
812
|
},
|
|
813
813
|
dispose: async () => {
|
|
814
|
+
for (const cleanup of pageListenerCleanups) {
|
|
815
|
+
cleanup();
|
|
816
|
+
}
|
|
814
817
|
isolateWsCallbacks.delete(isolateId);
|
|
815
818
|
const reqId = state.nextRequestId++;
|
|
816
819
|
const req = {
|
|
@@ -1314,4 +1317,4 @@ async function sendBodyStream(state, streamId, body) {
|
|
|
1314
1317
|
}
|
|
1315
1318
|
}
|
|
1316
1319
|
|
|
1317
|
-
//# debugId=
|
|
1320
|
+
//# debugId=F22B720CD1D2496764756E2164756E21
|