@pagepocket/lib 0.7.0 → 0.8.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.
- package/README.md +7 -6
- package/dist/build-snapshot-from-bundle.d.ts +23 -0
- package/dist/build-snapshot-from-bundle.js +68 -0
- package/dist/builtin-blacklist.js +3 -6
- package/dist/bundle/from-network-store.d.ts +10 -0
- package/dist/bundle/from-network-store.js +26 -0
- package/dist/bundle/types.d.ts +32 -0
- package/dist/bundle/types.js +2 -0
- package/dist/capture/index.d.ts +14 -0
- package/dist/capture/index.js +86 -0
- package/dist/capture/memory-content-store.d.ts +4 -0
- package/dist/capture/memory-content-store.js +42 -0
- package/dist/capture/types.d.ts +61 -0
- package/dist/capture/types.js +2 -0
- package/dist/content-store.js +3 -8
- package/dist/content-type.d.ts +1 -1
- package/dist/content-type.js +2 -28
- package/dist/core/_impl/completion.d.ts +4 -0
- package/dist/core/_impl/completion.js +29 -0
- package/dist/core/_impl/content-store.d.ts +21 -0
- package/dist/core/_impl/content-store.js +91 -0
- package/dist/core/_impl/debug.d.ts +1 -0
- package/dist/core/_impl/debug.js +16 -0
- package/dist/core/_impl/inflight-tracker.d.ts +19 -0
- package/dist/core/_impl/inflight-tracker.js +48 -0
- package/dist/core/_impl/pagepocket.d.ts +27 -0
- package/dist/core/_impl/pagepocket.js +155 -0
- package/dist/core/capture/_impl/memory-content-store.d.ts +4 -0
- package/dist/core/capture/_impl/memory-content-store.js +42 -0
- package/dist/core/capture/_impl/types.d.ts +61 -0
- package/dist/core/capture/_impl/types.js +2 -0
- package/dist/core/capture/internal/memory-content-store.d.ts +4 -0
- package/dist/core/capture/internal/memory-content-store.js +42 -0
- package/dist/core/capture/internal/types.d.ts +61 -0
- package/dist/core/capture/internal/types.js +2 -0
- package/dist/core/capture/memory-content-store.d.ts +4 -0
- package/dist/core/capture/memory-content-store.js +38 -0
- package/dist/core/capture/types.d.ts +61 -0
- package/dist/core/capture/types.js +1 -0
- package/dist/core/completion.d.ts +4 -0
- package/dist/core/completion.js +23 -0
- package/dist/core/content-store.d.ts +21 -0
- package/dist/core/content-store.js +54 -0
- package/dist/core/debug.d.ts +1 -0
- package/dist/core/debug.js +12 -0
- package/dist/core/file-tree-merge.d.ts +2 -0
- package/dist/core/file-tree-merge.js +27 -0
- package/dist/core/file-tree.d.ts +36 -0
- package/dist/core/file-tree.js +1 -0
- package/dist/core/inflight-tracker.d.ts +19 -0
- package/dist/core/inflight-tracker.js +44 -0
- package/dist/core/internal/completion.d.ts +4 -0
- package/dist/core/internal/completion.js +29 -0
- package/dist/core/internal/content-store.d.ts +21 -0
- package/dist/core/internal/content-store.js +91 -0
- package/dist/core/internal/debug.d.ts +1 -0
- package/dist/core/internal/debug.js +16 -0
- package/dist/core/internal/inflight-tracker.d.ts +19 -0
- package/dist/core/internal/inflight-tracker.js +48 -0
- package/dist/core/internal/pagepocket.d.ts +27 -0
- package/dist/core/internal/pagepocket.js +155 -0
- package/dist/core/pagepocket.d.ts +38 -0
- package/dist/core/pagepocket.js +57 -0
- package/dist/core/plugin/_impl/context.d.ts +47 -0
- package/dist/core/plugin/_impl/context.js +142 -0
- package/dist/core/plugin/_impl/runner.d.ts +12 -0
- package/dist/core/plugin/_impl/runner.js +232 -0
- package/dist/core/plugin/_impl/types.d.ts +108 -0
- package/dist/core/plugin/_impl/types.js +2 -0
- package/dist/core/plugin/context.d.ts +47 -0
- package/dist/core/plugin/context.js +205 -0
- package/dist/core/plugin/internal/context.d.ts +47 -0
- package/dist/core/plugin/internal/context.js +142 -0
- package/dist/core/plugin/internal/runner.d.ts +12 -0
- package/dist/core/plugin/internal/runner.js +232 -0
- package/dist/core/plugin/internal/types.d.ts +108 -0
- package/dist/core/plugin/internal/types.js +2 -0
- package/dist/core/plugin/runner-utils.d.ts +9 -0
- package/dist/core/plugin/runner-utils.js +29 -0
- package/dist/core/plugin/runner.d.ts +12 -0
- package/dist/core/plugin/runner.js +118 -0
- package/dist/core/plugin/types.d.ts +117 -0
- package/dist/core/plugin/types.js +1 -0
- package/dist/core/runtime/types.d.ts +14 -0
- package/dist/core/runtime/types.js +2 -0
- package/dist/css-rewrite.js +1 -5
- package/dist/debug.d.ts +0 -1
- package/dist/debug.js +3 -5
- package/dist/files/types.d.ts +41 -0
- package/dist/files/types.js +2 -0
- package/dist/hack-html.js +20 -13
- package/dist/hackers/index.d.ts +1 -1
- package/dist/hackers/index.js +24 -27
- package/dist/hackers/preload-fetch.d.ts +1 -1
- package/dist/hackers/preload-fetch.js +1 -4
- package/dist/hackers/preload-xhr.d.ts +1 -1
- package/dist/hackers/preload-xhr.js +1 -4
- package/dist/hackers/replay-beacon.d.ts +1 -1
- package/dist/hackers/replay-beacon.js +1 -4
- package/dist/hackers/replay-block-text-fragment.d.ts +1 -1
- package/dist/hackers/replay-block-text-fragment.js +1 -4
- package/dist/hackers/replay-css-proxy.d.ts +1 -1
- package/dist/hackers/replay-css-proxy.js +9 -12
- package/dist/hackers/replay-dom-rewrite.d.ts +1 -1
- package/dist/hackers/replay-dom-rewrite.js +165 -154
- package/dist/hackers/replay-eventsource.d.ts +1 -1
- package/dist/hackers/replay-eventsource.js +1 -4
- package/dist/hackers/replay-fetch.d.ts +1 -1
- package/dist/hackers/replay-fetch.js +1 -4
- package/dist/hackers/replay-history-path.d.ts +1 -1
- package/dist/hackers/replay-history-path.js +1 -4
- package/dist/hackers/replay-svg-image.d.ts +1 -1
- package/dist/hackers/replay-svg-image.js +1 -4
- package/dist/hackers/replay-websocket.d.ts +1 -1
- package/dist/hackers/replay-websocket.js +1 -4
- package/dist/hackers/replay-xhr.d.ts +1 -1
- package/dist/hackers/replay-xhr.js +1 -4
- package/dist/hackers/types.js +1 -2
- package/dist/index.d.ts +29 -13
- package/dist/index.js +23 -44
- package/dist/kind-map.d.ts +68 -0
- package/dist/kind-map.js +58 -0
- package/dist/network-store.js +12 -1
- package/dist/pagepocket.d.ts +19 -4
- package/dist/pagepocket.js +36 -102
- package/dist/path-resolver.d.ts +1 -2
- package/dist/path-resolver.js +9 -16
- package/dist/plugin/builtins/build-snapshot-plugin.d.ts +5 -0
- package/dist/plugin/builtins/build-snapshot-plugin.js +84 -0
- package/dist/plugin/builtins/replace-elements-plugin.d.ts +8 -0
- package/dist/plugin/builtins/replace-elements-plugin.js +13 -0
- package/dist/plugin/builtins/to-directory-plugin.d.ts +7 -0
- package/dist/plugin/builtins/to-directory-plugin.js +20 -0
- package/dist/plugin/builtins/to-zip-plugin.d.ts +5 -0
- package/dist/plugin/builtins/to-zip-plugin.js +19 -0
- package/dist/plugin/context.d.ts +47 -0
- package/dist/plugin/context.js +142 -0
- package/dist/plugin/runner.d.ts +12 -0
- package/dist/plugin/runner.js +232 -0
- package/dist/plugin/types.d.ts +108 -0
- package/dist/plugin/types.js +2 -0
- package/dist/plugins/build-files-from-capture.d.ts +5 -0
- package/dist/plugins/build-files-from-capture.js +85 -0
- package/dist/plugins/build-warc.d.ts +5 -0
- package/dist/plugins/build-warc.js +225 -0
- package/dist/plugins/builtins/manifest.d.ts +2 -0
- package/dist/plugins/builtins/manifest.js +42 -0
- package/dist/plugins/builtins/snapshot-directory.d.ts +2 -0
- package/dist/plugins/builtins/snapshot-directory.js +24 -0
- package/dist/plugins/builtins/snapshot-zip.d.ts +2 -0
- package/dist/plugins/builtins/snapshot-zip.js +25 -0
- package/dist/plugins/capture-http-lighterceptor.d.ts +5 -0
- package/dist/plugins/capture-http-lighterceptor.js +85 -0
- package/dist/plugins/capture-http-puppeteer.d.ts +5 -0
- package/dist/plugins/capture-http-puppeteer.js +85 -0
- package/dist/plugins/host.d.ts +37 -0
- package/dist/plugins/host.js +105 -0
- package/dist/plugins/index.d.ts +6 -0
- package/dist/plugins/index.js +11 -0
- package/dist/plugins/ordering.d.ts +2 -0
- package/dist/plugins/ordering.js +19 -0
- package/dist/plugins/types.d.ts +51 -0
- package/dist/plugins/types.js +2 -0
- package/dist/preload.js +3 -7
- package/dist/replace-elements/actions.d.ts +5 -0
- package/dist/replace-elements/actions.js +86 -0
- package/dist/replace-elements/match.d.ts +5 -0
- package/dist/replace-elements/match.js +46 -0
- package/dist/replace-elements/normalize.d.ts +21 -0
- package/dist/replace-elements/normalize.js +50 -0
- package/dist/replace-elements.d.ts +1 -1
- package/dist/replace-elements.js +5 -185
- package/dist/replay/match-api.d.ts +10 -0
- package/dist/replay/match-api.js +162 -0
- package/dist/replay/templates/match-api-source.d.ts +1 -0
- package/dist/replay/templates/match-api-source.js +137 -0
- package/dist/replay/templates/replay-script-template.d.ts +5 -0
- package/dist/replay/templates/replay-script-template.js +337 -0
- package/dist/replay/templates/resource-proxy-script.d.ts +1 -0
- package/dist/replay/templates/resource-proxy-script.js +274 -0
- package/dist/replay-script.d.ts +3 -10
- package/dist/replay-script.js +11 -625
- package/dist/resource-filter.d.ts +1 -1
- package/dist/resource-filter.js +1 -5
- package/dist/resource-proxy/escape-percent.d.ts +1 -0
- package/dist/resource-proxy/escape-percent.js +12 -0
- package/dist/resource-proxy/multimap.d.ts +3 -0
- package/dist/resource-proxy/multimap.js +18 -0
- package/dist/resource-proxy/pathname-variants.d.ts +3 -0
- package/dist/resource-proxy/pathname-variants.js +54 -0
- package/dist/resource-proxy.d.ts +4 -2
- package/dist/resource-proxy.js +48 -117
- package/dist/resources.js +4 -42
- package/dist/rewrite-links/js-imports.d.ts +3 -0
- package/dist/rewrite-links/js-imports.js +56 -0
- package/dist/rewrite-links/link-rel.d.ts +2 -0
- package/dist/rewrite-links/link-rel.js +10 -0
- package/dist/rewrite-links/meta-refresh.d.ts +3 -0
- package/dist/rewrite-links/meta-refresh.js +22 -0
- package/dist/rewrite-links/skip.d.ts +1 -0
- package/dist/rewrite-links/skip.js +10 -0
- package/dist/rewrite-links/srcset.d.ts +3 -0
- package/dist/rewrite-links/srcset.js +63 -0
- package/dist/rewrite-links/url-resolve.d.ts +3 -0
- package/dist/rewrite-links/url-resolve.js +13 -0
- package/dist/rewrite-links.d.ts +3 -3
- package/dist/rewrite-links.js +31 -240
- package/dist/snapshot-builder/api.d.ts +3 -0
- package/dist/snapshot-builder/api.js +6 -0
- package/dist/snapshot-builder/build-snapshot.d.ts +3 -0
- package/dist/snapshot-builder/build-snapshot.js +138 -0
- package/dist/snapshot-builder/capture-index/index-capture.d.ts +13 -0
- package/dist/snapshot-builder/capture-index/index-capture.js +168 -0
- package/dist/snapshot-builder/capture-index/index.d.ts +2 -0
- package/dist/snapshot-builder/capture-index/index.js +1 -0
- package/dist/snapshot-builder/capture-index/types.d.ts +12 -0
- package/dist/snapshot-builder/capture-index/types.js +1 -0
- package/dist/snapshot-builder/capture-index.d.ts +12 -0
- package/dist/snapshot-builder/capture-index.js +173 -0
- package/dist/snapshot-builder/emit-document.d.ts +24 -0
- package/dist/snapshot-builder/emit-document.js +50 -0
- package/dist/snapshot-builder/grouping.d.ts +8 -0
- package/dist/snapshot-builder/grouping.js +87 -0
- package/dist/snapshot-builder/http.d.ts +6 -0
- package/dist/snapshot-builder/http.js +28 -0
- package/dist/snapshot-builder/index.d.ts +4 -0
- package/dist/snapshot-builder/index.js +2 -0
- package/dist/snapshot-builder/path-map.d.ts +3 -0
- package/dist/snapshot-builder/path-map.js +35 -0
- package/dist/snapshot-builder/resources-path.d.ts +23 -0
- package/dist/snapshot-builder/resources-path.js +47 -0
- package/dist/snapshot-builder/rewrite-resource.d.ts +18 -0
- package/dist/snapshot-builder/rewrite-resource.js +52 -0
- package/dist/snapshot-builder/types.d.ts +37 -0
- package/dist/snapshot-builder/types.js +2 -0
- package/dist/snapshot-builder.d.ts +12 -8
- package/dist/snapshot-builder.js +252 -27
- package/dist/types.d.ts +122 -78
- package/dist/types.js +4 -2
- package/dist/units/contracts-bridge.d.ts +76 -0
- package/dist/units/contracts-bridge.js +6 -0
- package/dist/units/index.d.ts +4 -0
- package/dist/units/index.js +2 -0
- package/dist/units/runner.d.ts +11 -0
- package/dist/units/runner.js +270 -0
- package/dist/units/types.d.ts +39 -0
- package/dist/units/types.js +1 -0
- package/dist/utils/streams.d.ts +2 -0
- package/dist/utils/streams.js +29 -0
- package/dist/utils.d.ts +35 -1
- package/dist/utils.js +107 -29
- package/dist/v3/contracts-bridge.d.ts +69 -0
- package/dist/v3/contracts-bridge.js +5 -0
- package/dist/v3/index.d.ts +4 -0
- package/dist/v3/index.js +2 -0
- package/dist/v3/runner.d.ts +20 -0
- package/dist/v3/runner.js +245 -0
- package/dist/v3/types.d.ts +39 -0
- package/dist/v3/types.js +1 -0
- package/dist/writers.js +3 -1
- package/package.json +11 -3
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { readBinary, remove, write } from "@pagepocket/uni-fs";
|
|
2
|
+
import { streamFromUint8Array } from "../utils/streams.js";
|
|
3
|
+
import { hashString, toUint8Array } from "../utils.js";
|
|
4
|
+
const DEFAULT_THRESHOLD = 256 * 1024;
|
|
5
|
+
const DEFAULT_BASE_DIR = ".pagepocket_store";
|
|
6
|
+
const nowId = () => `${Date.now()}_${Math.random().toString(16).slice(2)}`;
|
|
7
|
+
const isNodeEnvironment = () => {
|
|
8
|
+
const globalProcess = globalThis.process;
|
|
9
|
+
return typeof globalProcess?.versions?.node === "string";
|
|
10
|
+
};
|
|
11
|
+
export class HybridContentStore {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.name = "hybrid";
|
|
14
|
+
this.storedIds = new Set();
|
|
15
|
+
this.thresholdBytes = options?.thresholdBytes ?? DEFAULT_THRESHOLD;
|
|
16
|
+
this.baseDir = options?.baseDir ?? DEFAULT_BASE_DIR;
|
|
17
|
+
}
|
|
18
|
+
async put(body, meta) {
|
|
19
|
+
const data = await toUint8Array(body);
|
|
20
|
+
const size = data.byteLength;
|
|
21
|
+
if (size <= this.thresholdBytes) {
|
|
22
|
+
return { kind: "memory", data };
|
|
23
|
+
}
|
|
24
|
+
const id = `${hashString(meta.url)}_${nowId()}`;
|
|
25
|
+
await write(`${this.baseDir}/${id}`, "bin", data);
|
|
26
|
+
this.storedIds.add(id);
|
|
27
|
+
return { kind: "store-ref", id };
|
|
28
|
+
}
|
|
29
|
+
async open(ref) {
|
|
30
|
+
if (ref.kind === "memory") {
|
|
31
|
+
return streamFromUint8Array(ref.data);
|
|
32
|
+
}
|
|
33
|
+
const data = await readBinary(`${this.baseDir}/${ref.id}`, "bin");
|
|
34
|
+
return streamFromUint8Array(data);
|
|
35
|
+
}
|
|
36
|
+
async dispose() {
|
|
37
|
+
const entries = Array.from(this.storedIds);
|
|
38
|
+
this.storedIds.clear();
|
|
39
|
+
await Promise.all(entries.map((id) => remove(`${this.baseDir}/${id}`, "bin").catch(() => { })));
|
|
40
|
+
await this.removeBaseDir().catch(() => { });
|
|
41
|
+
}
|
|
42
|
+
async removeBaseDir() {
|
|
43
|
+
if (!isNodeEnvironment()) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (!this.baseDir || this.baseDir === "/" || this.baseDir === ".") {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const { resolve, isAbsolute } = await import("node:path");
|
|
50
|
+
const { rm } = await import("node:fs/promises");
|
|
51
|
+
const target = isAbsolute(this.baseDir) ? this.baseDir : resolve(this.baseDir);
|
|
52
|
+
await rm(target, { recursive: true, force: true });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const debugLog: (...args: unknown[]) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const isDebugEnabled = () => {
|
|
2
|
+
const globalProcess = globalThis
|
|
3
|
+
.process;
|
|
4
|
+
const value = globalProcess?.env?.PAGEPOCKET_DEBUG;
|
|
5
|
+
return Boolean(value);
|
|
6
|
+
};
|
|
7
|
+
export const debugLog = (...args) => {
|
|
8
|
+
if (!isDebugEnabled()) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
console.log(...args);
|
|
12
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const entryKey = (entry) => `${entry.kind}:${entry.path}`;
|
|
2
|
+
const mergeDirectories = (a, b) => {
|
|
3
|
+
const outByKey = new Map();
|
|
4
|
+
for (const entry of a.entries) {
|
|
5
|
+
outByKey.set(entryKey(entry), entry);
|
|
6
|
+
}
|
|
7
|
+
for (const entry of b.entries) {
|
|
8
|
+
const key = entryKey(entry);
|
|
9
|
+
const prev = outByKey.get(key);
|
|
10
|
+
if (prev && prev.kind === "directory" && entry.kind === "directory") {
|
|
11
|
+
outByKey.set(key, mergeDirectories(prev, entry));
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
outByKey.set(key, entry);
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
...a,
|
|
18
|
+
entries: Array.from(outByKey.values())
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export const mergeFileTrees = (base, extra) => {
|
|
22
|
+
const root = mergeDirectories(base.root, extra.root);
|
|
23
|
+
return {
|
|
24
|
+
root,
|
|
25
|
+
...(base.content ? { content: base.content } : {})
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ContentRef, ContentStoreHandle } from "../types.js";
|
|
2
|
+
export type FileTreeSource = {
|
|
3
|
+
kind: "bytes";
|
|
4
|
+
data: Uint8Array;
|
|
5
|
+
} | {
|
|
6
|
+
kind: "text";
|
|
7
|
+
text: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: "content-ref";
|
|
10
|
+
ref: ContentRef;
|
|
11
|
+
};
|
|
12
|
+
export type FileTreeFile = {
|
|
13
|
+
kind: "file";
|
|
14
|
+
/** Path relative to the root (posix-ish, may include '/'). */
|
|
15
|
+
path: string;
|
|
16
|
+
source: FileTreeSource;
|
|
17
|
+
};
|
|
18
|
+
export type FileTreeDirectory = {
|
|
19
|
+
kind: "directory";
|
|
20
|
+
/** Path relative to the root (posix-ish, may include '/'). */
|
|
21
|
+
path: string;
|
|
22
|
+
entries: FileTreeEntry[];
|
|
23
|
+
};
|
|
24
|
+
export type FileTreeEntry = FileTreeFile | FileTreeDirectory;
|
|
25
|
+
/**
|
|
26
|
+
* Core, plugin-agnostic filesystem tree.
|
|
27
|
+
*
|
|
28
|
+
* Builders should attach this to `ctx.value.files`.
|
|
29
|
+
* Writers should consume it.
|
|
30
|
+
*/
|
|
31
|
+
export type FileTree = {
|
|
32
|
+
/** Virtual root directory; its path should be "". */
|
|
33
|
+
root: FileTreeDirectory;
|
|
34
|
+
/** Optional content handle for `{ kind: "content-ref" }`. */
|
|
35
|
+
content?: ContentStoreHandle;
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { NetworkEvent } from "../types.js";
|
|
2
|
+
type InflightStats = {
|
|
3
|
+
inflightRequests: number;
|
|
4
|
+
lastNetworkTs: number;
|
|
5
|
+
totalRequests: number;
|
|
6
|
+
};
|
|
7
|
+
export declare class InflightTracker {
|
|
8
|
+
private inflight;
|
|
9
|
+
private inflightRequests;
|
|
10
|
+
private lastNetworkTs;
|
|
11
|
+
private totalRequests;
|
|
12
|
+
private shouldIgnore;
|
|
13
|
+
constructor(options?: {
|
|
14
|
+
shouldIgnore?: (event: NetworkEvent) => boolean;
|
|
15
|
+
});
|
|
16
|
+
handleEvent(event: NetworkEvent): InflightStats;
|
|
17
|
+
getStats(): InflightStats;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export class InflightTracker {
|
|
2
|
+
constructor(options) {
|
|
3
|
+
this.inflight = new Set();
|
|
4
|
+
this.inflightRequests = 0;
|
|
5
|
+
this.lastNetworkTs = Date.now();
|
|
6
|
+
this.totalRequests = 0;
|
|
7
|
+
this.shouldIgnore = options?.shouldIgnore ?? (() => false);
|
|
8
|
+
}
|
|
9
|
+
handleEvent(event) {
|
|
10
|
+
if (this.shouldIgnore(event)) {
|
|
11
|
+
return this.getStats();
|
|
12
|
+
}
|
|
13
|
+
if (event?.timestamp) {
|
|
14
|
+
this.lastNetworkTs = event.timestamp;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
this.lastNetworkTs = Date.now();
|
|
18
|
+
}
|
|
19
|
+
if (event?.type === "request") {
|
|
20
|
+
this.totalRequests += 1;
|
|
21
|
+
if (!this.inflight.has(event.requestId)) {
|
|
22
|
+
this.inflight.add(event.requestId);
|
|
23
|
+
this.inflightRequests += 1;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (event?.type === "response" || event?.type === "failed") {
|
|
27
|
+
if (this.inflight.delete(event.requestId)) {
|
|
28
|
+
this.inflightRequests = Math.max(0, this.inflightRequests - 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
inflightRequests: this.inflightRequests,
|
|
33
|
+
lastNetworkTs: this.lastNetworkTs,
|
|
34
|
+
totalRequests: this.totalRequests
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
getStats() {
|
|
38
|
+
return {
|
|
39
|
+
inflightRequests: this.inflightRequests,
|
|
40
|
+
lastNetworkTs: this.lastNetworkTs,
|
|
41
|
+
totalRequests: this.totalRequests
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CompletionStrategy } from "../../types";
|
|
2
|
+
export declare const timeout: (ms: number) => CompletionStrategy;
|
|
3
|
+
export declare const networkIdle: (ms: number, checkInterval?: number) => CompletionStrategy;
|
|
4
|
+
export declare const normalizeCompletion: (completion?: CompletionStrategy | CompletionStrategy[]) => CompletionStrategy[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeCompletion = exports.networkIdle = exports.timeout = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const timeout = (ms) => ({
|
|
6
|
+
async wait() {
|
|
7
|
+
await (0, utils_1.sleep)(ms);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
exports.timeout = timeout;
|
|
11
|
+
const networkIdle = (ms, checkInterval = 100) => ({
|
|
12
|
+
async wait(ctx) {
|
|
13
|
+
while (true) {
|
|
14
|
+
const stats = ctx.getStats();
|
|
15
|
+
const idleFor = ctx.now() - stats.lastNetworkTs;
|
|
16
|
+
if (stats.inflightRequests === 0 && idleFor >= ms) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
await (0, utils_1.sleep)(Math.min(checkInterval, ms));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
exports.networkIdle = networkIdle;
|
|
24
|
+
const normalizeCompletion = (completion) => {
|
|
25
|
+
if (!completion)
|
|
26
|
+
return [];
|
|
27
|
+
return Array.isArray(completion) ? completion : [completion];
|
|
28
|
+
};
|
|
29
|
+
exports.normalizeCompletion = normalizeCompletion;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BodySource, ContentRef, ContentStore } from "../../types";
|
|
2
|
+
type HybridContentStoreOptions = {
|
|
3
|
+
thresholdBytes?: number;
|
|
4
|
+
baseDir?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare class HybridContentStore implements ContentStore {
|
|
7
|
+
name: string;
|
|
8
|
+
private thresholdBytes;
|
|
9
|
+
private baseDir;
|
|
10
|
+
private storedIds;
|
|
11
|
+
constructor(options?: HybridContentStoreOptions);
|
|
12
|
+
put(body: BodySource, meta: {
|
|
13
|
+
url: string;
|
|
14
|
+
mimeType?: string;
|
|
15
|
+
sizeHint?: number;
|
|
16
|
+
}): Promise<ContentRef>;
|
|
17
|
+
open(ref: ContentRef): Promise<ReadableStream<Uint8Array>>;
|
|
18
|
+
dispose(): Promise<void>;
|
|
19
|
+
private removeBaseDir;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.HybridContentStore = void 0;
|
|
37
|
+
const uni_fs_1 = require("@pagepocket/uni-fs");
|
|
38
|
+
const utils_1 = require("../../utils");
|
|
39
|
+
const streams_1 = require("../../utils/streams");
|
|
40
|
+
const DEFAULT_THRESHOLD = 256 * 1024;
|
|
41
|
+
const DEFAULT_BASE_DIR = ".pagepocket_store";
|
|
42
|
+
const nowId = () => `${Date.now()}_${Math.random().toString(16).slice(2)}`;
|
|
43
|
+
const isNodeEnvironment = () => {
|
|
44
|
+
const globalProcess = globalThis.process;
|
|
45
|
+
return typeof globalProcess?.versions?.node === "string";
|
|
46
|
+
};
|
|
47
|
+
class HybridContentStore {
|
|
48
|
+
constructor(options) {
|
|
49
|
+
this.name = "hybrid";
|
|
50
|
+
this.storedIds = new Set();
|
|
51
|
+
this.thresholdBytes = options?.thresholdBytes ?? DEFAULT_THRESHOLD;
|
|
52
|
+
this.baseDir = options?.baseDir ?? DEFAULT_BASE_DIR;
|
|
53
|
+
}
|
|
54
|
+
async put(body, meta) {
|
|
55
|
+
const data = await (0, utils_1.toUint8Array)(body);
|
|
56
|
+
const size = data.byteLength;
|
|
57
|
+
if (size <= this.thresholdBytes) {
|
|
58
|
+
return { kind: "memory", data };
|
|
59
|
+
}
|
|
60
|
+
const id = `${(0, utils_1.hashString)(meta.url)}_${nowId()}`;
|
|
61
|
+
await (0, uni_fs_1.write)(`${this.baseDir}/${id}`, "bin", data);
|
|
62
|
+
this.storedIds.add(id);
|
|
63
|
+
return { kind: "store-ref", id };
|
|
64
|
+
}
|
|
65
|
+
async open(ref) {
|
|
66
|
+
if (ref.kind === "memory") {
|
|
67
|
+
return (0, streams_1.streamFromUint8Array)(ref.data);
|
|
68
|
+
}
|
|
69
|
+
const data = await (0, uni_fs_1.readBinary)(`${this.baseDir}/${ref.id}`, "bin");
|
|
70
|
+
return (0, streams_1.streamFromUint8Array)(data);
|
|
71
|
+
}
|
|
72
|
+
async dispose() {
|
|
73
|
+
const entries = Array.from(this.storedIds);
|
|
74
|
+
this.storedIds.clear();
|
|
75
|
+
await Promise.all(entries.map((id) => (0, uni_fs_1.remove)(`${this.baseDir}/${id}`, "bin").catch(() => { })));
|
|
76
|
+
await this.removeBaseDir().catch(() => { });
|
|
77
|
+
}
|
|
78
|
+
async removeBaseDir() {
|
|
79
|
+
if (!isNodeEnvironment()) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (!this.baseDir || this.baseDir === "/" || this.baseDir === ".") {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const { resolve, isAbsolute } = await Promise.resolve().then(() => __importStar(require("node:path")));
|
|
86
|
+
const { rm } = await Promise.resolve().then(() => __importStar(require("node:fs/promises")));
|
|
87
|
+
const target = isAbsolute(this.baseDir) ? this.baseDir : resolve(this.baseDir);
|
|
88
|
+
await rm(target, { recursive: true, force: true });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.HybridContentStore = HybridContentStore;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const debugLog: (...args: unknown[]) => void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.debugLog = void 0;
|
|
4
|
+
const isDebugEnabled = () => {
|
|
5
|
+
const globalProcess = globalThis
|
|
6
|
+
.process;
|
|
7
|
+
const value = globalProcess?.env?.PAGEPOCKET_DEBUG;
|
|
8
|
+
return Boolean(value);
|
|
9
|
+
};
|
|
10
|
+
const debugLog = (...args) => {
|
|
11
|
+
if (!isDebugEnabled()) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
console.log(...args);
|
|
15
|
+
};
|
|
16
|
+
exports.debugLog = debugLog;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { NetworkEvent } from "@pagepocket/interceptor";
|
|
2
|
+
type InflightStats = {
|
|
3
|
+
inflightRequests: number;
|
|
4
|
+
lastNetworkTs: number;
|
|
5
|
+
totalRequests: number;
|
|
6
|
+
};
|
|
7
|
+
export declare class InflightTracker {
|
|
8
|
+
private inflight;
|
|
9
|
+
private inflightRequests;
|
|
10
|
+
private lastNetworkTs;
|
|
11
|
+
private totalRequests;
|
|
12
|
+
private shouldIgnore;
|
|
13
|
+
constructor(options?: {
|
|
14
|
+
shouldIgnore?: (event: NetworkEvent) => boolean;
|
|
15
|
+
});
|
|
16
|
+
handleEvent(event: NetworkEvent): InflightStats;
|
|
17
|
+
getStats(): InflightStats;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InflightTracker = void 0;
|
|
4
|
+
class InflightTracker {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.inflight = new Set();
|
|
7
|
+
this.inflightRequests = 0;
|
|
8
|
+
this.lastNetworkTs = Date.now();
|
|
9
|
+
this.totalRequests = 0;
|
|
10
|
+
this.shouldIgnore = options?.shouldIgnore ?? (() => false);
|
|
11
|
+
}
|
|
12
|
+
handleEvent(event) {
|
|
13
|
+
if (this.shouldIgnore(event)) {
|
|
14
|
+
return this.getStats();
|
|
15
|
+
}
|
|
16
|
+
if (event?.timestamp) {
|
|
17
|
+
this.lastNetworkTs = event.timestamp;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.lastNetworkTs = Date.now();
|
|
21
|
+
}
|
|
22
|
+
if (event?.type === "request") {
|
|
23
|
+
this.totalRequests += 1;
|
|
24
|
+
if (!this.inflight.has(event.requestId)) {
|
|
25
|
+
this.inflight.add(event.requestId);
|
|
26
|
+
this.inflightRequests += 1;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (event?.type === "response" || event?.type === "failed") {
|
|
30
|
+
if (this.inflight.delete(event.requestId)) {
|
|
31
|
+
this.inflightRequests = Math.max(0, this.inflightRequests - 1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
inflightRequests: this.inflightRequests,
|
|
36
|
+
lastNetworkTs: this.lastNetworkTs,
|
|
37
|
+
totalRequests: this.totalRequests
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
getStats() {
|
|
41
|
+
return {
|
|
42
|
+
inflightRequests: this.inflightRequests,
|
|
43
|
+
lastNetworkTs: this.lastNetworkTs,
|
|
44
|
+
totalRequests: this.totalRequests
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.InflightTracker = InflightTracker;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { NetworkEvent } from "@pagepocket/interceptor";
|
|
2
|
+
import type { NetworkEventStream, PagePocketOptions } from "../../types";
|
|
3
|
+
import type { CaptureWithPluginsOptions, PagePocketCaptureResult } from "../plugin/types";
|
|
4
|
+
export declare class PagePocket {
|
|
5
|
+
private target;
|
|
6
|
+
private options;
|
|
7
|
+
private eventStream;
|
|
8
|
+
private constructor();
|
|
9
|
+
static fromURL(url: string, options?: PagePocketOptions): PagePocket;
|
|
10
|
+
static fromPuppeteerPage(page: unknown, options?: PagePocketOptions): PagePocket;
|
|
11
|
+
static fromCDPTab(tabId: number, options?: PagePocketOptions): PagePocket;
|
|
12
|
+
static fromHTMLString(htmlString: string, options: {
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
url?: string;
|
|
15
|
+
} & PagePocketOptions): PagePocket;
|
|
16
|
+
interceptedRequestEvents(): NetworkEventStream;
|
|
17
|
+
/** @internal */
|
|
18
|
+
_emitNetworkEvent(event: NetworkEvent): void;
|
|
19
|
+
/** @internal */
|
|
20
|
+
_closeNetworkEventStream(): void;
|
|
21
|
+
static fromDocument(doc: unknown, options: {
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
url?: string;
|
|
24
|
+
serialize?: (doc: unknown) => string;
|
|
25
|
+
} & PagePocketOptions): PagePocket;
|
|
26
|
+
capture(options: CaptureWithPluginsOptions): Promise<PagePocketCaptureResult>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PagePocket = void 0;
|
|
4
|
+
const runner_1 = require("../plugin/runner");
|
|
5
|
+
class AsyncEventQueue {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.values = [];
|
|
8
|
+
this.pending = [];
|
|
9
|
+
this.closed = false;
|
|
10
|
+
}
|
|
11
|
+
push(value) {
|
|
12
|
+
if (this.closed) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (this.pending.length > 0) {
|
|
16
|
+
const resolve = this.pending.shift();
|
|
17
|
+
resolve?.({ kind: "value", value });
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
this.values.push({ kind: "value", value });
|
|
21
|
+
}
|
|
22
|
+
close() {
|
|
23
|
+
if (this.closed) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
this.closed = true;
|
|
27
|
+
if (this.pending.length > 0) {
|
|
28
|
+
for (const resolve of this.pending) {
|
|
29
|
+
resolve({ kind: "close" });
|
|
30
|
+
}
|
|
31
|
+
this.pending = [];
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this.values.push({ kind: "close" });
|
|
35
|
+
}
|
|
36
|
+
async *iterate() {
|
|
37
|
+
while (true) {
|
|
38
|
+
if (this.values.length > 0) {
|
|
39
|
+
const item = this.values.shift();
|
|
40
|
+
if (!item || item.kind === "close") {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
yield item.value;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (this.closed) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const item = await new Promise((resolve) => {
|
|
50
|
+
this.pending.push(resolve);
|
|
51
|
+
});
|
|
52
|
+
if (item.kind === "close") {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
yield item.value;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
class BroadcastAsyncIterable {
|
|
60
|
+
constructor() {
|
|
61
|
+
this.queues = new Set();
|
|
62
|
+
this.closed = false;
|
|
63
|
+
}
|
|
64
|
+
subscribe() {
|
|
65
|
+
const queue = new AsyncEventQueue();
|
|
66
|
+
if (this.closed) {
|
|
67
|
+
queue.close();
|
|
68
|
+
}
|
|
69
|
+
this.queues.add(queue);
|
|
70
|
+
return (async function* (owner) {
|
|
71
|
+
try {
|
|
72
|
+
for await (const value of queue.iterate()) {
|
|
73
|
+
yield value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
owner.queues.delete(queue);
|
|
78
|
+
queue.close();
|
|
79
|
+
}
|
|
80
|
+
})(this);
|
|
81
|
+
}
|
|
82
|
+
emit(value) {
|
|
83
|
+
if (this.queues.size === 0) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
for (const queue of this.queues) {
|
|
87
|
+
queue.push(value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
close() {
|
|
91
|
+
if (this.closed) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.closed = true;
|
|
95
|
+
for (const queue of this.queues) {
|
|
96
|
+
queue.close();
|
|
97
|
+
}
|
|
98
|
+
this.queues.clear();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
class PagePocket {
|
|
102
|
+
constructor(target, options) {
|
|
103
|
+
this.eventStream = new BroadcastAsyncIterable();
|
|
104
|
+
this.target = target;
|
|
105
|
+
this.options = options ?? {};
|
|
106
|
+
}
|
|
107
|
+
static fromURL(url, options) {
|
|
108
|
+
return new PagePocket({ kind: "url", url }, options);
|
|
109
|
+
}
|
|
110
|
+
static fromPuppeteerPage(page, options) {
|
|
111
|
+
return new PagePocket({ kind: "puppeteer-page", page }, options);
|
|
112
|
+
}
|
|
113
|
+
static fromCDPTab(tabId, options) {
|
|
114
|
+
return new PagePocket({ kind: "cdp-tab", tabId }, options);
|
|
115
|
+
}
|
|
116
|
+
static fromHTMLString(htmlString, options) {
|
|
117
|
+
const { baseUrl, url, ...rest } = options;
|
|
118
|
+
return new PagePocket({ kind: "html", htmlString, baseUrl, ...(url ? { url } : {}) }, rest);
|
|
119
|
+
}
|
|
120
|
+
interceptedRequestEvents() {
|
|
121
|
+
return this.eventStream.subscribe();
|
|
122
|
+
}
|
|
123
|
+
/** @internal */
|
|
124
|
+
_emitNetworkEvent(event) {
|
|
125
|
+
this.eventStream.emit(event);
|
|
126
|
+
}
|
|
127
|
+
/** @internal */
|
|
128
|
+
_closeNetworkEventStream() {
|
|
129
|
+
this.eventStream.close();
|
|
130
|
+
}
|
|
131
|
+
static fromDocument(doc, options) {
|
|
132
|
+
const serialize = options.serialize ??
|
|
133
|
+
((value) => {
|
|
134
|
+
if (value && typeof value === "object" && "documentElement" in value) {
|
|
135
|
+
const el = value.documentElement;
|
|
136
|
+
if (el && typeof el.outerHTML === "string") {
|
|
137
|
+
return el.outerHTML;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
throw new Error("fromDocument requires options.serialize(doc) or doc.documentElement.outerHTML");
|
|
141
|
+
});
|
|
142
|
+
const htmlString = serialize(doc);
|
|
143
|
+
const { baseUrl, url, serialize: _serialize, ...rest } = options;
|
|
144
|
+
return new PagePocket({ kind: "html", htmlString, baseUrl, ...(url ? { url } : {}) }, rest);
|
|
145
|
+
}
|
|
146
|
+
async capture(options) {
|
|
147
|
+
return (0, runner_1.captureWithPlugins)({
|
|
148
|
+
pocket: this,
|
|
149
|
+
pocketOptions: this.options,
|
|
150
|
+
target: this.target,
|
|
151
|
+
options
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.PagePocket = PagePocket;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type CaptureTarget = {
|
|
2
|
+
kind: "url";
|
|
3
|
+
url: string;
|
|
4
|
+
} | {
|
|
5
|
+
kind: "puppeteer-page";
|
|
6
|
+
page: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
kind: "cdp-tab";
|
|
9
|
+
tabId: number;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "html";
|
|
12
|
+
htmlString: string;
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
url?: string;
|
|
15
|
+
};
|
|
16
|
+
import type { PagePocketOptions } from "../types.js";
|
|
17
|
+
import type { CaptureResult as PagePocketCaptureResult, Plugin as V3Plugin, Unit as V3Unit } from "../units/contracts-bridge.js";
|
|
18
|
+
export declare class PagePocket {
|
|
19
|
+
private target;
|
|
20
|
+
private options;
|
|
21
|
+
private constructor();
|
|
22
|
+
static fromURL(url: string, options?: PagePocketOptions): PagePocket;
|
|
23
|
+
static fromPuppeteerPage(page: unknown, options?: PagePocketOptions): PagePocket;
|
|
24
|
+
static fromCDPTab(tabId: number, options?: PagePocketOptions): PagePocket;
|
|
25
|
+
static fromHTMLString(htmlString: string, options: {
|
|
26
|
+
baseUrl: string;
|
|
27
|
+
url?: string;
|
|
28
|
+
} & PagePocketOptions): PagePocket;
|
|
29
|
+
static fromDocument(doc: unknown, options: {
|
|
30
|
+
baseUrl: string;
|
|
31
|
+
url?: string;
|
|
32
|
+
serialize?: (doc: unknown) => string;
|
|
33
|
+
} & PagePocketOptions): PagePocket;
|
|
34
|
+
capture(options: {
|
|
35
|
+
units: V3Unit[];
|
|
36
|
+
plugins?: V3Plugin[];
|
|
37
|
+
} & import("../units/types.js").CaptureOptions): Promise<PagePocketCaptureResult>;
|
|
38
|
+
}
|