@shotkit/shotium 0.0.1 → 0.2.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 +168 -1
- package/dist/daemon_main.d.ts +1 -0
- package/dist/daemon_main.js +305 -0
- package/dist/daemon_main.js.map +1 -0
- package/dist/engine-Xe7nH-1i.js +267 -0
- package/dist/engine-Xe7nH-1i.js.map +1 -0
- package/dist/index.d.ts +268 -0
- package/dist/index.js +355 -0
- package/dist/index.js.map +1 -0
- package/native/binding.cc +283 -0
- package/native/binding.gyp +54 -0
- package/native/stage_header.js +53 -0
- package/package.json +56 -3
- package/src/daemon_main.ts +76 -0
- package/src/index.ts +139 -0
- package/src/lib/binding.ts +89 -0
- package/src/lib/client.ts +373 -0
- package/src/lib/config.ts +31 -0
- package/src/lib/daemon.ts +382 -0
- package/src/lib/endpoint.ts +70 -0
- package/src/lib/engine.ts +168 -0
- package/src/lib/platform.ts +69 -0
- package/src/lib/protocol.ts +53 -0
- package/src/lib/request.ts +97 -0
- package/src/types.ts +143 -0
package/README.md
CHANGED
|
@@ -1,3 +1,170 @@
|
|
|
1
1
|
# @shotkit/shotium
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> High-performance static HTML/CSS screenshot engine powered by a stripped Chromium Blink core.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/sj817/shotium/blob/main/LICENSE)
|
|
6
|
+
[](https://www.npmjs.com/package/@shotkit/shotium)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
`@shotkit/shotium` provides Node.js / TypeScript bindings for **shotium**, a stripped-down Chromium engine built specifically for fast static page rendering. By completely removing V8 and browser chrome overhead, Shotium delivers cold starts under 350 ms, single-shot captures in ~47 ms, and an idle memory footprint of ~58 MB.
|
|
13
|
+
|
|
14
|
+
The engine is loaded into your own process as a Node-API addon over a C ABI. Nothing is spawned, no image crosses a process boundary, and `screenshot()` returns the bytes Blink just encoded.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import shotium from '@shotkit/shotium';
|
|
18
|
+
|
|
19
|
+
shotium.runtime.start();
|
|
20
|
+
|
|
21
|
+
const png = await shotium.screenshot({
|
|
22
|
+
file: 'https://example.com',
|
|
23
|
+
viewport: { width: 1280, height: 720 },
|
|
24
|
+
fullPage: true,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await shotium.runtime.stop();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install @shotkit/shotium
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Prebuilt platform binaries are installed automatically via npm optional dependencies — six of them, covering Windows, macOS and Linux on x64 and arm64. There is no build step and no postinstall download.
|
|
39
|
+
|
|
40
|
+
The package is ESM. `import` works on Node 18 and up; `require()` of it needs Node 22.12 or 20.19, and anything older should use `await import('@shotkit/shotium')`.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
### 1. In-Process Engine (`runtime`)
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { runtime, screenshot } from '@shotkit/shotium';
|
|
50
|
+
|
|
51
|
+
runtime.start({
|
|
52
|
+
cacheDir: '/var/tmp/shotium-cache' // Optional HTTP disk cache. Default: null (off)
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Returns a Buffer, or null when `path` was given and the engine wrote the file
|
|
56
|
+
const buffer = await screenshot({
|
|
57
|
+
file: 'https://example.com',
|
|
58
|
+
viewport: { width: 1280, height: 720 },
|
|
59
|
+
type: 'webp',
|
|
60
|
+
quality: 85,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Hand memory back between batches without giving up the engine
|
|
64
|
+
runtime.purge({ releaseWorkingSet: true });
|
|
65
|
+
|
|
66
|
+
await runtime.stop();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**One engine per process, ever, and not one at a time.** Starting Blink writes process-wide statics it has no path to undo, so `stop()` is final: a `start()` after it throws, and so does a second `Runtime`. Concurrent callers are queued and served one at a time, because there is one renderer. Parallelism is therefore more processes, and a program that will want another screenshot later should stay started and call `purge()` rather than stopping.
|
|
70
|
+
|
|
71
|
+
#### `StartOptions`
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
interface StartOptions {
|
|
75
|
+
/** Root of the HTTP disk cache. null (the default) disables caching. */
|
|
76
|
+
cacheDir?: string | null;
|
|
77
|
+
|
|
78
|
+
/** User-Agent sent with every request. */
|
|
79
|
+
userAgent?: string;
|
|
80
|
+
|
|
81
|
+
/** Where the engine looks for its resource packs. Defaults to the
|
|
82
|
+
* directory the addon was loaded from, which is right for an install. */
|
|
83
|
+
resourceDir?: string;
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
### 2. Resident Daemon (`daemon`)
|
|
90
|
+
|
|
91
|
+
Recommended for CLI tools, ephemeral CI tasks, or serverless workers where startup latency is critical.
|
|
92
|
+
|
|
93
|
+
The daemon is the same engine in a process of its own, behind a local socket (Named Pipe on Windows, Unix domain socket on POSIX). It renders a blank page on start, so it is warm before the first real request arrives.
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { daemon } from '@shotkit/shotium';
|
|
97
|
+
|
|
98
|
+
// Connect to an existing daemon (automatically starts one if none is running)
|
|
99
|
+
const client = await daemon.connect();
|
|
100
|
+
|
|
101
|
+
const png = await client.screenshot({
|
|
102
|
+
file: 'https://example.com',
|
|
103
|
+
viewport: { width: 1280, height: 720 },
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
client.close();
|
|
107
|
+
|
|
108
|
+
// Check status or stop the daemon
|
|
109
|
+
const status = await daemon.status(); // { running: true, pid: 12345, warm: true, ... }
|
|
110
|
+
await daemon.stop();
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
One connection may have several requests outstanding, because every message carries an `id`. That is a convenience for the client rather than concurrency: the daemon holds one renderer too, and answers in the order it finished them. Two at once means two daemons, told apart by `name`.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## API Reference
|
|
118
|
+
|
|
119
|
+
### `ScreenshotOptions`
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
interface ScreenshotOptions {
|
|
123
|
+
/** Target URL (http/https/file) or local file path */
|
|
124
|
+
file: string;
|
|
125
|
+
|
|
126
|
+
/** Output format (default: 'png') */
|
|
127
|
+
type?: 'png' | 'jpeg' | 'webp';
|
|
128
|
+
|
|
129
|
+
/** Viewport dimensions (default: 1280x720) */
|
|
130
|
+
viewport?: { width?: number; height?: number };
|
|
131
|
+
|
|
132
|
+
/** Capture full scrollable document */
|
|
133
|
+
fullPage?: boolean;
|
|
134
|
+
|
|
135
|
+
/** Capture element bounding box matching selector */
|
|
136
|
+
selector?: string;
|
|
137
|
+
|
|
138
|
+
/** Capture specific rectangular crop */
|
|
139
|
+
clip?: { x: number; y: number; width: number; height: number };
|
|
140
|
+
|
|
141
|
+
/** Image compression quality: 1-100 (jpeg and webp only, default: 90) */
|
|
142
|
+
quality?: number;
|
|
143
|
+
|
|
144
|
+
/** Device scale factor: 0.01 - 8.0 (default: 1.0) */
|
|
145
|
+
scale?: number;
|
|
146
|
+
|
|
147
|
+
/** Preserve transparent background (png/webp only) */
|
|
148
|
+
omitBackground?: boolean;
|
|
149
|
+
|
|
150
|
+
/** Output file destination path (returns null if specified) */
|
|
151
|
+
path?: string;
|
|
152
|
+
|
|
153
|
+
/** Navigation & wait options */
|
|
154
|
+
pageGotoParams?: {
|
|
155
|
+
timeout?: number;
|
|
156
|
+
waitUntil?: 'load' | 'networkidle';
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/** Allow document to access local file:// resources (default: false) */
|
|
160
|
+
allowFileAccess?: boolean;
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
An option this interface does not list is a typo, and a typo that was quietly dropped is a screenshot that ignored what you asked for — so an unknown key is a `TypeError` rather than a silent no-op. `fullPage`, `selector` and `clip` are mutually exclusive.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
BSD-3-Clause. See [LICENSE](https://github.com/sj817/shotium/blob/main/LICENSE) for details.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { a as encodeFrame, i as FrameReader, o as endpointFor, s as resolveStartOptions, t as Engine } from "./engine-Xe7nH-1i.js";
|
|
2
|
+
import { EventEmitter } from "node:events";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import net from "node:net";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
|
|
8
|
+
//#region src/lib/daemon.ts
|
|
9
|
+
const VERSION = (() => {
|
|
10
|
+
try {
|
|
11
|
+
const manifest = fs.readFileSync(new URL("../package.json", import.meta.url), "utf8");
|
|
12
|
+
return JSON.parse(manifest).version ?? "0.0.0";
|
|
13
|
+
} catch {
|
|
14
|
+
return "0.0.0";
|
|
15
|
+
}
|
|
16
|
+
})();
|
|
17
|
+
const DEFAULT_IDLE_TIMEOUT_MS = 3e5;
|
|
18
|
+
var Daemon = class extends EventEmitter {
|
|
19
|
+
options;
|
|
20
|
+
endpointPath;
|
|
21
|
+
idleTimeoutMs;
|
|
22
|
+
prewarmOnStart;
|
|
23
|
+
engine = new Engine();
|
|
24
|
+
server = null;
|
|
25
|
+
sockets = /* @__PURE__ */ new Set();
|
|
26
|
+
inFlight = 0;
|
|
27
|
+
served = 0;
|
|
28
|
+
warmed = false;
|
|
29
|
+
startedAt = Date.now();
|
|
30
|
+
idleTimer = null;
|
|
31
|
+
closing = false;
|
|
32
|
+
constructor(options = {}) {
|
|
33
|
+
super();
|
|
34
|
+
this.options = resolveStartOptions(options);
|
|
35
|
+
this.endpointPath = endpointFor({
|
|
36
|
+
...this.options,
|
|
37
|
+
name: options.name,
|
|
38
|
+
endpoint: options.endpoint
|
|
39
|
+
});
|
|
40
|
+
this.idleTimeoutMs = options.idleTimeoutMs === void 0 ? DEFAULT_IDLE_TIMEOUT_MS : options.idleTimeoutMs;
|
|
41
|
+
this.prewarmOnStart = options.prewarm !== false;
|
|
42
|
+
}
|
|
43
|
+
get endpoint() {
|
|
44
|
+
return this.endpointPath;
|
|
45
|
+
}
|
|
46
|
+
get warm() {
|
|
47
|
+
return this.warmed;
|
|
48
|
+
}
|
|
49
|
+
async listen() {
|
|
50
|
+
this.engine.start(this.options);
|
|
51
|
+
this.server = net.createServer((socket) => this.accept(socket));
|
|
52
|
+
this.server.on("error", (error) => this.emit("error", error));
|
|
53
|
+
await this.bind();
|
|
54
|
+
this.armIdleTimer();
|
|
55
|
+
this.emit("ready", { endpoint: this.endpointPath });
|
|
56
|
+
if (this.prewarmOnStart) await this.prewarm();
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
bind() {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
const server = this.server;
|
|
62
|
+
const onError = (error) => {
|
|
63
|
+
if (error.code === "EADDRINUSE" && process.platform !== "win32") {
|
|
64
|
+
const probe = net.connect(this.endpointPath);
|
|
65
|
+
probe.on("connect", () => {
|
|
66
|
+
probe.destroy();
|
|
67
|
+
reject(error);
|
|
68
|
+
});
|
|
69
|
+
probe.on("error", () => {
|
|
70
|
+
try {
|
|
71
|
+
fs.unlinkSync(this.endpointPath);
|
|
72
|
+
} catch {
|
|
73
|
+
reject(error);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
server.listen(this.endpointPath, () => {
|
|
77
|
+
this.restrict();
|
|
78
|
+
resolve();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
reject(error);
|
|
84
|
+
};
|
|
85
|
+
server.once("error", onError);
|
|
86
|
+
server.listen(this.endpointPath, () => {
|
|
87
|
+
server.removeListener("error", onError);
|
|
88
|
+
this.restrict();
|
|
89
|
+
resolve();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
restrict() {
|
|
94
|
+
if (process.platform === "win32") return;
|
|
95
|
+
try {
|
|
96
|
+
fs.chmodSync(this.endpointPath, 384);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
this.emit("error", error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async prewarm() {
|
|
102
|
+
const blank = path.join(os.tmpdir(), `shotium-prewarm-${process.pid}.html`);
|
|
103
|
+
try {
|
|
104
|
+
fs.writeFileSync(blank, "<!doctype html><title>shotium</title><p>shotium");
|
|
105
|
+
await this.engine.capture({
|
|
106
|
+
file: blank,
|
|
107
|
+
width: 16,
|
|
108
|
+
height: 16
|
|
109
|
+
});
|
|
110
|
+
this.warmed = true;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
this.emit("error", error);
|
|
113
|
+
} finally {
|
|
114
|
+
fs.rmSync(blank, { force: true });
|
|
115
|
+
}
|
|
116
|
+
this.emit("warm", { warm: this.warmed });
|
|
117
|
+
}
|
|
118
|
+
status() {
|
|
119
|
+
return {
|
|
120
|
+
ok: true,
|
|
121
|
+
pid: process.pid,
|
|
122
|
+
endpoint: this.endpointPath,
|
|
123
|
+
cacheDir: this.options.cacheDir,
|
|
124
|
+
userAgent: this.options.userAgent,
|
|
125
|
+
resourceDir: this.options.resourceDir,
|
|
126
|
+
warm: this.warmed,
|
|
127
|
+
uptimeMs: Date.now() - this.startedAt,
|
|
128
|
+
connections: this.sockets.size,
|
|
129
|
+
inFlight: this.inFlight,
|
|
130
|
+
served: this.served,
|
|
131
|
+
idleTimeoutMs: this.idleTimeoutMs,
|
|
132
|
+
version: VERSION
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
accept(socket) {
|
|
136
|
+
socket.on("error", () => socket.destroy());
|
|
137
|
+
this.sockets.add(socket);
|
|
138
|
+
this.armIdleTimer();
|
|
139
|
+
const reader = new FrameReader();
|
|
140
|
+
socket.on("data", (chunk) => {
|
|
141
|
+
reader.push(chunk);
|
|
142
|
+
for (;;) {
|
|
143
|
+
const frame = reader.next();
|
|
144
|
+
if (frame === null) return;
|
|
145
|
+
this.dispatch(socket, frame);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
socket.on("close", () => {
|
|
149
|
+
this.sockets.delete(socket);
|
|
150
|
+
this.armIdleTimer();
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
dispatch(socket, frame) {
|
|
154
|
+
let message;
|
|
155
|
+
try {
|
|
156
|
+
message = JSON.parse(frame.toString("utf8"));
|
|
157
|
+
} catch {
|
|
158
|
+
this.reply(socket, {
|
|
159
|
+
id: null,
|
|
160
|
+
ok: false,
|
|
161
|
+
error: "shotium: request is not JSON"
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const id = message.id === void 0 ? null : message.id;
|
|
166
|
+
const op = message.op || "screenshot";
|
|
167
|
+
if (op === "status") {
|
|
168
|
+
this.reply(socket, {
|
|
169
|
+
...this.status(),
|
|
170
|
+
id
|
|
171
|
+
});
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (op === "ping") {
|
|
175
|
+
this.reply(socket, {
|
|
176
|
+
id,
|
|
177
|
+
ok: true
|
|
178
|
+
});
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (op === "shutdown") {
|
|
182
|
+
this.reply(socket, {
|
|
183
|
+
id,
|
|
184
|
+
ok: true,
|
|
185
|
+
stopping: true
|
|
186
|
+
});
|
|
187
|
+
socket.end(() => void this.close());
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (op !== "screenshot") {
|
|
191
|
+
this.reply(socket, {
|
|
192
|
+
id,
|
|
193
|
+
ok: false,
|
|
194
|
+
error: `shotium: unknown op "${op}"`
|
|
195
|
+
});
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const request = message.request || {};
|
|
199
|
+
this.inFlight += 1;
|
|
200
|
+
this.armIdleTimer();
|
|
201
|
+
this.emit("request", {
|
|
202
|
+
id,
|
|
203
|
+
file: request.file
|
|
204
|
+
});
|
|
205
|
+
this.engine.capture(request).then((image) => {
|
|
206
|
+
this.served += 1;
|
|
207
|
+
this.reply(socket, {
|
|
208
|
+
id,
|
|
209
|
+
ok: true,
|
|
210
|
+
bytes: image ? image.length : 0,
|
|
211
|
+
path: request.path
|
|
212
|
+
}, image);
|
|
213
|
+
}).catch((error) => {
|
|
214
|
+
this.reply(socket, {
|
|
215
|
+
id,
|
|
216
|
+
ok: false,
|
|
217
|
+
error: String(error.message || error)
|
|
218
|
+
});
|
|
219
|
+
}).finally(() => {
|
|
220
|
+
this.inFlight -= 1;
|
|
221
|
+
this.emit("response", { id });
|
|
222
|
+
this.armIdleTimer();
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
reply(socket, header, payload) {
|
|
226
|
+
if (socket.destroyed) return;
|
|
227
|
+
socket.write(encodeFrame(Buffer.from(JSON.stringify(header), "utf8")));
|
|
228
|
+
socket.write(encodeFrame(payload || Buffer.alloc(0)));
|
|
229
|
+
}
|
|
230
|
+
armIdleTimer() {
|
|
231
|
+
if (this.idleTimer) {
|
|
232
|
+
clearTimeout(this.idleTimer);
|
|
233
|
+
this.idleTimer = null;
|
|
234
|
+
}
|
|
235
|
+
if (!this.idleTimeoutMs || this.closing) return;
|
|
236
|
+
if (this.sockets.size > 0 || this.inFlight > 0) return;
|
|
237
|
+
this.idleTimer = setTimeout(() => {
|
|
238
|
+
this.emit("idle-exit", { idleTimeoutMs: this.idleTimeoutMs });
|
|
239
|
+
this.close();
|
|
240
|
+
}, this.idleTimeoutMs);
|
|
241
|
+
this.idleTimer.unref();
|
|
242
|
+
}
|
|
243
|
+
async close() {
|
|
244
|
+
if (this.closing) return;
|
|
245
|
+
this.closing = true;
|
|
246
|
+
if (this.idleTimer) {
|
|
247
|
+
clearTimeout(this.idleTimer);
|
|
248
|
+
this.idleTimer = null;
|
|
249
|
+
}
|
|
250
|
+
for (const socket of this.sockets) socket.destroy();
|
|
251
|
+
this.sockets.clear();
|
|
252
|
+
await new Promise((resolve) => this.server.close(() => resolve()));
|
|
253
|
+
await this.engine.stop();
|
|
254
|
+
this.emit("close", {});
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/daemon_main.ts
|
|
260
|
+
async function main() {
|
|
261
|
+
const encoded = process.argv[2];
|
|
262
|
+
if (!encoded) {
|
|
263
|
+
process.stderr.write("shotium: daemon_main expects a base64 config\n");
|
|
264
|
+
process.exit(2);
|
|
265
|
+
}
|
|
266
|
+
const options = JSON.parse(Buffer.from(encoded, "base64").toString("utf8"));
|
|
267
|
+
const daemon = new Daemon(options);
|
|
268
|
+
daemon.on("stderr", ({ worker, line }) => {
|
|
269
|
+
process.stderr.write(`shotium worker ${worker}: ${line}\n`);
|
|
270
|
+
});
|
|
271
|
+
for (const event of [
|
|
272
|
+
"crash",
|
|
273
|
+
"timeout",
|
|
274
|
+
"worker-restart",
|
|
275
|
+
"worker-error",
|
|
276
|
+
"idle-exit"
|
|
277
|
+
]) daemon.on(event, (payload) => {
|
|
278
|
+
const detail = payload && payload.error ? {
|
|
279
|
+
...payload,
|
|
280
|
+
error: String(payload.error.message ?? payload.error)
|
|
281
|
+
} : payload;
|
|
282
|
+
process.stderr.write(`shotium daemon ${event}: ${JSON.stringify(detail)}\n`);
|
|
283
|
+
});
|
|
284
|
+
daemon.on("error", (error) => {
|
|
285
|
+
process.stderr.write(`shotium daemon error: ${error && error.message || error}\n`);
|
|
286
|
+
});
|
|
287
|
+
try {
|
|
288
|
+
await daemon.listen();
|
|
289
|
+
} catch (error) {
|
|
290
|
+
if (error?.code === "EADDRINUSE") process.exit(0);
|
|
291
|
+
process.stderr.write(`shotium: daemon failed to start: ${error}\n`);
|
|
292
|
+
process.exit(1);
|
|
293
|
+
}
|
|
294
|
+
const shutdown = () => {
|
|
295
|
+
daemon.close().then(() => process.exit(0), () => process.exit(1));
|
|
296
|
+
};
|
|
297
|
+
process.on("SIGINT", shutdown);
|
|
298
|
+
process.on("SIGTERM", shutdown);
|
|
299
|
+
daemon.on("close", () => process.exit(0));
|
|
300
|
+
}
|
|
301
|
+
main();
|
|
302
|
+
|
|
303
|
+
//#endregion
|
|
304
|
+
export { };
|
|
305
|
+
//# sourceMappingURL=daemon_main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daemon_main.js","names":[],"sources":["../src/lib/daemon.ts","../src/daemon_main.ts"],"sourcesContent":["import {EventEmitter} from 'node:events';\nimport fs from 'node:fs';\nimport net from 'node:net';\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport type {DaemonOptions, DaemonStatus} from '../types.js';\n\nimport {resolveStartOptions} from './config.js';\nimport type {ResolvedStartOptions} from './config.js';\nimport {endpointFor} from './endpoint.js';\nimport {Engine} from './engine.js';\nimport {FrameReader, encodeFrame} from './protocol.js';\nimport type {WireRequest} from './request.js';\n\n// Our own version, for status(). Read rather than imported: an import\n// attribute would do it too, but only on a node new enough that this package\n// would not run on the rest. The URL is relative to the built module, which\n// sits one directory below the manifest.\nconst VERSION = (() => {\n try {\n const manifest =\n fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8');\n return (JSON.parse(manifest) as {version?: string}).version ?? '0.0.0';\n } catch {\n return '0.0.0';\n }\n})();\n\nconst DEFAULT_IDLE_TIMEOUT_MS = 300000;\n\n// One message off the socket. `op` defaults to screenshot because that is what\n// almost every message is.\ninterface DaemonMessage {\n id?: number|null;\n op?: 'screenshot'|'status'|'ping'|'shutdown';\n request?: WireRequest;\n timeout?: number;\n retry?: number;\n}\n\ninterface DaemonReply {\n id: number|null;\n ok?: boolean;\n error?: string;\n bytes?: number;\n path?: string;\n stopping?: boolean;\n}\n\n// An engine that outlives the process that asked for it.\n//\n// The engine in index.ts is already resident, but only for as long as the Node\n// process holding it: a command-line invocation, a CI step, a serverless\n// handler and a `node -e` all pay for starting Blink and then throw it away.\n// This is the same engine behind a socket, so the second caller -- in a\n// different process, minutes later -- pays a connect() and nothing else.\n//\n// A request frame of JSON, answered by a header frame and a payload frame:\n//\n// -> [len][{\"id\":7,\"op\":\"screenshot\",\"request\":{...}}]\n// <- [len][{\"id\":7,\"ok\":true,\"bytes\":97756}] [len][<PNG>]\n//\n// `id` is on the wire so that a client may have several requests outstanding\n// on one connection. That is a convenience for the client, not concurrency:\n// there is one renderer here, because Blink is a process-wide singleton, so\n// the requests queue and come back in the order the engine finished them.\n// Wanting two at once means wanting two daemons, addressed by `name`.\n//\n// Nothing supervises a capture. The pool this replaced could time a worker out\n// and kill it; an in-process engine has no such seam -- there is no way to\n// abandon a render without abandoning the process. A page's own deadline\n// (`pageGotoParams.timeout`) is what bounds it, and the engine answers slow\n// pages by itself. `timeout` and `retry` on the wire are accepted and ignored,\n// so that an older client still talks to this.\n//\n// Events: ready, warm, request, response, idle-exit, error, close.\nclass Daemon extends EventEmitter {\n private readonly options: ResolvedStartOptions;\n private readonly endpointPath: string;\n private readonly idleTimeoutMs: number;\n private readonly prewarmOnStart: boolean;\n private readonly engine = new Engine();\n private server: net.Server|null = null;\n private sockets = new Set<net.Socket>();\n private inFlight = 0;\n private served = 0;\n private warmed = false;\n private startedAt = Date.now();\n private idleTimer: NodeJS.Timeout|null = null;\n private closing = false;\n\n constructor(options: DaemonOptions = {}) {\n super();\n this.options = resolveStartOptions(options);\n this.endpointPath = endpointFor({\n ...this.options,\n name: options.name,\n endpoint: options.endpoint,\n });\n this.idleTimeoutMs = options.idleTimeoutMs === undefined ?\n DEFAULT_IDLE_TIMEOUT_MS :\n options.idleTimeoutMs;\n this.prewarmOnStart = options.prewarm !== false;\n }\n\n get endpoint(): string {\n return this.endpointPath;\n }\n\n get warm(): boolean {\n return this.warmed;\n }\n\n // Brings the engine up and starts listening. The pipe existing *is* the\n // readiness signal -- a client's connect() either succeeds or the daemon is\n // not up -- so nothing is bound until the engine has started.\n //\n // Starting it here rather than on the first request is deliberate: a machine\n // with no engine for its platform should fail while the caller is still\n // watching, not answer a connect() and then reject every request on it.\n async listen(): Promise<this> {\n this.engine.start(this.options);\n\n this.server = net.createServer((socket) => this.accept(socket));\n this.server.on('error', (error) => this.emit('error', error));\n await this.bind();\n this.armIdleTimer();\n this.emit('ready', {endpoint: this.endpointPath});\n if (this.prewarmOnStart) {\n await this.prewarm();\n }\n return this;\n }\n\n private bind(): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n const server = this.server!;\n const onError = (error: NodeJS.ErrnoException) => {\n // A unix socket file outlives the process that made it, so EADDRINUSE\n // means either a live daemon or a leftover path. Connecting is the only\n // way to tell them apart: refused means nobody is home, and the file\n // can go.\n if (error.code === 'EADDRINUSE' && process.platform !== 'win32') {\n const probe = net.connect(this.endpointPath);\n probe.on('connect', () => {\n probe.destroy();\n reject(error);\n });\n probe.on('error', () => {\n try {\n fs.unlinkSync(this.endpointPath);\n } catch {\n reject(error);\n return;\n }\n server.listen(this.endpointPath, () => {\n this.restrict();\n resolve();\n });\n });\n return;\n }\n reject(error);\n };\n server.once('error', onError);\n server.listen(this.endpointPath, () => {\n server.removeListener('error', onError);\n this.restrict();\n resolve();\n });\n });\n }\n\n // Who may talk to this daemon.\n //\n // It matters because a request may set `allowFileAccess`, so a stranger who\n // can connect can have a document read this machine's filesystem and get the\n // result back as a picture. On POSIX the socket is a file and 0600 says only\n // its owner may connect.\n //\n // On Windows it is a named pipe, and node exposes no way to give one an ACL:\n // the default lets any account on the machine open it. A daemon on a shared\n // Windows host is therefore as trusted as the machine's users are -- use the\n // engine in your own process, where nothing is listening, if that is not\n // acceptable.\n private restrict(): void {\n if (process.platform === 'win32') {\n return;\n }\n try {\n fs.chmodSync(this.endpointPath, 0o600);\n } catch (error) {\n this.emit('error', error);\n }\n }\n\n // Renders one throwaway document so that the first real request does not pay\n // for whatever the engine initialises lazily. One is enough: there is one\n // renderer, and it is the same one every request lands on.\n //\n // A temporary file, not a `data:` URL. This used to send\n // `data:text/html,...`, which the renderer rejects -- shot_capture.cc takes\n // file, http and https and nothing else -- so every prewarm failed into the\n // catch below and the step had never once done anything. The failure was\n // invisible because a prewarm that does not work looks exactly like one that\n // does, only slower on the first request.\n //\n // The document names no subresources, so it renders identically whether or\n // not this daemon allows file access -- which is what the `data:` URL was\n // reaching for. A top-level file: URL always loads; `allowFileAccess` gates\n // what the document may then pull in.\n async prewarm(): Promise<void> {\n const blank = path.join(\n os.tmpdir(), `shotium-prewarm-${process.pid}.html`);\n try {\n fs.writeFileSync(\n blank, '<!doctype html><title>shotium</title><p>shotium');\n await this.engine.capture({file: blank, width: 16, height: 16});\n this.warmed = true;\n } catch (error) {\n // Not fatal: a daemon that could not prewarm still serves. But it is not\n // warm, and status() should not claim it is.\n this.emit('error', error);\n } finally {\n fs.rmSync(blank, {force: true});\n }\n this.emit('warm', {warm: this.warmed});\n }\n\n status(): DaemonStatus {\n return {\n ok: true,\n pid: process.pid,\n endpoint: this.endpointPath,\n cacheDir: this.options.cacheDir,\n userAgent: this.options.userAgent,\n resourceDir: this.options.resourceDir,\n warm: this.warmed,\n uptimeMs: Date.now() - this.startedAt,\n connections: this.sockets.size,\n inFlight: this.inFlight,\n served: this.served,\n idleTimeoutMs: this.idleTimeoutMs,\n version: VERSION,\n };\n }\n\n private accept(socket: net.Socket): void {\n socket.on('error', () => socket.destroy());\n this.sockets.add(socket);\n this.armIdleTimer();\n\n const reader = new FrameReader();\n socket.on('data', (chunk: Buffer) => {\n reader.push(chunk);\n for (;;) {\n const frame = reader.next();\n if (frame === null) {\n return;\n }\n this.dispatch(socket, frame);\n }\n });\n socket.on('close', () => {\n this.sockets.delete(socket);\n this.armIdleTimer();\n });\n }\n\n private dispatch(socket: net.Socket, frame: Buffer): void {\n let message: DaemonMessage;\n try {\n message = JSON.parse(frame.toString('utf8')) as DaemonMessage;\n } catch {\n this.reply(\n socket, {id: null, ok: false, error: 'shotium: request is not JSON'});\n return;\n }\n\n const id = message.id === undefined ? null : message.id;\n const op = message.op || 'screenshot';\n if (op === 'status') {\n this.reply(socket, {...this.status(), id});\n return;\n }\n if (op === 'ping') {\n this.reply(socket, {id, ok: true});\n return;\n }\n if (op === 'shutdown') {\n this.reply(socket, {id, ok: true, stopping: true});\n // After the reply is on the wire, not before: a client that asked for a\n // shutdown is entitled to hear that it happened.\n socket.end(() => void this.close());\n return;\n }\n if (op !== 'screenshot') {\n this.reply(socket, {id, ok: false, error: `shotium: unknown op \"${op}\"`});\n return;\n }\n\n const request = message.request || ({} as WireRequest);\n\n this.inFlight += 1;\n this.armIdleTimer();\n this.emit('request', {id, file: request.file});\n this.engine.capture(request)\n .then((image) => {\n this.served += 1;\n this.reply(\n socket,\n {\n id,\n ok: true,\n bytes: image ? image.length : 0,\n path: request.path,\n },\n image);\n })\n .catch((error: Error) => {\n this.reply(\n socket, {id, ok: false, error: String(error.message || error)});\n })\n .finally(() => {\n this.inFlight -= 1;\n this.emit('response', {id});\n this.armIdleTimer();\n });\n }\n\n private reply(\n socket: net.Socket, header: DaemonReply|(DaemonStatus&{id: number|null}),\n payload?: Buffer|null): void {\n if (socket.destroyed) {\n return;\n }\n socket.write(encodeFrame(Buffer.from(JSON.stringify(header), 'utf8')));\n socket.write(encodeFrame(payload || Buffer.alloc(0)));\n }\n\n // Idle is \"nobody connected and nothing rendering\". A client that holds its\n // socket open -- a long-lived service using connect() -- keeps the daemon\n // alive without having to poll it.\n private armIdleTimer(): void {\n if (this.idleTimer) {\n clearTimeout(this.idleTimer);\n this.idleTimer = null;\n }\n if (!this.idleTimeoutMs || this.closing) {\n return;\n }\n if (this.sockets.size > 0 || this.inFlight > 0) {\n return;\n }\n this.idleTimer = setTimeout(() => {\n this.emit('idle-exit', {idleTimeoutMs: this.idleTimeoutMs});\n void this.close();\n }, this.idleTimeoutMs);\n this.idleTimer.unref();\n }\n\n async close(): Promise<void> {\n if (this.closing) {\n return;\n }\n this.closing = true;\n if (this.idleTimer) {\n clearTimeout(this.idleTimer);\n this.idleTimer = null;\n }\n for (const socket of this.sockets) {\n socket.destroy();\n }\n this.sockets.clear();\n await new Promise<void>((resolve) => this.server!.close(() => resolve()));\n await this.engine.stop();\n this.emit('close', {});\n }\n}\n\nexport {Daemon, DEFAULT_IDLE_TIMEOUT_MS};\n","// The entry point of a detached daemon process.\n//\n// The configuration arrives as one base64 argument rather than as flags,\n// because it contains paths that a Windows command line would otherwise quote\n// badly, and because the client and the daemon have to agree on it exactly:\n// the endpoint is a hash of these fields, so a value mangled in transit would\n// produce a daemon listening where nobody looks. See endpoint.ts.\n//\n// It is a build entry of its own, and not a chunk, because lib/client.ts\n// spawns it by path -- `node dist/daemon_main.js <base64 json>` -- and a name\n// the bundler chose would be a name that changes.\n\nimport {Daemon} from './lib/daemon.js';\nimport type {DaemonOptions} from './types.js';\n\nasync function main(): Promise<void> {\n const encoded = process.argv[2];\n if (!encoded) {\n process.stderr.write('shotium: daemon_main expects a base64 config\\n');\n process.exit(2);\n }\n const options = JSON.parse(Buffer.from(encoded, 'base64').toString('utf8')) as\n DaemonOptions;\n const daemon = new Daemon(options);\n\n daemon.on('stderr', ({worker, line}: {worker: number, line: string}) => {\n process.stderr.write(`shotium worker ${worker}: ${line}\\n`);\n });\n for (const event of ['crash', 'timeout', 'worker-restart', 'worker-error',\n 'idle-exit']) {\n daemon.on(event, (payload: {error?: unknown}) => {\n // An Error does not survive JSON.stringify -- it comes out as {} -- and\n // its message is the whole point of logging a worker that would not\n // start.\n const detail = payload && payload.error ?\n {\n ...payload,\n error: String(\n (payload.error as Error).message ?? payload.error),\n } :\n payload;\n process.stderr.write(\n `shotium daemon ${event}: ${JSON.stringify(detail)}\\n`);\n });\n }\n // An 'error' with nobody listening is thrown by EventEmitter itself, which\n // would turn a socket that failed after binding -- something the daemon can\n // survive -- into a dead pool.\n daemon.on('error', (error: Error) => {\n process.stderr.write(\n `shotium daemon error: ${(error && error.message) || error}\\n`);\n });\n\n try {\n await daemon.listen();\n } catch (error) {\n // Losing the race to bind is the ordinary outcome when two clients start a\n // daemon at the same moment: the other one is up, this one is not needed,\n // and the client that spawned it will connect to the winner. Anything else\n // is a real failure and says so.\n if ((error as NodeJS.ErrnoException | null)?.code === 'EADDRINUSE') {\n process.exit(0);\n }\n process.stderr.write(`shotium: daemon failed to start: ${error}\\n`);\n process.exit(1);\n }\n\n const shutdown = () => {\n daemon.close().then(() => process.exit(0), () => process.exit(1));\n };\n process.on('SIGINT', shutdown);\n process.on('SIGTERM', shutdown);\n daemon.on('close', () => process.exit(0));\n}\n\nvoid main();\n"],"mappings":";;;;;;;;AAmBA,MAAM,iBAAiB;CACrB,IAAI;EACF,MAAM,WACF,GAAG,aAAa,IAAI,IAAI,mBAAmB,YAAY,GAAG,GAAG,MAAM;EACvE,OAAQ,KAAK,MAAM,QAAQ,CAAC,CAAwB,WAAW;CACjE,QAAQ;EACN,OAAO;CACT;AACF,EAAC,CAAE;AAEH,MAAM,0BAA0B;AAgDhC,IAAM,SAAN,cAAqB,aAAa;CAChC,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB,SAAS,IAAI,OAAO;CACrC,AAAQ,SAA0B;CAClC,AAAQ,0BAAU,IAAI,IAAgB;CACtC,AAAQ,WAAW;CACnB,AAAQ,SAAS;CACjB,AAAQ,SAAS;CACjB,AAAQ,YAAY,KAAK,IAAI;CAC7B,AAAQ,YAAiC;CACzC,AAAQ,UAAU;CAElB,YAAY,UAAyB,CAAC,GAAG;EACvC,MAAM;EACN,KAAK,UAAU,oBAAoB,OAAO;EAC1C,KAAK,eAAe,YAAY;GAC9B,GAAG,KAAK;GACR,MAAM,QAAQ;GACd,UAAU,QAAQ;EACpB,CAAC;EACD,KAAK,gBAAgB,QAAQ,kBAAkB,SAC3C,0BACA,QAAQ;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