@kitsra/kavio-render-worker 0.1.2 → 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/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +157 -20
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,12 @@ export interface BrowserOpenOptions {
|
|
|
22
22
|
export interface BrowserFrameCaptureOptions {
|
|
23
23
|
omitBackground?: boolean;
|
|
24
24
|
}
|
|
25
|
+
export interface BrowserFrameCaptureTiming {
|
|
26
|
+
/** Wall time spent seeking the composition to the frame in the page. */
|
|
27
|
+
evaluateMs: number;
|
|
28
|
+
/** Wall time spent producing the screenshot bytes. */
|
|
29
|
+
screenshotMs: number;
|
|
30
|
+
}
|
|
25
31
|
export interface BrowserFrameCapture {
|
|
26
32
|
frame: number;
|
|
27
33
|
bytes: Uint8Array;
|
|
@@ -30,6 +36,8 @@ export interface BrowserFrameCapture {
|
|
|
30
36
|
width: number;
|
|
31
37
|
height: number;
|
|
32
38
|
omitBackground: boolean;
|
|
39
|
+
/** Per-frame timing when the driver measures it. */
|
|
40
|
+
timing?: BrowserFrameCaptureTiming;
|
|
33
41
|
}
|
|
34
42
|
export interface DeterministicChromiumLaunchOptions {
|
|
35
43
|
headless: true;
|
|
@@ -69,6 +77,13 @@ export interface BrowserDriver {
|
|
|
69
77
|
open(composition: KavioDocument, options?: BrowserOpenOptions): Promise<void>;
|
|
70
78
|
renderFrame(frame: number, options?: BrowserFrameCaptureOptions): Promise<BrowserFrameCapture>;
|
|
71
79
|
close(): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Optional capability: create an independent frame renderer sharing this
|
|
82
|
+
* driver's browser session (e.g. another page on the same Chromium). Only
|
|
83
|
+
* valid after open(); the fork is already open for the same composition and
|
|
84
|
+
* its close() must tear down only the fork's own resources.
|
|
85
|
+
*/
|
|
86
|
+
fork?(): Promise<BrowserDriver>;
|
|
72
87
|
}
|
|
73
88
|
export declare function createBrowserViewport(composition: KavioDocument, deviceScaleFactor?: number): BrowserViewport;
|
|
74
89
|
export declare function createBrowserDriverMetadata(options: BrowserDriverMetadataOptions): BrowserDriverMetadata;
|
|
@@ -77,6 +92,7 @@ export declare function createPngFrameCapture(options: {
|
|
|
77
92
|
bytes: Uint8Array;
|
|
78
93
|
viewport: BrowserViewport;
|
|
79
94
|
omitBackground?: boolean;
|
|
95
|
+
timing?: BrowserFrameCaptureTiming;
|
|
80
96
|
}): BrowserFrameCapture;
|
|
81
97
|
export type RenderChecksumAlgorithm = "sha256" | "sha512";
|
|
82
98
|
export type RenderCleanupReason = "success" | "failure" | "manual";
|
|
@@ -182,6 +198,20 @@ export interface CaptureFramesOptions {
|
|
|
182
198
|
startFrame?: number;
|
|
183
199
|
frameCount?: number;
|
|
184
200
|
continueOnFrameError?: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Number of concurrent frame renderers. Values above 1 fork the driver
|
|
203
|
+
* (parallelism-1 times) and shard frames across the forks while onFrame,
|
|
204
|
+
* progress, and retention still observe strict frame order. Falls back to
|
|
205
|
+
* serial capture when the driver does not implement fork(). Deterministic:
|
|
206
|
+
* the same frames produce the same bytes in the same order.
|
|
207
|
+
*/
|
|
208
|
+
parallelism?: number;
|
|
209
|
+
/**
|
|
210
|
+
* Keep every capture's bytes in the result `captures` array. Defaults to
|
|
211
|
+
* true only when no `onFrame` sink is provided; streaming consumers should
|
|
212
|
+
* not pay O(frames) memory for bytes they already handled.
|
|
213
|
+
*/
|
|
214
|
+
retainCaptures?: boolean;
|
|
185
215
|
onProgress?: (progress: FrameCaptureProgress) => void | Promise<void>;
|
|
186
216
|
onFrame?: (capture: BrowserFrameCapture, progress: FrameCaptureProgress) => void | Promise<void>;
|
|
187
217
|
onFrameError?: (failure: FrameCaptureFrameError, progress: FrameCaptureProgress) => void | Promise<void>;
|
|
@@ -194,6 +224,12 @@ export interface CaptureFramesResult {
|
|
|
194
224
|
capturedFrames: number;
|
|
195
225
|
failedFrames: number;
|
|
196
226
|
bytesCaptured: number;
|
|
227
|
+
/** Wall time spent in driver.open() (browser launch + harness ready). */
|
|
228
|
+
openMs: number;
|
|
229
|
+
/** Sum of per-frame evaluate timings, when the driver reports them. */
|
|
230
|
+
evaluateMs?: number;
|
|
231
|
+
/** Sum of per-frame screenshot timings, when the driver reports them. */
|
|
232
|
+
screenshotMs?: number;
|
|
197
233
|
}
|
|
198
234
|
export interface RenderBatchInput {
|
|
199
235
|
template: KavioDocument;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACf,MAAM,sBAAsB,CAAC;AAG9B,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG,WAAW,GAAG,eAAe,CAAC;AAC7E,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC;AACvC,MAAM,MAAM,uBAAuB,GAAG,KAAK,CAAC;AAC5C,MAAM,MAAM,yBAAyB,GAAG,WAAW,CAAC;AACpD,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAE1C,eAAO,MAAM,2BAA2B,eAA2C,CAAC;AACpF,eAAO,MAAM,sBAAsB,aAAqC,CAAC;AACzE,eAAO,MAAM,iCAAiC,QAA0C,CAAC;AACzF,eAAO,MAAM,oCAAoC,cAAkD,CAAC;AACpG,eAAO,MAAM,mCAAmC,IAAI,CAAC;AACrD,eAAO,MAAM,8BAA8B,SAAwC,CAAC;AAEpF,eAAO,MAAM,4BAA4B,4JAM/B,CAAC;AAEX,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAA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iBAAiB,CAMnB;AAED,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,SAAS,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,CAAC,CAAC,CAuBZ;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAqH/F;AAyHD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,GAAG,cAAc,EAAE,CAkD3E;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,cAAc,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB,GAAG,MAAM,CAQT"}
|
package/dist/index.js
CHANGED
|
@@ -67,7 +67,8 @@ export function createPngFrameCapture(options) {
|
|
|
67
67
|
mimeType: DEFAULT_BROWSER_SCREENSHOT_MIME_TYPE,
|
|
68
68
|
width: options.viewport.width,
|
|
69
69
|
height: options.viewport.height,
|
|
70
|
-
omitBackground: options.omitBackground ?? true
|
|
70
|
+
omitBackground: options.omitBackground ?? true,
|
|
71
|
+
...(options.timing !== undefined && { timing: options.timing })
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
74
|
export class RenderCleanupStack {
|
|
@@ -198,12 +199,16 @@ export async function captureFrames(options) {
|
|
|
198
199
|
...DEFAULT_BROWSER_FRAME_CAPTURE_OPTIONS,
|
|
199
200
|
...options.captureOptions
|
|
200
201
|
};
|
|
202
|
+
const retainCaptures = options.retainCaptures ?? options.onFrame === undefined;
|
|
201
203
|
const captures = [];
|
|
202
204
|
const errors = [];
|
|
203
205
|
let completedFrames = 0;
|
|
204
206
|
let capturedFrames = 0;
|
|
205
207
|
let failedFrames = 0;
|
|
206
208
|
let bytesCaptured = 0;
|
|
209
|
+
let openMs = 0;
|
|
210
|
+
let evaluateMs;
|
|
211
|
+
let screenshotMs;
|
|
207
212
|
const createProgress = (phase, frame, error) => {
|
|
208
213
|
const progress = {
|
|
209
214
|
phase,
|
|
@@ -224,35 +229,64 @@ export async function captureFrames(options) {
|
|
|
224
229
|
await withRenderCleanup(async (cleanup) => {
|
|
225
230
|
cleanup.defer(createBrowserContextCleanupTask(options.driver));
|
|
226
231
|
await emitCaptureProgress(options.onProgress, createProgress("open"));
|
|
232
|
+
const openStart = performance.now();
|
|
227
233
|
await options.driver.open(options.composition, {
|
|
228
234
|
viewport: createBrowserViewport(options.composition),
|
|
229
235
|
...options.openOptions
|
|
230
236
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
237
|
+
openMs = performance.now() - openStart;
|
|
238
|
+
const emitSuccess = async (capture) => {
|
|
239
|
+
if (retainCaptures) {
|
|
240
|
+
captures.push(capture);
|
|
235
241
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
failedFrames += 1;
|
|
240
|
-
completedFrames += 1;
|
|
241
|
-
const progress = createProgress("frame-error", frame, error);
|
|
242
|
-
await emitCaptureFrameError(options.onFrameError, failure, progress);
|
|
243
|
-
await emitCaptureProgress(options.onProgress, progress);
|
|
244
|
-
if (options.continueOnFrameError !== true) {
|
|
245
|
-
throw createFrameCaptureError(failure);
|
|
246
|
-
}
|
|
247
|
-
continue;
|
|
242
|
+
if (capture.timing !== undefined) {
|
|
243
|
+
evaluateMs = (evaluateMs ?? 0) + capture.timing.evaluateMs;
|
|
244
|
+
screenshotMs = (screenshotMs ?? 0) + capture.timing.screenshotMs;
|
|
248
245
|
}
|
|
249
|
-
captures.push(capture);
|
|
250
246
|
capturedFrames += 1;
|
|
251
247
|
completedFrames += 1;
|
|
252
248
|
bytesCaptured += capture.bytes.byteLength;
|
|
253
|
-
const progress = createProgress("capture", frame);
|
|
249
|
+
const progress = createProgress("capture", capture.frame);
|
|
254
250
|
await emitCapturedFrame(options.onFrame, capture, progress);
|
|
255
251
|
await emitCaptureProgress(options.onProgress, progress);
|
|
252
|
+
};
|
|
253
|
+
const emitFailure = async (frame, error) => {
|
|
254
|
+
const failure = { frame, error };
|
|
255
|
+
errors.push(failure);
|
|
256
|
+
failedFrames += 1;
|
|
257
|
+
completedFrames += 1;
|
|
258
|
+
const progress = createProgress("frame-error", frame, error);
|
|
259
|
+
await emitCaptureFrameError(options.onFrameError, failure, progress);
|
|
260
|
+
await emitCaptureProgress(options.onProgress, progress);
|
|
261
|
+
if (options.continueOnFrameError !== true) {
|
|
262
|
+
throw createFrameCaptureError(failure);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const requestedParallelism = Math.max(1, Math.trunc(options.parallelism ?? 1));
|
|
266
|
+
const forkDriver = options.driver.fork?.bind(options.driver);
|
|
267
|
+
const workerCount = forkDriver === undefined ? 1 : Math.max(1, Math.min(requestedParallelism, range.totalFrames));
|
|
268
|
+
if (workerCount === 1 || forkDriver === undefined) {
|
|
269
|
+
for (let frame = range.startFrame; frame < range.endFrame; frame += 1) {
|
|
270
|
+
let capture;
|
|
271
|
+
try {
|
|
272
|
+
capture = await options.driver.renderFrame(frame, captureOptions);
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
await emitFailure(frame, error);
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
await emitSuccess(capture);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
await captureFramesInParallel({
|
|
283
|
+
drivers: await forkParallelDrivers(options.driver, forkDriver, workerCount, cleanup),
|
|
284
|
+
startFrame: range.startFrame,
|
|
285
|
+
endFrame: range.endFrame,
|
|
286
|
+
captureOptions,
|
|
287
|
+
emitSuccess,
|
|
288
|
+
emitFailure
|
|
289
|
+
});
|
|
256
290
|
}
|
|
257
291
|
await emitCaptureProgress(options.onProgress, createProgress("complete"));
|
|
258
292
|
});
|
|
@@ -263,8 +297,111 @@ export async function captureFrames(options) {
|
|
|
263
297
|
completedFrames,
|
|
264
298
|
capturedFrames,
|
|
265
299
|
failedFrames,
|
|
266
|
-
bytesCaptured
|
|
300
|
+
bytesCaptured,
|
|
301
|
+
openMs,
|
|
302
|
+
...(evaluateMs !== undefined && { evaluateMs }),
|
|
303
|
+
...(screenshotMs !== undefined && { screenshotMs })
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
async function forkParallelDrivers(driver, forkDriver, workerCount, cleanup) {
|
|
307
|
+
// Forks launch concurrently; each registers cleanup as soon as it exists so
|
|
308
|
+
// partial failures still tear down the forks that did launch.
|
|
309
|
+
const forks = await Promise.allSettled(Array.from({ length: workerCount - 1 }, async (_unused, index) => {
|
|
310
|
+
const fork = await forkDriver();
|
|
311
|
+
cleanup.defer(createBrowserContextCleanupTask(fork, `browser-context-fork-${index + 1}`));
|
|
312
|
+
return fork;
|
|
313
|
+
}));
|
|
314
|
+
const rejected = forks.find((outcome) => outcome.status === "rejected");
|
|
315
|
+
if (rejected !== undefined) {
|
|
316
|
+
throw rejected.reason;
|
|
317
|
+
}
|
|
318
|
+
return [
|
|
319
|
+
driver,
|
|
320
|
+
...forks.map((outcome) => outcome.value)
|
|
321
|
+
];
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Shard frames across drivers with a work-stealing counter while emitting
|
|
325
|
+
* results in strict frame order through a bounded reorder buffer. Workers
|
|
326
|
+
* pause when the buffer is full, so a slow downstream consumer applies
|
|
327
|
+
* backpressure to every page instead of buffering the render.
|
|
328
|
+
*/
|
|
329
|
+
async function captureFramesInParallel(options) {
|
|
330
|
+
const pending = new Map();
|
|
331
|
+
const maxPending = options.drivers.length * 2;
|
|
332
|
+
let nextFrame = options.startFrame;
|
|
333
|
+
let nextEmit = options.startFrame;
|
|
334
|
+
let stopped = false;
|
|
335
|
+
let emitterWaiter = null;
|
|
336
|
+
const wakeEmitter = () => {
|
|
337
|
+
const waiter = emitterWaiter;
|
|
338
|
+
emitterWaiter = null;
|
|
339
|
+
waiter?.();
|
|
340
|
+
};
|
|
341
|
+
let workerWaiters = [];
|
|
342
|
+
const wakeWorkers = () => {
|
|
343
|
+
const waiters = workerWaiters;
|
|
344
|
+
workerWaiters = [];
|
|
345
|
+
for (const waiter of waiters) {
|
|
346
|
+
waiter();
|
|
347
|
+
}
|
|
267
348
|
};
|
|
349
|
+
const emitter = async () => {
|
|
350
|
+
try {
|
|
351
|
+
while (nextEmit < options.endFrame) {
|
|
352
|
+
const entry = pending.get(nextEmit);
|
|
353
|
+
if (entry === undefined) {
|
|
354
|
+
await new Promise((resolve) => {
|
|
355
|
+
emitterWaiter = resolve;
|
|
356
|
+
});
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
pending.delete(nextEmit);
|
|
360
|
+
const frame = nextEmit;
|
|
361
|
+
nextEmit += 1;
|
|
362
|
+
wakeWorkers();
|
|
363
|
+
if (entry.ok) {
|
|
364
|
+
await options.emitSuccess(entry.capture);
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
await options.emitFailure(frame, entry.error);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
finally {
|
|
372
|
+
stopped = true;
|
|
373
|
+
wakeWorkers();
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
const worker = async (driver) => {
|
|
377
|
+
while (!stopped) {
|
|
378
|
+
if (pending.size >= maxPending) {
|
|
379
|
+
await new Promise((resolve) => {
|
|
380
|
+
workerWaiters.push(resolve);
|
|
381
|
+
});
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
const frame = nextFrame;
|
|
385
|
+
if (frame >= options.endFrame) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
nextFrame += 1;
|
|
389
|
+
let entry;
|
|
390
|
+
try {
|
|
391
|
+
entry = { ok: true, capture: await driver.renderFrame(frame, options.captureOptions) };
|
|
392
|
+
}
|
|
393
|
+
catch (error) {
|
|
394
|
+
entry = { ok: false, error };
|
|
395
|
+
}
|
|
396
|
+
pending.set(frame, entry);
|
|
397
|
+
wakeEmitter();
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
const settled = await Promise.allSettled([emitter(), ...options.drivers.map((driver) => worker(driver))]);
|
|
401
|
+
const rejected = settled.find((outcome) => outcome.status === "rejected");
|
|
402
|
+
if (rejected !== undefined) {
|
|
403
|
+
throw rejected.reason;
|
|
404
|
+
}
|
|
268
405
|
}
|
|
269
406
|
export function expandRenderBatch(input) {
|
|
270
407
|
if (input.rows.length === 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitsra/kavio-render-worker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Browser automation and frame capture worker for Kavio.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@kitsra/kavio-schema": "0.
|
|
16
|
+
"@kitsra/kavio-schema": "0.2.0"
|
|
17
17
|
},
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|