@parhelia/capture 0.0.0-stage → 0.4.12893
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 +83 -2
- package/dist/browserHost.d.ts +19 -0
- package/dist/browserHost.d.ts.map +1 -0
- package/dist/browserHost.js +247 -0
- package/dist/browserHostLink.d.ts +50 -0
- package/dist/browserHostLink.d.ts.map +1 -0
- package/dist/browserHostLink.js +193 -0
- package/dist/browserHostProtocol.d.ts +61 -0
- package/dist/browserHostProtocol.d.ts.map +1 -0
- package/dist/browserHostProtocol.js +29 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +239 -0
- package/dist/cmsJob.d.ts +38 -0
- package/dist/cmsJob.d.ts.map +1 -0
- package/dist/cmsJob.js +218 -0
- package/dist/egressProxy.d.ts +59 -0
- package/dist/egressProxy.d.ts.map +1 -0
- package/dist/egressProxy.js +205 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/install/doctor.d.ts +31 -0
- package/dist/install/doctor.d.ts.map +1 -0
- package/dist/install/doctor.js +189 -0
- package/dist/install/install.d.ts +72 -0
- package/dist/install/install.d.ts.map +1 -0
- package/dist/install/install.js +267 -0
- package/dist/install/layout.d.ts +81 -0
- package/dist/install/layout.d.ts.map +1 -0
- package/dist/install/layout.js +77 -0
- package/dist/install/services.d.ts +16 -0
- package/dist/install/services.d.ts.map +1 -0
- package/dist/install/services.js +94 -0
- package/dist/install/sys.d.ts +91 -0
- package/dist/install/sys.d.ts.map +1 -0
- package/dist/install/sys.js +260 -0
- package/dist/install/units.d.ts +57 -0
- package/dist/install/units.d.ts.map +1 -0
- package/dist/install/units.js +244 -0
- package/dist/install/updater.d.ts +66 -0
- package/dist/install/updater.d.ts.map +1 -0
- package/dist/install/updater.js +111 -0
- package/dist/install/versions.d.ts +61 -0
- package/dist/install/versions.d.ts.map +1 -0
- package/dist/install/versions.js +204 -0
- package/dist/isolation.d.ts +76 -0
- package/dist/isolation.d.ts.map +1 -0
- package/dist/isolation.js +163 -0
- package/dist/parheliaClient.d.ts +97 -0
- package/dist/parheliaClient.d.ts.map +1 -0
- package/dist/parheliaClient.js +111 -0
- package/dist/version.d.ts +13 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +36 -0
- package/dist/webIsolation.d.ts +24 -0
- package/dist/webIsolation.d.ts.map +1 -0
- package/dist/webIsolation.js +112 -0
- package/dist/webJob.d.ts +56 -0
- package/dist/webJob.d.ts.map +1 -0
- package/dist/webJob.js +177 -0
- package/dist/worker.d.ts +53 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +213 -0
- package/package.json +28 -4
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type Browser } from "playwright-core";
|
|
2
|
+
import type { BrowserHostLink, EgressPolicy } from "./browserHostLink.js";
|
|
3
|
+
import type { EgressLogEntry } from "./egressProxy.js";
|
|
4
|
+
import type { IsolationReport } from "./isolation.js";
|
|
5
|
+
import { type CapturePollAnswer } from "./parheliaClient.js";
|
|
6
|
+
import type { InstallRecord } from "./install/layout.js";
|
|
7
|
+
import { type WebIsolationOptions } from "./webIsolation.js";
|
|
8
|
+
export declare const WEB_CAPABILITY = "public-web";
|
|
9
|
+
export type WebProfileOptions = {
|
|
10
|
+
link: BrowserHostLink;
|
|
11
|
+
/** The self-test's options (probe URL, public URL); the client and link are the worker's. */
|
|
12
|
+
isolation?: Omit<WebIsolationOptions, "client" | "link">;
|
|
13
|
+
/** Replaces the self-test (tests of the job path only; the CLI never sets it). */
|
|
14
|
+
verify?: () => Promise<IsolationReport>;
|
|
15
|
+
reverifyMs?: number;
|
|
16
|
+
/** Test seams of the job's egress proxy (the SSRF fixtures); the decision itself is never replaced. */
|
|
17
|
+
egressSeams?: Pick<EgressPolicy, "resolve" | "connectTo">;
|
|
18
|
+
egressLog?: (entry: EgressLogEntry) => void;
|
|
19
|
+
onStatus?: (report: IsolationReport) => void;
|
|
20
|
+
};
|
|
21
|
+
export type WorkerOptions = {
|
|
22
|
+
origin: string;
|
|
23
|
+
key: string;
|
|
24
|
+
version: string;
|
|
25
|
+
/** Job kinds this worker offers besides `public-web` (default `cms`). */
|
|
26
|
+
capabilities?: string[];
|
|
27
|
+
/** The public-web profile: the browser host link and its self-test. Without it the worker offers no `public-web`. */
|
|
28
|
+
web?: WebProfileOptions;
|
|
29
|
+
maxConcurrentJobs?: number;
|
|
30
|
+
pollWaitMs?: number;
|
|
31
|
+
/** Launches the job's browser with the egress proxy's flags (default: playwright-core's Chromium, sandbox on). */
|
|
32
|
+
launch?: (args: string[]) => Promise<Browser>;
|
|
33
|
+
log?: (line: Record<string, unknown>) => void;
|
|
34
|
+
fetch?: typeof fetch;
|
|
35
|
+
/** CS6: an installed sidecar's record (browser revision and release date) and the files it shares with status and the updater. */
|
|
36
|
+
install?: {
|
|
37
|
+
record?: InstallRecord;
|
|
38
|
+
statusFile?: string;
|
|
39
|
+
updaterStatusFile?: string;
|
|
40
|
+
};
|
|
41
|
+
now?: () => number;
|
|
42
|
+
};
|
|
43
|
+
/** CS6: why public-web stays off whatever the self-test says: below the host's security minimum, or a browser past its age. */
|
|
44
|
+
export declare function stalenessOf(version: string, record: InstallRecord | undefined, answer: Pick<CapturePollAnswer, "securityMinimum" | "browserMaxAgeDays">, now: number): string | undefined;
|
|
45
|
+
export type RunningWorker = {
|
|
46
|
+
stop(): Promise<void>;
|
|
47
|
+
done: Promise<void>;
|
|
48
|
+
webStatus(): IsolationReport | undefined;
|
|
49
|
+
};
|
|
50
|
+
/** The default browser: the sidecar's own Chromium build with its sandbox (CS0 amendment A5: never without it). */
|
|
51
|
+
export declare function defaultLaunch(executablePath?: string): (args: string[]) => Promise<Browser>;
|
|
52
|
+
export declare function startWorker(options: WorkerOptions): RunningWorker;
|
|
53
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @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4/CS5w: the worker loop. Long-polls Parhelia outbound (held up to 25 s by the host), runs each claimed `cms`
|
|
3
|
+
* job in its own browser and hands each `public-web` job to the isolated browser host behind that job's egress proxy,
|
|
4
|
+
* abandons the attempts the host names cancelled, and answers every job it finished with `complete`. It offers `public-web`
|
|
5
|
+
* only while the browser host is connected and the isolation self-test passed (re-run when the host reconnects and hourly).
|
|
6
|
+
* A failed poll backs off; a refused key stops the worker (a revoked pairing is not retried forever).
|
|
7
|
+
*/
|
|
8
|
+
import { chromium } from "playwright-core";
|
|
9
|
+
import { runCmsJob } from "./cmsJob.js";
|
|
10
|
+
import { ParheliaClient, ParheliaRefusedError, SSO_FRONT_CODE } from "./parheliaClient.js";
|
|
11
|
+
import { compareVersions } from "./version.js";
|
|
12
|
+
import { writeFileSync, readFileSync, renameSync } from "node:fs";
|
|
13
|
+
import { verifyWebIsolation, webDenyAddresses } from "./webIsolation.js";
|
|
14
|
+
export const WEB_CAPABILITY = "public-web";
|
|
15
|
+
/** CS6: why public-web stays off whatever the self-test says: below the host's security minimum, or a browser past its age. */
|
|
16
|
+
export function stalenessOf(version, record, answer, now) {
|
|
17
|
+
if (answer.securityMinimum && compareVersions(version, answer.securityMinimum) < 0)
|
|
18
|
+
return `capture-web-outdated: sidecar ${version} is below the security minimum ${answer.securityMinimum}; screenshots of public websites stay off until it updates.`;
|
|
19
|
+
const released = record?.browserReleasedUtc ? Date.parse(record.browserReleasedUtc) : NaN;
|
|
20
|
+
if (answer.browserMaxAgeDays && Number.isFinite(released) && now - released > answer.browserMaxAgeDays * 86_400_000)
|
|
21
|
+
return `capture-web-browser-old: the browser (revision ${record?.browserRevision ?? "?"}) is older than ${answer.browserMaxAgeDays} days; screenshots of public websites stay off until it updates.`;
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
/** The default browser: the sidecar's own Chromium build with its sandbox (CS0 amendment A5: never without it). */
|
|
25
|
+
export function defaultLaunch(executablePath) {
|
|
26
|
+
return (args) => chromium.launch({ headless: true, chromiumSandbox: true, args, ...(executablePath ? { executablePath } : {}) });
|
|
27
|
+
}
|
|
28
|
+
export function startWorker(options) {
|
|
29
|
+
const log = options.log ?? ((line) => console.log(JSON.stringify({ at: new Date().toISOString(), ...line })));
|
|
30
|
+
const client = new ParheliaClient({ origin: options.origin, key: options.key, version: options.version, fetch: options.fetch });
|
|
31
|
+
const baseCapabilities = (options.capabilities ?? ["cms"]).filter((capability) => capability !== WEB_CAPABILITY);
|
|
32
|
+
let webReport;
|
|
33
|
+
const now = options.now ?? Date.now;
|
|
34
|
+
let staleness;
|
|
35
|
+
let hostRefusal;
|
|
36
|
+
const webReady = () => !!options.web && !!webReport?.ok && !!options.web.link.host && !staleness;
|
|
37
|
+
const startedUtc = new Date(now()).toISOString();
|
|
38
|
+
const report = () => {
|
|
39
|
+
const problems = [];
|
|
40
|
+
const updater = readJsonFile(options.install?.updaterStatusFile);
|
|
41
|
+
problems.push(...(updater?.problems ?? []));
|
|
42
|
+
if (hostRefusal)
|
|
43
|
+
problems.push(hostRefusal);
|
|
44
|
+
const webOff = !options.web ? undefined : staleness ?? (webReport && !webReport.ok ? `${webReport.code}: ${webReport.reason}` : undefined);
|
|
45
|
+
return { browserRevision: options.install?.record?.browserRevision, browserReleasedUtc: options.install?.record?.browserReleasedUtc,
|
|
46
|
+
problems: problems.slice(0, 8), ...(webOff ? { webOffReason: webOff } : {}) };
|
|
47
|
+
};
|
|
48
|
+
const writeStatus = (poll) => {
|
|
49
|
+
const file = options.install?.statusFile;
|
|
50
|
+
if (!file)
|
|
51
|
+
return;
|
|
52
|
+
try {
|
|
53
|
+
const status = { version: options.version, pid: process.pid, startedUtc, lastPollUtc: new Date(now()).toISOString(), lastPollOk: poll.ok,
|
|
54
|
+
...(poll.error ? { lastPollError: poll.error } : {}),
|
|
55
|
+
web: options.web ? { ok: webReady(), ...(webReady() ? {} : { reason: staleness ?? webReport?.reason ?? "not verified yet" }) } : null };
|
|
56
|
+
writeFileSync(file + ".tmp", JSON.stringify(status, null, 2) + "\n", { mode: 0o640 });
|
|
57
|
+
renameSync(file + ".tmp", file);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
log({ event: "status-write-failed", error: String(error) });
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const capabilities = () => (webReady() ? [...baseCapabilities, WEB_CAPABILITY] : baseCapabilities);
|
|
64
|
+
const maxJobs = Math.max(1, options.maxConcurrentJobs ?? 2);
|
|
65
|
+
const launch = options.launch ?? defaultLaunch();
|
|
66
|
+
const stopping = new AbortController();
|
|
67
|
+
const running = new Map();
|
|
68
|
+
let bridge;
|
|
69
|
+
const bridgeScript = () => (bridge ??= client.bridge().catch((error) => {
|
|
70
|
+
bridge = undefined;
|
|
71
|
+
throw error;
|
|
72
|
+
}));
|
|
73
|
+
async function runJob(offer) {
|
|
74
|
+
const abort = new AbortController();
|
|
75
|
+
const done = (async () => {
|
|
76
|
+
const started = Date.now();
|
|
77
|
+
// The coordinate only: the preview URL may carry a one-time preview code, and the cookie is a credential.
|
|
78
|
+
log({ event: "job-start", job: offer.jobId, attempt: offer.attemptId, dialogType: offer.dialogType, target: offer.target ?? null });
|
|
79
|
+
let outcome;
|
|
80
|
+
const signal = AbortSignal.any([abort.signal, stopping.signal]);
|
|
81
|
+
if (offer.kind === "cms")
|
|
82
|
+
outcome = await runCmsJob(offer, { origin: client.origin, launch, bridgeScript, signal, log });
|
|
83
|
+
else if (offer.kind === WEB_CAPABILITY && options.web && webReady())
|
|
84
|
+
outcome = await runWeb(offer, options.web, signal);
|
|
85
|
+
else if (offer.kind === WEB_CAPABILITY)
|
|
86
|
+
outcome = { kind: "failed", errorCode: "capture-web-unavailable", message: webReport?.reason ?? "This worker's public-web profile is not ready." };
|
|
87
|
+
else
|
|
88
|
+
outcome = { kind: "failed", errorCode: "capture-kind-unsupported", message: `This worker runs no '${offer.kind}' jobs.` };
|
|
89
|
+
log({ event: "job", job: offer.jobId, attempt: offer.attemptId, outcome: outcome.kind,
|
|
90
|
+
...(outcome.kind === "failed" ? { errorCode: outcome.errorCode } : {}), ms: Date.now() - started });
|
|
91
|
+
if (outcome.kind === "cancelled")
|
|
92
|
+
return;
|
|
93
|
+
try {
|
|
94
|
+
const answer = outcome.kind === "result"
|
|
95
|
+
? await client.complete(offer.jobId, offer.attemptId, outcome.result)
|
|
96
|
+
: await client.complete(offer.jobId, offer.attemptId, { success: false, scope: "page", errorCode: outcome.errorCode,
|
|
97
|
+
error: outcome.message }, outcome.message);
|
|
98
|
+
log({ event: "completed", job: offer.jobId, status: answer.status });
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
log({ event: "complete-failed", job: offer.jobId, error: String(error) });
|
|
102
|
+
}
|
|
103
|
+
})().finally(() => running.delete(offer.attemptId));
|
|
104
|
+
running.set(offer.attemptId, { abort, done });
|
|
105
|
+
}
|
|
106
|
+
async function runWeb(offer, web, signal) {
|
|
107
|
+
// The worker trusts no allowlist for a public page: nothing passes the address check, and Parhelia's and this machine's
|
|
108
|
+
// own addresses are refused whatever range they are in.
|
|
109
|
+
const policy = {
|
|
110
|
+
blockedRanges: offer.blockedRanges ?? [],
|
|
111
|
+
denyAddresses: await webDenyAddresses(client.origin, { resolve: web.egressSeams?.resolve }),
|
|
112
|
+
...web.egressSeams,
|
|
113
|
+
};
|
|
114
|
+
const outcome = await web.link.runWebJob(offer.attemptId, offer.parameters, offer.deadlineUnixMs, policy, signal, (entry) => {
|
|
115
|
+
// Hosts only: a public page's own URLs are the person's business, not the log's.
|
|
116
|
+
if (!entry.ok)
|
|
117
|
+
log({ event: "egress-refused", job: offer.jobId, host: entry.host, port: entry.port, reason: entry.reason });
|
|
118
|
+
web.egressLog?.(entry);
|
|
119
|
+
});
|
|
120
|
+
return outcome;
|
|
121
|
+
}
|
|
122
|
+
let verifying;
|
|
123
|
+
const verifyWeb = () => (verifying ??= (async () => {
|
|
124
|
+
const web = options.web;
|
|
125
|
+
try {
|
|
126
|
+
webReport = web.verify ? await web.verify() : await verifyWebIsolation({ ...web.isolation, client, link: web.link });
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
webReport = { ok: false, code: "capture-web-isolation-unproven", reason: String(error), checks: [] };
|
|
130
|
+
}
|
|
131
|
+
log({ event: "web-profile", ok: webReport.ok, ...(webReport.ok ? {} : { code: webReport.code, reason: webReport.reason }) });
|
|
132
|
+
web.onStatus?.(webReport);
|
|
133
|
+
})().finally(() => (verifying = undefined)));
|
|
134
|
+
let reverify;
|
|
135
|
+
if (options.web) {
|
|
136
|
+
// A (re)connected browser host is a new process: nothing it ran before vouches for it.
|
|
137
|
+
options.web.link.onConnect(() => {
|
|
138
|
+
webReport = undefined;
|
|
139
|
+
void verifyWeb();
|
|
140
|
+
});
|
|
141
|
+
if (options.web.link.host)
|
|
142
|
+
void verifyWeb();
|
|
143
|
+
reverify = setInterval(() => void verifyWeb(), options.web.reverifyMs ?? 60 * 60_000);
|
|
144
|
+
reverify.unref?.();
|
|
145
|
+
}
|
|
146
|
+
const done = (async () => {
|
|
147
|
+
let backoff = 1_000;
|
|
148
|
+
while (!stopping.signal.aborted) {
|
|
149
|
+
try {
|
|
150
|
+
// A busy worker still polls (without claiming more than it can run): the poll names cancelled attempts.
|
|
151
|
+
const room = running.size < maxJobs;
|
|
152
|
+
const answer = await client.poll(room ? capabilities() : [], room ? options.pollWaitMs ?? 25_000 : 1_000, stopping.signal, report());
|
|
153
|
+
backoff = 1_000;
|
|
154
|
+
const stale = options.web ? stalenessOf(options.version, options.install?.record, answer, now()) : undefined;
|
|
155
|
+
if (stale !== staleness)
|
|
156
|
+
log({ event: "web-staleness", reason: stale ?? null });
|
|
157
|
+
staleness = stale;
|
|
158
|
+
hostRefusal = answer.webRefusal;
|
|
159
|
+
writeStatus({ ok: true });
|
|
160
|
+
for (const attempt of answer.cancelledAttempts)
|
|
161
|
+
running.get(attempt)?.abort.abort();
|
|
162
|
+
for (const offer of answer.jobs)
|
|
163
|
+
void runJob(offer);
|
|
164
|
+
if (!room)
|
|
165
|
+
await sleep(500, stopping.signal);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (stopping.signal.aborted)
|
|
169
|
+
break;
|
|
170
|
+
// Only Parhelia's own refusal ends the worker (a revoked pairing is not retried forever). A refusal from an SSO proxy in
|
|
171
|
+
// front of it is named and retried: a fixed --origin or proxy rule heals it without a restart.
|
|
172
|
+
if (error instanceof ParheliaRefusedError && error.status === 401 && error.code !== SSO_FRONT_CODE) {
|
|
173
|
+
log({ event: "stopped", reason: "the worker key was refused (revoked or unknown): pair again" });
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
log({ event: "poll-failed", error: error instanceof Error ? error.message : String(error), retryInMs: backoff });
|
|
177
|
+
writeStatus({ ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
178
|
+
await sleep(backoff, stopping.signal);
|
|
179
|
+
backoff = Math.min(backoff * 2, 30_000);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
await Promise.allSettled([...running.values()].map((job) => job.done));
|
|
183
|
+
if (reverify)
|
|
184
|
+
clearInterval(reverify);
|
|
185
|
+
})();
|
|
186
|
+
return {
|
|
187
|
+
done,
|
|
188
|
+
webStatus: () => webReport,
|
|
189
|
+
async stop() {
|
|
190
|
+
stopping.abort();
|
|
191
|
+
await done;
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function readJsonFile(file) {
|
|
196
|
+
if (!file)
|
|
197
|
+
return undefined;
|
|
198
|
+
try {
|
|
199
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function sleep(ms, signal) {
|
|
206
|
+
return new Promise((resolve) => {
|
|
207
|
+
const timer = setTimeout(resolve, ms);
|
|
208
|
+
signal.addEventListener("abort", () => {
|
|
209
|
+
clearTimeout(timer);
|
|
210
|
+
resolve();
|
|
211
|
+
}, { once: true });
|
|
212
|
+
});
|
|
213
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parhelia/capture",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.12893",
|
|
4
|
+
"description": "Parhelia's capture sidecar: real Chromium screenshots of CMS pages without an open editor. Install with `npx @parhelia/capture install`.",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"bin": {
|
|
10
|
+
"parhelia-capture": "./dist/cli.js"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"playwright-core": "1.62.1"
|
|
29
|
+
}
|
|
30
|
+
}
|