@pagepocket/capture-http-puppeteer-unit 0.12.0 → 0.13.0
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.
|
@@ -3,7 +3,7 @@ import { type PuppeteerAdapterOptions } from "./internal/puppeteer-adapter.js";
|
|
|
3
3
|
export type CaptureHttpPuppeteerUnitOptions = PuppeteerAdapterOptions;
|
|
4
4
|
export declare class CaptureHttpPuppeteerUnit extends Unit {
|
|
5
5
|
readonly id = "captureHttpPuppeteer";
|
|
6
|
-
readonly
|
|
6
|
+
readonly description = "Capturing page via Puppeteer";
|
|
7
7
|
private adapterOptions;
|
|
8
8
|
constructor(options?: CaptureHttpPuppeteerUnitOptions);
|
|
9
9
|
run(ctx: UnitContext, rt: UnitRuntime): Promise<{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NETWORK } from "@pagepocket/contracts";
|
|
2
|
-
import { Unit, createMemoryContentStore, InflightTracker, mapKind, networkIdle, normalizeCompletion, throwUnsupportedEntryKind, timeout } from "@pagepocket/lib";
|
|
2
|
+
import { Unit, createMemoryContentStore, debugLog, InflightTracker, mapKind, networkIdle, normalizeCompletion, throwUnsupportedEntryKind, timeout } from "@pagepocket/lib";
|
|
3
3
|
import { PuppeteerAdapter } from "./internal/puppeteer-adapter.js";
|
|
4
4
|
const headersRecordToList = (headers) => {
|
|
5
5
|
if (!headers) {
|
|
@@ -7,6 +7,23 @@ const headersRecordToList = (headers) => {
|
|
|
7
7
|
}
|
|
8
8
|
return Object.keys(headers).map((name) => ({ name, value: headers[name] }));
|
|
9
9
|
};
|
|
10
|
+
const toInterceptedResourceName = (url) => {
|
|
11
|
+
try {
|
|
12
|
+
const parsedUrl = new URL(url);
|
|
13
|
+
const normalizedPath = parsedUrl.pathname.endsWith("/")
|
|
14
|
+
? parsedUrl.pathname.slice(0, -1)
|
|
15
|
+
: parsedUrl.pathname;
|
|
16
|
+
const pathSegments = normalizedPath.split("/").filter((segment) => segment.length > 0);
|
|
17
|
+
const lastSegment = pathSegments[pathSegments.length - 1];
|
|
18
|
+
if (lastSegment && lastSegment.length > 0) {
|
|
19
|
+
return decodeURIComponent(lastSegment);
|
|
20
|
+
}
|
|
21
|
+
return parsedUrl.hostname;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return url;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
10
27
|
const targetBuilders = {
|
|
11
28
|
url: (entry) => ({
|
|
12
29
|
kind: "url",
|
|
@@ -27,7 +44,7 @@ export class CaptureHttpPuppeteerUnit extends Unit {
|
|
|
27
44
|
constructor(options) {
|
|
28
45
|
super();
|
|
29
46
|
this.id = "captureHttpPuppeteer";
|
|
30
|
-
this.
|
|
47
|
+
this.description = "Capturing page via Puppeteer";
|
|
31
48
|
this.adapterOptions = options ?? {};
|
|
32
49
|
}
|
|
33
50
|
async run(ctx, rt) {
|
|
@@ -47,6 +64,9 @@ export class CaptureHttpPuppeteerUnit extends Unit {
|
|
|
47
64
|
inflightTracker.handleEvent(event);
|
|
48
65
|
rt.publish(NETWORK, event);
|
|
49
66
|
if (event.type === "request") {
|
|
67
|
+
const resourceName = toInterceptedResourceName(event.url);
|
|
68
|
+
const resourceTypeLabel = event.resourceType ? ` (${event.resourceType})` : "";
|
|
69
|
+
rt.log(`[puppeteer] intercepted ${resourceName}${resourceTypeLabel}`);
|
|
50
70
|
events.push({
|
|
51
71
|
type: "http.request",
|
|
52
72
|
requestId: event.requestId,
|
|
@@ -102,7 +122,7 @@ export class CaptureHttpPuppeteerUnit extends Unit {
|
|
|
102
122
|
void handleNetworkEvent(event);
|
|
103
123
|
},
|
|
104
124
|
onError: (error) => {
|
|
105
|
-
|
|
125
|
+
debugLog("[pagepocket][capture-http-puppeteer] adapter error", error);
|
|
106
126
|
}
|
|
107
127
|
}, {
|
|
108
128
|
timeoutMs: rt.options.timeoutMs,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagepocket/capture-http-puppeteer-unit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "PagePocket plugin: capture HTTP events (puppeteer adapter)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"puppeteer": "^22.12.1",
|
|
14
|
-
"@pagepocket/lib": "0.
|
|
15
|
-
"@pagepocket/contracts": "0.
|
|
14
|
+
"@pagepocket/lib": "0.13.0",
|
|
15
|
+
"@pagepocket/contracts": "0.13.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"typescript": "^5.4.5"
|