@pagepocket/capture-http-cdp-unit 0.8.6 → 0.9.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.
@@ -2,8 +2,9 @@ import { NETWORK } from "@pagepocket/contracts";
2
2
  import { Unit, createMemoryContentStore, InflightTracker, mapKind, networkIdle, normalizeCompletion, throwRequiredEntryKind, timeout } from "@pagepocket/lib";
3
3
  import { CdpAdapter } from "./internal/cdp-adapter.js";
4
4
  const headersRecordToList = (headers) => {
5
- if (!headers)
5
+ if (!headers) {
6
6
  return [];
7
+ }
7
8
  return Object.keys(headers).map((name) => ({ name, value: headers[name] }));
8
9
  };
9
10
  const targetBuilders = {
@@ -13,19 +13,22 @@ export const decodeBase64 = (input) => {
13
13
  export const encodeUtf8 = (input) => new TextEncoder().encode(input);
14
14
  export const normalizeHeaders = (headers) => {
15
15
  const output = {};
16
- if (!headers)
16
+ if (!headers) {
17
17
  return output;
18
+ }
18
19
  for (const key of Object.keys(headers)) {
19
20
  const value = headers[key];
20
- if (value === undefined || value === null)
21
+ if (value === undefined) {
21
22
  continue;
23
+ }
22
24
  output[key] = Array.isArray(value) ? value.join(", ") : String(value);
23
25
  }
24
26
  return output;
25
27
  };
26
28
  export const mapResourceType = (input) => {
27
- if (!input)
29
+ if (!input) {
28
30
  return undefined;
31
+ }
29
32
  const normalized = input.toLowerCase();
30
33
  switch (normalized) {
31
34
  case "document":
@@ -51,8 +54,9 @@ export const mapResourceType = (input) => {
51
54
  }
52
55
  };
53
56
  export const inferResourceTypeFromMime = (mimeType) => {
54
- if (!mimeType)
57
+ if (!mimeType) {
55
58
  return undefined;
59
+ }
56
60
  const normalized = mimeType.toLowerCase();
57
61
  if (normalized.includes("text/html") || normalized.includes("application/xhtml+xml")) {
58
62
  return "document";
@@ -40,8 +40,9 @@ export const createChromeDebuggerClient = (target, protocolVersion) => {
40
40
  });
41
41
  });
42
42
  const ensureAttached = async () => {
43
- if (attached)
43
+ if (attached) {
44
44
  return;
45
+ }
45
46
  await attach();
46
47
  };
47
48
  return {
@@ -61,10 +62,12 @@ export const createChromeDebuggerClient = (target, protocolVersion) => {
61
62
  },
62
63
  on: (event, listener) => {
63
64
  const handler = (source, method, params) => {
64
- if (source.tabId !== target.tabId)
65
+ if (source.tabId !== target.tabId) {
65
66
  return;
66
- if (method !== event)
67
+ }
68
+ if (method !== event) {
67
69
  return;
70
+ }
68
71
  listener(params);
69
72
  };
70
73
  listeners.set(listener, handler);
@@ -72,17 +75,20 @@ export const createChromeDebuggerClient = (target, protocolVersion) => {
72
75
  },
73
76
  off: (_event, listener) => {
74
77
  const handler = listeners.get(listener);
75
- if (!handler)
78
+ if (!handler) {
76
79
  return;
80
+ }
77
81
  listeners.delete(listener);
78
82
  chromeDebugger.onEvent.removeListener(handler);
79
83
  },
80
84
  close: async () => {
81
- if (closed)
85
+ if (closed) {
82
86
  return;
87
+ }
83
88
  closed = true;
84
- if (!attached)
89
+ if (!attached) {
85
90
  return;
91
+ }
86
92
  await detach();
87
93
  }
88
94
  };
@@ -5,12 +5,12 @@ type HtmlArtifact = {
5
5
  contentType?: string;
6
6
  };
7
7
  export declare const createHtmlMilestone: () => {
8
- htmlPromise: Promise<never>;
8
+ htmlPromise: Promise<HtmlArtifact>;
9
9
  tryResolveHtml: (input: {
10
10
  url: string;
11
11
  contentType?: string;
12
- bodyBytes: Uint8Array | null;
12
+ bodyBytes: Uint8Array | undefined;
13
13
  }) => void;
14
- getHtmlArtifact: () => HtmlArtifact | null;
14
+ getHtmlArtifact: () => HtmlArtifact | undefined;
15
15
  };
16
16
  export {};
@@ -1,6 +1,6 @@
1
1
  export const createHtmlMilestone = () => {
2
- let htmlArtifact = null;
3
- let resolveHtml = null;
2
+ let htmlArtifact;
3
+ let resolveHtml;
4
4
  const htmlPromise = new Promise((resolve, _reject) => {
5
5
  resolveHtml = resolve;
6
6
  });
@@ -19,7 +19,7 @@ export const createHtmlMilestone = () => {
19
19
  contentType: input.contentType
20
20
  };
21
21
  resolveHtml?.(htmlArtifact);
22
- resolveHtml = null;
22
+ resolveHtml = undefined;
23
23
  };
24
24
  return {
25
25
  htmlPromise,
@@ -1,6 +1,6 @@
1
1
  export const createTimestampResolver = () => {
2
2
  const requestTimeOffsets = new Map();
3
- let globalTimeOffset = null;
3
+ let globalTimeOffset;
4
4
  const resolveTimestampMs = (payload, requestId) => {
5
5
  if (typeof payload.wallTime === "number") {
6
6
  if (typeof payload.timestamp === "number") {
@@ -42,14 +42,14 @@ export const createCdpSession = async ({ client, handlers, ownsClient, triggerAc
42
42
  }
43
43
  catch (error) {
44
44
  if (isNoBodyError(error)) {
45
- return null;
45
+ return undefined;
46
46
  }
47
47
  throw error;
48
48
  }
49
49
  };
50
50
  const tryGetPageResourceContent = async (info) => {
51
51
  if (!info.frameId || !info.url) {
52
- return null;
52
+ return undefined;
53
53
  }
54
54
  try {
55
55
  const result = await callCdp(client, "Page.getResourceContent", {
@@ -62,7 +62,7 @@ export const createCdpSession = async ({ client, handlers, ownsClient, triggerAc
62
62
  return encodeUtf8(result.content);
63
63
  }
64
64
  catch {
65
- return null;
65
+ return undefined;
66
66
  }
67
67
  };
68
68
  const handleLoadingFinished = async (payload) => {
@@ -94,7 +94,7 @@ export const createCdpSession = async ({ client, handlers, ownsClient, triggerAc
94
94
  handlers.onEvent(updatedRequest);
95
95
  }
96
96
  }
97
- let bodyBytes = null;
97
+ let bodyBytes;
98
98
  try {
99
99
  bodyBytes = await tryGetResponseBody(cdpRequestId);
100
100
  }
@@ -102,7 +102,7 @@ export const createCdpSession = async ({ client, handlers, ownsClient, triggerAc
102
102
  handlers.onError?.(error instanceof Error ? error : new Error(String(error)));
103
103
  }
104
104
  if (bodyBytes && bodyBytes.byteLength === 0) {
105
- bodyBytes = null;
105
+ bodyBytes = undefined;
106
106
  }
107
107
  if (!bodyBytes) {
108
108
  const fallbackInfo = requestState.requestInfo.get(cdpRequestId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagepocket/capture-http-cdp-unit",
3
- "version": "0.8.6",
3
+ "version": "0.9.0",
4
4
  "description": "PagePocket plugin: capture HTTP events (CDP)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -10,8 +10,8 @@
10
10
  ],
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "@pagepocket/lib": "0.8.6",
14
- "@pagepocket/contracts": "0.8.6"
13
+ "@pagepocket/lib": "0.9.0",
14
+ "@pagepocket/contracts": "0.9.0"
15
15
  },
16
16
  "devDependencies": {
17
17
  "typescript": "^5.4.5"