deictic 0.8.0 → 0.8.1

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/API.md CHANGED
@@ -289,7 +289,8 @@ screenshots({ renderer: dom() }); // drawn in the page with modern-screenshot: n
289
289
  ```
290
290
 
291
291
  `rrweb()` uses Playwright's Chromium (`npx playwright install chromium`), else Chrome or Edge; `channel` or
292
- `executablePath` names one.
292
+ `executablePath` names one. A shot has what a `<canvas>` shows, WebGL's included: `rrweb()` has a WebGL canvas keep
293
+ its drawing buffer unless the page says otherwise.
293
294
 
294
295
  Masking follows [rrweb](https://github.com/rrweb-io/rrweb)'s names and defaults: `rr-block` blanks an element
295
296
  (`blockClass`, `blockSelector`), `rr-mask` masks its text (`maskTextClass`, `maskTextSelector`), and `maskAllInputs`
@@ -1 +1 @@
1
- {"version":3,"file":"rrweb.d.ts","names":["_$__index_ts0.Capture"],"sources":["../../src/plugins/screenshots/rrweb.ts"],"mappings":";;;;;;;cAiBA,4B,2BAAAA"}
1
+ {"version":3,"file":"rrweb.d.ts","names":["_$__index_ts0.Capture"],"sources":["../../src/plugins/screenshots/rrweb.ts"],"mappings":";;;;;;;cAqBA,4B,2BAAAA"}
@@ -1,3 +1,4 @@
1
+ import { n as keepWebGLDrawing, t as CANVAS_SIZE } from "../shared/canvas.js";
1
2
  import { i as screenshotsClient, t as boxOf } from "../shared/client.js";
2
3
  // src/plugins/screenshots/rrweb.ts
3
4
  /**
@@ -6,6 +7,7 @@ import { i as screenshotsClient, t as boxOf } from "../shared/client.js";
6
7
  * to show it as the page does: the viewport and the window around it, where it's scrolled to, the pixel density, the page's URL.
7
8
  * And which node of the snapshot the element is, so the server says where it is in what it drew.
8
9
  */
10
+ keepWebGLDrawing();
9
11
  /** The snapshot without deictic's overlay, which rrweb has no option to leave out. */
10
12
  function withoutOurs(node) {
11
13
  if (!("childNodes" in node)) return node;
@@ -20,16 +22,23 @@ var rrweb_default = screenshotsClient(async (element, { area, masking, overlay }
20
22
  throw new Error("the rrweb() renderer needs rrweb-snapshot: add it to your devDependencies", { cause: e });
21
23
  });
22
24
  const mirror = createMirror();
23
- const taken = snapshot(document, {
25
+ const taken = await new Promise((done) => requestAnimationFrame(() => done(snapshot(document, {
24
26
  mirror,
25
27
  inlineStylesheet: true,
28
+ recordCanvas: true,
26
29
  blockClass: masking.blockClass,
27
30
  blockSelector: masking.blockSelector ?? null,
28
31
  maskTextClass: masking.maskTextClass,
29
32
  maskTextSelector: masking.maskTextSelector ?? null,
30
33
  maskAllInputs: masking.maskAllInputs
31
- });
34
+ }))));
32
35
  if (taken === null) throw new Error("screenshots: rrweb took no snapshot of this page");
36
+ for (const canvas of document.querySelectorAll("canvas")) {
37
+ const node = mirror.getMeta(canvas);
38
+ if (node === null || !("attributes" in node) || typeof node.attributes.rr_dataURL !== "string") continue;
39
+ const inline = getComputedStyle(canvas).display === "inline";
40
+ node.attributes[CANVAS_SIZE] = `${canvas.offsetWidth}x${canvas.offsetHeight}${inline ? " inline" : ""}`;
41
+ }
33
42
  const box = boxOf(element, area);
34
43
  const viewport = {
35
44
  width: document.documentElement.clientWidth,
@@ -1 +1 @@
1
- {"version":3,"file":"rrweb.js","names":[],"sources":["../../src/plugins/screenshots/rrweb.ts"],"sourcesContent":["/**\n * The `rrweb()` renderer's page half: a snapshot of the page's DOM with `rrweb-snapshot` (imported on the\n * first shot), masked as rrweb masks, without deictic's overlay, sent with what the server's browser needs\n * to show it as the page does: the viewport and the window around it, where it's scrolled to, the pixel density, the page's URL.\n * And which node of the snapshot the element is, so the server says where it is in what it drew.\n */\n\nimport { boxOf, screenshotsClient } from './client.ts';\nimport type { Snapshot, SnapshotNode } from './playwright.ts';\n\n/** The snapshot without deictic's overlay, which rrweb has no option to leave out. */\nfunction withoutOurs(node: SnapshotNode): SnapshotNode {\n if (!('childNodes' in node)) return node;\n const childNodes = node.childNodes.filter((c: SnapshotNode) => !('tagName' in c && c.tagName === 'deictic-overlay')).map(withoutOurs);\n return { ...node, childNodes };\n}\n\nexport default screenshotsClient(async (element, { area, masking, overlay }) => {\n const { snapshot, createMirror } = await import('rrweb-snapshot').catch((e: unknown) => {\n throw new Error('the rrweb() renderer needs rrweb-snapshot: add it to your devDependencies', { cause: e });\n });\n const mirror = createMirror();\n const taken = snapshot(document, {\n mirror,\n inlineStylesheet: true,\n blockClass: masking.blockClass,\n blockSelector: masking.blockSelector ?? null,\n maskTextClass: masking.maskTextClass,\n maskTextSelector: masking.maskTextSelector ?? null,\n maskAllInputs: masking.maskAllInputs,\n });\n if (taken === null) throw new Error('screenshots: rrweb took no snapshot of this page');\n const box = boxOf(element, area);\n const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };\n // Over the viewport, which the server renders before cutting out an element's part.\n const marks = overlay({ x: 0, y: 0, ...viewport });\n const body: Snapshot = {\n snapshot: withoutOurs(taken),\n ...(mirror.getId(element) === -1 ? {} : { element: mirror.getId(element) }),\n url: location.href,\n viewport,\n window: { width: innerWidth, height: innerHeight },\n ...(marks === undefined ? {} : { overlay: marks }),\n scroll: { x: scrollX, y: scrollY },\n scale: Math.min(devicePixelRatio, 2),\n // A shot of the element alone is the part of the viewport it fills.\n ...(area === 'element' ? { clip: element.getBoundingClientRect().toJSON() as Snapshot['clip'] } : {}),\n };\n return { body: JSON.stringify(body), type: 'application/json', box };\n});\n"],"mappings":";;;;;;;;;AAWA,SAAS,YAAY,MAAkC;CACrD,IAAI,EAAE,gBAAgB,OAAO,OAAO;CACpC,MAAM,aAAa,KAAK,WAAW,QAAQ,MAAoB,EAAE,aAAa,KAAK,EAAE,YAAY,kBAAkB,CAAC,CAAC,IAAI,WAAW;CACpI,OAAO;EAAE,GAAG;EAAM;CAAW;AAC/B;AAEA,IAAA,gBAAe,kBAAkB,OAAO,SAAS,EAAE,MAAM,SAAS,cAAc;CAC9E,MAAM,EAAE,UAAU,iBAAiB,MAAM,OAAO,iBAAiB,CAAC,OAAO,MAAe;EACtF,MAAM,IAAI,MAAM,6EAA6E,EAAE,OAAO,EAAE,CAAC;CAC3G,CAAC;CACD,MAAM,SAAS,aAAa;CAC5B,MAAM,QAAQ,SAAS,UAAU;EAC/B;EACA,kBAAkB;EAClB,YAAY,QAAQ;EACpB,eAAe,QAAQ,iBAAiB;EACxC,eAAe,QAAQ;EACvB,kBAAkB,QAAQ,oBAAoB;EAC9C,eAAe,QAAQ;CACzB,CAAC;CACD,IAAI,UAAU,MAAM,MAAM,IAAI,MAAM,kDAAkD;CACtF,MAAM,MAAM,MAAM,SAAS,IAAI;CAC/B,MAAM,WAAW;EAAE,OAAO,SAAS,gBAAgB;EAAa,QAAQ,SAAS,gBAAgB;CAAa;CAE9G,MAAM,QAAQ,QAAQ;EAAE,GAAG;EAAG,GAAG;EAAG,GAAG;CAAS,CAAC;CACjD,MAAM,OAAiB;EACrB,UAAU,YAAY,KAAK;EAC3B,GAAI,OAAO,MAAM,OAAO,MAAM,KAAK,CAAC,IAAI,EAAE,SAAS,OAAO,MAAM,OAAO,EAAE;EACzE,KAAK,SAAS;EACd;EACA,QAAQ;GAAE,OAAO;GAAY,QAAQ;EAAY;EACjD,GAAI,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,MAAM;EAChD,QAAQ;GAAE,GAAG;GAAS,GAAG;EAAQ;EACjC,OAAO,KAAK,IAAI,kBAAkB,CAAC;EAEnC,GAAI,SAAS,YAAY,EAAE,MAAM,QAAQ,sBAAsB,CAAC,CAAC,OAAO,EAAsB,IAAI,CAAC;CACrG;CACA,OAAO;EAAE,MAAM,KAAK,UAAU,IAAI;EAAG,MAAM;EAAoB;CAAI;AACrE,CAAC"}
1
+ {"version":3,"file":"rrweb.js","names":[],"sources":["../../src/plugins/screenshots/rrweb.ts"],"sourcesContent":["/**\n * The `rrweb()` renderer's page half: a snapshot of the page's DOM with `rrweb-snapshot` (imported on the\n * first shot), masked as rrweb masks, without deictic's overlay, sent with what the server's browser needs\n * to show it as the page does: the viewport and the window around it, where it's scrolled to, the pixel density, the page's URL.\n * And which node of the snapshot the element is, so the server says where it is in what it drew.\n */\n\nimport { CANVAS_SIZE, keepWebGLDrawing } from './canvas.ts';\nimport { boxOf, screenshotsClient } from './client.ts';\nimport type { Snapshot, SnapshotNode } from './playwright.ts';\n\n// As the page loads, before the page makes its canvases.\nkeepWebGLDrawing();\n\n/** The snapshot without deictic's overlay, which rrweb has no option to leave out. */\nfunction withoutOurs(node: SnapshotNode): SnapshotNode {\n if (!('childNodes' in node)) return node;\n const childNodes = node.childNodes.filter((c: SnapshotNode) => !('tagName' in c && c.tagName === 'deictic-overlay')).map(withoutOurs);\n return { ...node, childNodes };\n}\n\nexport default screenshotsClient(async (element, { area, masking, overlay }) => {\n const { snapshot, createMirror } = await import('rrweb-snapshot').catch((e: unknown) => {\n throw new Error('the rrweb() renderer needs rrweb-snapshot: add it to your devDependencies', { cause: e });\n });\n const mirror = createMirror();\n // In a frame, after the page drew in it: a WebGL canvas reads back blank once its frame is shown, unless the page\n // keeps its drawing buffer, and the page's own callbacks for the frame were asked for before this one.\n const taken = await new Promise<ReturnType<typeof snapshot>>((done) =>\n requestAnimationFrame(() =>\n done(\n snapshot(document, {\n mirror,\n inlineStylesheet: true,\n // A canvas as a picture of what it shows, which the server draws on the canvas it rebuilds.\n recordCanvas: true,\n blockClass: masking.blockClass,\n blockSelector: masking.blockSelector ?? null,\n maskTextClass: masking.maskTextClass,\n maskTextSelector: masking.maskTextSelector ?? null,\n maskAllInputs: masking.maskAllInputs,\n }),\n ),\n ),\n );\n if (taken === null) throw new Error('screenshots: rrweb took no snapshot of this page');\n // Each canvas's size as the page lays it out, and whether in a line, as which the server shows the canvas's picture.\n for (const canvas of document.querySelectorAll('canvas')) {\n const node = mirror.getMeta(canvas);\n if (node === null || !('attributes' in node) || typeof node.attributes.rr_dataURL !== 'string') continue;\n const inline = getComputedStyle(canvas).display === 'inline';\n node.attributes[CANVAS_SIZE] = `${canvas.offsetWidth}x${canvas.offsetHeight}${inline ? ' inline' : ''}`;\n }\n const box = boxOf(element, area);\n const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };\n // Over the viewport, which the server renders before cutting out an element's part.\n const marks = overlay({ x: 0, y: 0, ...viewport });\n const body: Snapshot = {\n snapshot: withoutOurs(taken),\n ...(mirror.getId(element) === -1 ? {} : { element: mirror.getId(element) }),\n url: location.href,\n viewport,\n window: { width: innerWidth, height: innerHeight },\n ...(marks === undefined ? {} : { overlay: marks }),\n scroll: { x: scrollX, y: scrollY },\n scale: Math.min(devicePixelRatio, 2),\n // A shot of the element alone is the part of the viewport it fills.\n ...(area === 'element' ? { clip: element.getBoundingClientRect().toJSON() as Snapshot['clip'] } : {}),\n };\n return { body: JSON.stringify(body), type: 'application/json', box };\n});\n"],"mappings":";;;;;;;;;AAYA,iBAAiB;;AAGjB,SAAS,YAAY,MAAkC;CACrD,IAAI,EAAE,gBAAgB,OAAO,OAAO;CACpC,MAAM,aAAa,KAAK,WAAW,QAAQ,MAAoB,EAAE,aAAa,KAAK,EAAE,YAAY,kBAAkB,CAAC,CAAC,IAAI,WAAW;CACpI,OAAO;EAAE,GAAG;EAAM;CAAW;AAC/B;AAEA,IAAA,gBAAe,kBAAkB,OAAO,SAAS,EAAE,MAAM,SAAS,cAAc;CAC9E,MAAM,EAAE,UAAU,iBAAiB,MAAM,OAAO,iBAAiB,CAAC,OAAO,MAAe;EACtF,MAAM,IAAI,MAAM,6EAA6E,EAAE,OAAO,EAAE,CAAC;CAC3G,CAAC;CACD,MAAM,SAAS,aAAa;CAG5B,MAAM,QAAQ,MAAM,IAAI,SAAsC,SAC5D,4BACE,KACE,SAAS,UAAU;EACjB;EACA,kBAAkB;EAElB,cAAc;EACd,YAAY,QAAQ;EACpB,eAAe,QAAQ,iBAAiB;EACxC,eAAe,QAAQ;EACvB,kBAAkB,QAAQ,oBAAoB;EAC9C,eAAe,QAAQ;CACzB,CAAC,CACH,CACF,CACF;CACA,IAAI,UAAU,MAAM,MAAM,IAAI,MAAM,kDAAkD;CAEtF,KAAK,MAAM,UAAU,SAAS,iBAAiB,QAAQ,GAAG;EACxD,MAAM,OAAO,OAAO,QAAQ,MAAM;EAClC,IAAI,SAAS,QAAQ,EAAE,gBAAgB,SAAS,OAAO,KAAK,WAAW,eAAe,UAAU;EAChG,MAAM,SAAS,iBAAiB,MAAM,CAAC,CAAC,YAAY;EACpD,KAAK,WAAW,eAAe,GAAG,OAAO,YAAY,GAAG,OAAO,eAAe,SAAS,YAAY;CACrG;CACA,MAAM,MAAM,MAAM,SAAS,IAAI;CAC/B,MAAM,WAAW;EAAE,OAAO,SAAS,gBAAgB;EAAa,QAAQ,SAAS,gBAAgB;CAAa;CAE9G,MAAM,QAAQ,QAAQ;EAAE,GAAG;EAAG,GAAG;EAAG,GAAG;CAAS,CAAC;CACjD,MAAM,OAAiB;EACrB,UAAU,YAAY,KAAK;EAC3B,GAAI,OAAO,MAAM,OAAO,MAAM,KAAK,CAAC,IAAI,EAAE,SAAS,OAAO,MAAM,OAAO,EAAE;EACzE,KAAK,SAAS;EACd;EACA,QAAQ;GAAE,OAAO;GAAY,QAAQ;EAAY;EACjD,GAAI,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,MAAM;EAChD,QAAQ;GAAE,GAAG;GAAS,GAAG;EAAQ;EACjC,OAAO,KAAK,IAAI,kBAAkB,CAAC;EAEnC,GAAI,SAAS,YAAY,EAAE,MAAM,QAAQ,sBAAsB,CAAC,CAAC,OAAO,EAAsB,IAAI,CAAC;CACrG;CACA,OAAO;EAAE,MAAM,KAAK,UAAU,IAAI;EAAG,MAAM;EAAoB;CAAI;AACrE,CAAC"}
@@ -0,0 +1,30 @@
1
+ // src/plugins/screenshots/canvas.ts
2
+ /** What the rrweb() renderer's two halves share about canvases, with no imports, as the page half runs in the page. */
3
+ /**
4
+ * The attribute the page half gives each canvas with a picture: the canvas's size as the page lays it out, `WxH` in
5
+ * CSS pixels, then ` inline` where the canvas sits in a line of text, as which the server shows the picture.
6
+ */
7
+ const CANVAS_SIZE = "data-deictic-canvas-size";
8
+ /**
9
+ * Has each WebGL canvas the page makes from here on keep what the canvas drew, where the page doesn't say: a WebGL
10
+ * canvas otherwise reads back cleared once the canvas's frame shows, so a shot of a page that drew and went still
11
+ * would have the canvas blank. rrweb's recorder does the same while the recorder records canvases. A page that clears
12
+ * each frame draws the same either way. Self-contained, as the rrweb() renderer's test runs the function in a page as it is.
13
+ */
14
+ function keepWebGLDrawing() {
15
+ if (typeof HTMLCanvasElement === "undefined") return;
16
+ const proto = HTMLCanvasElement.prototype;
17
+ const original = Object.getOwnPropertyDescriptor(proto, "getContext")?.value;
18
+ if (typeof original !== "function") return;
19
+ proto.getContext = function(type, options) {
20
+ const given = typeof options === "object" && options !== null ? options : {};
21
+ const kept = (type === "webgl" || type === "webgl2" || type === "experimental-webgl") && given.preserveDrawingBuffer === void 0 ? {
22
+ ...given,
23
+ preserveDrawingBuffer: true
24
+ } : options;
25
+ return Reflect.apply(original, this, [type, kept]);
26
+ };
27
+ }
28
+ export { keepWebGLDrawing as n, CANVAS_SIZE as t };
29
+
30
+ //# sourceMappingURL=canvas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canvas.js","names":[],"sources":["../../src/plugins/screenshots/canvas.ts"],"sourcesContent":["/** What the rrweb() renderer's two halves share about canvases, with no imports, as the page half runs in the page. */\n\n/**\n * The attribute the page half gives each canvas with a picture: the canvas's size as the page lays it out, `WxH` in\n * CSS pixels, then ` inline` where the canvas sits in a line of text, as which the server shows the picture.\n */\nexport const CANVAS_SIZE = 'data-deictic-canvas-size';\n\n/**\n * Has each WebGL canvas the page makes from here on keep what the canvas drew, where the page doesn't say: a WebGL\n * canvas otherwise reads back cleared once the canvas's frame shows, so a shot of a page that drew and went still\n * would have the canvas blank. rrweb's recorder does the same while the recorder records canvases. A page that clears\n * each frame draws the same either way. Self-contained, as the rrweb() renderer's test runs the function in a page as it is.\n */\nexport function keepWebGLDrawing(): void {\n if (typeof HTMLCanvasElement === 'undefined') return;\n const proto = HTMLCanvasElement.prototype;\n // The page's own `getContext`, called on each canvas as the canvas's own.\n const original: unknown = Object.getOwnPropertyDescriptor(proto, 'getContext')?.value;\n if (typeof original !== 'function') return;\n proto.getContext = function (this: HTMLCanvasElement, type: string, options?: unknown) {\n const given = typeof options === 'object' && options !== null ? (options as Record<string, unknown>) : {};\n const webgl = type === 'webgl' || type === 'webgl2' || type === 'experimental-webgl';\n const kept = webgl && given.preserveDrawingBuffer === undefined ? { ...given, preserveDrawingBuffer: true } : options;\n return Reflect.apply(original, this, [type, kept]) as RenderingContext | null;\n } as typeof HTMLCanvasElement.prototype.getContext;\n}\n"],"mappings":";;;;;;AAMA,MAAa,cAAc;;;;;;;AAQ3B,SAAgB,mBAAyB;CACvC,IAAI,OAAO,sBAAsB,aAAa;CAC9C,MAAM,QAAQ,kBAAkB;CAEhC,MAAM,WAAoB,OAAO,yBAAyB,OAAO,YAAY,CAAC,EAAE;CAChF,IAAI,OAAO,aAAa,YAAY;CACpC,MAAM,aAAa,SAAmC,MAAc,SAAmB;EACrF,MAAM,QAAQ,OAAO,YAAY,YAAY,YAAY,OAAQ,UAAsC,CAAC;EAExG,MAAM,QADQ,SAAS,WAAW,SAAS,YAAY,SAAS,yBAC1C,MAAM,0BAA0B,KAAA,IAAY;GAAE,GAAG;GAAO,uBAAuB;EAAK,IAAI;EAC9G,OAAO,QAAQ,MAAM,UAAU,MAAM,CAAC,MAAM,IAAI,CAAC;CACnD;AACF"}
@@ -148,7 +148,12 @@ function ffmpeg(args) {
148
148
  async function fromProject(...names) {
149
149
  const project = createRequire(join(process.cwd(), "package.json"));
150
150
  for (const name of names) try {
151
- return await import(pathToFileURL(project.resolve(name)).href);
151
+ const module = await import(pathToFileURL(project.resolve(name)).href);
152
+ const exported = module.default;
153
+ return typeof exported === "object" && exported !== null ? {
154
+ ...exported,
155
+ ...module
156
+ } : module;
152
157
  } catch {}
153
158
  return fail(`Needs ${names.join(" or ")} in the project: npm install -D ${names[0]}`);
154
159
  }
@@ -1 +1 @@
1
- {"version":3,"file":"find.js","names":[],"sources":["../../src/cli/find.ts"],"sourcesContent":["/**\n * Finding what a task carries: a recording or a voice clip, by a task's ID, a recording's ID, a replay URL or a path,\n * kept under a `.deictic/` near here or downloaded from the board. And the tools outside deictic some commands run\n * (ffmpeg, the project's Playwright).\n */\nimport { spawnSync } from 'node:child_process';\nimport { existsSync, mkdtempSync, readdirSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport type { Kept } from '#src/plugins/recordings/index.ts';\n\nimport { deicticDirs, download, fail, type Message, task } from './board.ts';\n\nconst TASK = /^#?\\d+$/;\n\nexport interface Found {\n kept: Kept;\n id: string;\n /** Where it replays, where that's known. */\n replay?: string;\n /** The task it's attached to, where it was found by one. */\n task?: Message;\n}\n\nconst parsed = (path: string) => JSON.parse(readFileSync(path, 'utf8')) as Kept;\n\n/** An attachment of a task, written to a temporary folder: its path. */\nfunction fetched(root: Message, name: string): string {\n const file = root.attachments.find((a) => a.name === name);\n if (file === undefined) fail(`Task #${root.id} has no ${name}.`);\n const path = join(mkdtempSync(join(tmpdir(), 'deictic-')), file.name);\n download(file, path);\n return path;\n}\n\n/**\n * A recording, with where it came from. `ref` is a task's ID (its first recording, or the `nth`), a replay or\n * recording URL, a recording's ID kept under a `.deictic/`, or a path.\n */\nexport async function loadRecording(ref: string | undefined, nth = 1): Promise<Found> {\n if (ref === undefined) fail('Name a recording: a task (68), a replay URL, a recording ID or a JSON file.');\n if (TASK.test(ref)) {\n const root = task(ref);\n const files = root.attachments.filter((a) => /^recording-.*\\.json$/.test(a.name));\n const file = files[nth - 1];\n if (file === undefined) fail(`Task #${root.id} has ${files.length} recording(s), not a ${nth}th.`);\n const id = file.name.slice('recording-'.length, -'.json'.length);\n // Its `deictic.recording.N.replay` label, or in the text of a task added before that was a label.\n const where = (text: string) => new RegExp(`https?://\\\\S+/replay/${id}`).exec(text)?.[0];\n const replay = Object.values(root.labels).map(where).find(Boolean) ?? where(root.text);\n return { kept: parsed(fetched(root, file.name)), id, replay, task: root };\n }\n if (/^https?:/.test(ref)) {\n const url = new URL(ref);\n const id = url.pathname.split('/').at(-1) ?? '';\n const json = new URL(url.pathname.replace(/\\/(replay|recording)\\/[^/]+$/, `/recording/${id}`), url);\n const res = await fetch(json);\n if (!res.ok) fail(`${json.href}: ${res.status} ${await res.text()}`);\n return { kept: (await res.json()) as Kept, id, replay: new URL(json.pathname.replace(/\\/recording\\//, '/replay/'), url).href };\n }\n if (existsSync(ref)) return { kept: parsed(ref), id: ref.replace(/^.*[\\\\/]|\\.json$/g, '') };\n for (const dir of deicticDirs()) {\n const path = join(dir, 'recordings', `${ref}.json`);\n if (existsSync(path)) return { kept: parsed(path), id: ref };\n }\n return fail(`No recording ${ref} in ${deicticDirs().join(', ') || 'any .deictic/ near here'}: name its task or replay URL instead.`);\n}\n\n/** A voice clip kept under a `.deictic/` near here, by its ID. */\nfunction keptClip(id: string): string | undefined {\n for (const dir of deicticDirs()) {\n const voice = join(dir, 'voice');\n const name = existsSync(voice) ? readdirSync(voice).find((f) => f.startsWith(`${id}.`)) : undefined;\n if (name !== undefined) return join(voice, name);\n }\n return undefined;\n}\n\n/** A voice clip's audio as a file: kept under a `.deictic/`, or downloaded from `from`. */\nfunction voiceFile(id: string, from?: Message): string {\n const kept = keptClip(id);\n if (kept !== undefined) return kept;\n const file = from?.attachments.find((a) => a.name.startsWith(`voice-${id}.`));\n if (from === undefined || file === undefined) fail(`No voice clip ${id} here${from ? ` or on task #${from.id}` : ''}.`);\n return fetched(from, file.name);\n}\n\nexport interface Clip {\n id: string;\n file: string;\n /** Where it starts in its recording, or 0 for a voice note on its own. */\n at: number;\n recording?: string;\n}\n\n/**\n * The voice clips `ref` names: a task (every recording's clips and its voice notes), a recording as `loadRecording`\n * takes one, or a clip's ID.\n */\nexport async function voiceClips(ref: string | undefined): Promise<Clip[]> {\n if (ref === undefined) fail('Name a task, a recording or a voice clip.');\n const clips: Clip[] = [];\n if (TASK.test(ref)) {\n const root = task(ref);\n const recordings = root.attachments.filter((a) => /^recording-.*\\.json$/.test(a.name));\n const inRecordings = new Set<string>();\n for (let n = 1; n <= recordings.length; n++) {\n const { kept, id } = await loadRecording(ref, n);\n for (const c of kept.voice ?? []) {\n inRecordings.add(c.id);\n clips.push({ id: c.id, file: voiceFile(c.id, root), at: c.at, recording: id });\n }\n }\n for (const a of root.attachments) {\n const id = /^voice-(.+)\\.\\w+$/.exec(a.name)?.[1];\n if (id !== undefined && !inRecordings.has(id)) clips.push({ id, file: voiceFile(id, root), at: 0 });\n }\n } else if (!/^https?:/.test(ref) && !existsSync(ref) && keptClip(ref) !== undefined) {\n clips.push({ id: ref, file: voiceFile(ref), at: 0 });\n } else {\n const { kept, id } = await loadRecording(ref);\n for (const c of kept.voice ?? []) clips.push({ id: c.id, file: voiceFile(c.id), at: c.at, recording: id });\n }\n if (clips.length === 0) fail(`No voice on ${ref}.`);\n return clips;\n}\n\n/** Runs ffmpeg, which reads what MediaRecorder makes, and answers its log (stderr) and what it wrote to stdout. */\nexport function ffmpeg(args: string[]): { stdout: Buffer; log: string } {\n const run = spawnSync('ffmpeg', ['-hide_banner', '-nostats', ...args], { maxBuffer: 1 << 30 });\n if (run.error) fail('Needs ffmpeg on the PATH (https://ffmpeg.org/download.html).');\n return { stdout: run.stdout, log: run.stderr.toString('utf8') };\n}\n\n/** The project's own copy of a package deictic doesn't bring (Playwright, either of its names), from here. */\nexport async function fromProject<T>(...names: string[]): Promise<T> {\n const project = createRequire(join(process.cwd(), 'package.json'));\n for (const name of names) {\n try {\n return (await import(pathToFileURL(project.resolve(name)).href)) as T;\n } catch {\n // Not this one: the next name.\n }\n }\n return fail(`Needs ${names.join(' or ')} in the project: npm install -D ${names[0]}`);\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAM,OAAO;AAWb,MAAM,UAAU,SAAiB,KAAK,MAAM,aAA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;GAAG,IAAI,EAAE;GAAI,WAAW;EAAG,CAAC;CAC3G;CACA,IAAI,MAAM,WAAW,GAAG,KAAK,eAAe,IAAI,EAAE;CAClD,OAAO;AACT;;AAGA,SAAgB,OAAO,MAAiD;CACtE,MAAM,MAAM,UAAU,UAAU;EAAC;EAAgB;EAAY,GAAG;CAAI,GAAG,EAAE,WAAW,KAAK,GAAG,CAAC;CAC7F,IAAI,IAAI,OAAO,KAAK,8DAA8D;CAClF,OAAO;EAAE,QAAQ,IAAI;EAAQ,KAAK,IAAI,OAAO,SAAS,MAAM;CAAE;AAChE;;AAGA,eAAsB,YAAe,GAAG,OAA6B;CACnE,MAAM,UAAU,cAAc,KAAK,QAAQ,IAAI,GAAG,cAAc,CAAC;CACjE,KAAK,MAAM,QAAQ,OACjB,IAAI;EACF,OAAQ,MAAM,OAAO,cAAc,QAAQ,QAAQ,IAAI,CAAC,CAAC,CAAC;CAC5D,QAAQ,CAER;CAEF,OAAO,KAAK,SAAS,MAAM,KAAK,MAAM,EAAE,kCAAkC,MAAM,IAAI;AACtF"}
1
+ {"version":3,"file":"find.js","names":[],"sources":["../../src/cli/find.ts"],"sourcesContent":["/**\n * Finding what a task carries: a recording or a voice clip, by a task's ID, a recording's ID, a replay URL or a path,\n * kept under a `.deictic/` near here or downloaded from the board. And the tools outside deictic some commands run\n * (ffmpeg, the project's Playwright).\n */\nimport { spawnSync } from 'node:child_process';\nimport { existsSync, mkdtempSync, readdirSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport type { Kept } from '#src/plugins/recordings/index.ts';\n\nimport { deicticDirs, download, fail, type Message, task } from './board.ts';\n\nconst TASK = /^#?\\d+$/;\n\nexport interface Found {\n kept: Kept;\n id: string;\n /** Where it replays, where that's known. */\n replay?: string;\n /** The task it's attached to, where it was found by one. */\n task?: Message;\n}\n\nconst parsed = (path: string) => JSON.parse(readFileSync(path, 'utf8')) as Kept;\n\n/** An attachment of a task, written to a temporary folder: its path. */\nfunction fetched(root: Message, name: string): string {\n const file = root.attachments.find((a) => a.name === name);\n if (file === undefined) fail(`Task #${root.id} has no ${name}.`);\n const path = join(mkdtempSync(join(tmpdir(), 'deictic-')), file.name);\n download(file, path);\n return path;\n}\n\n/**\n * A recording, with where it came from. `ref` is a task's ID (its first recording, or the `nth`), a replay or\n * recording URL, a recording's ID kept under a `.deictic/`, or a path.\n */\nexport async function loadRecording(ref: string | undefined, nth = 1): Promise<Found> {\n if (ref === undefined) fail('Name a recording: a task (68), a replay URL, a recording ID or a JSON file.');\n if (TASK.test(ref)) {\n const root = task(ref);\n const files = root.attachments.filter((a) => /^recording-.*\\.json$/.test(a.name));\n const file = files[nth - 1];\n if (file === undefined) fail(`Task #${root.id} has ${files.length} recording(s), not a ${nth}th.`);\n const id = file.name.slice('recording-'.length, -'.json'.length);\n // Its `deictic.recording.N.replay` label, or in the text of a task added before that was a label.\n const where = (text: string) => new RegExp(`https?://\\\\S+/replay/${id}`).exec(text)?.[0];\n const replay = Object.values(root.labels).map(where).find(Boolean) ?? where(root.text);\n return { kept: parsed(fetched(root, file.name)), id, replay, task: root };\n }\n if (/^https?:/.test(ref)) {\n const url = new URL(ref);\n const id = url.pathname.split('/').at(-1) ?? '';\n const json = new URL(url.pathname.replace(/\\/(replay|recording)\\/[^/]+$/, `/recording/${id}`), url);\n const res = await fetch(json);\n if (!res.ok) fail(`${json.href}: ${res.status} ${await res.text()}`);\n return { kept: (await res.json()) as Kept, id, replay: new URL(json.pathname.replace(/\\/recording\\//, '/replay/'), url).href };\n }\n if (existsSync(ref)) return { kept: parsed(ref), id: ref.replace(/^.*[\\\\/]|\\.json$/g, '') };\n for (const dir of deicticDirs()) {\n const path = join(dir, 'recordings', `${ref}.json`);\n if (existsSync(path)) return { kept: parsed(path), id: ref };\n }\n return fail(`No recording ${ref} in ${deicticDirs().join(', ') || 'any .deictic/ near here'}: name its task or replay URL instead.`);\n}\n\n/** A voice clip kept under a `.deictic/` near here, by its ID. */\nfunction keptClip(id: string): string | undefined {\n for (const dir of deicticDirs()) {\n const voice = join(dir, 'voice');\n const name = existsSync(voice) ? readdirSync(voice).find((f) => f.startsWith(`${id}.`)) : undefined;\n if (name !== undefined) return join(voice, name);\n }\n return undefined;\n}\n\n/** A voice clip's audio as a file: kept under a `.deictic/`, or downloaded from `from`. */\nfunction voiceFile(id: string, from?: Message): string {\n const kept = keptClip(id);\n if (kept !== undefined) return kept;\n const file = from?.attachments.find((a) => a.name.startsWith(`voice-${id}.`));\n if (from === undefined || file === undefined) fail(`No voice clip ${id} here${from ? ` or on task #${from.id}` : ''}.`);\n return fetched(from, file.name);\n}\n\nexport interface Clip {\n id: string;\n file: string;\n /** Where it starts in its recording, or 0 for a voice note on its own. */\n at: number;\n recording?: string;\n}\n\n/**\n * The voice clips `ref` names: a task (every recording's clips and its voice notes), a recording as `loadRecording`\n * takes one, or a clip's ID.\n */\nexport async function voiceClips(ref: string | undefined): Promise<Clip[]> {\n if (ref === undefined) fail('Name a task, a recording or a voice clip.');\n const clips: Clip[] = [];\n if (TASK.test(ref)) {\n const root = task(ref);\n const recordings = root.attachments.filter((a) => /^recording-.*\\.json$/.test(a.name));\n const inRecordings = new Set<string>();\n for (let n = 1; n <= recordings.length; n++) {\n const { kept, id } = await loadRecording(ref, n);\n for (const c of kept.voice ?? []) {\n inRecordings.add(c.id);\n clips.push({ id: c.id, file: voiceFile(c.id, root), at: c.at, recording: id });\n }\n }\n for (const a of root.attachments) {\n const id = /^voice-(.+)\\.\\w+$/.exec(a.name)?.[1];\n if (id !== undefined && !inRecordings.has(id)) clips.push({ id, file: voiceFile(id, root), at: 0 });\n }\n } else if (!/^https?:/.test(ref) && !existsSync(ref) && keptClip(ref) !== undefined) {\n clips.push({ id: ref, file: voiceFile(ref), at: 0 });\n } else {\n const { kept, id } = await loadRecording(ref);\n for (const c of kept.voice ?? []) clips.push({ id: c.id, file: voiceFile(c.id), at: c.at, recording: id });\n }\n if (clips.length === 0) fail(`No voice on ${ref}.`);\n return clips;\n}\n\n/** Runs ffmpeg, which reads what MediaRecorder makes, and answers its log (stderr) and what it wrote to stdout. */\nexport function ffmpeg(args: string[]): { stdout: Buffer; log: string } {\n const run = spawnSync('ffmpeg', ['-hide_banner', '-nostats', ...args], { maxBuffer: 1 << 30 });\n if (run.error) fail('Needs ffmpeg on the PATH (https://ffmpeg.org/download.html).');\n return { stdout: run.stdout, log: run.stderr.toString('utf8') };\n}\n\n/** The project's own copy of a package deictic doesn't bring (Playwright, either of its names), from here. */\nexport async function fromProject<T>(...names: string[]): Promise<T> {\n const project = createRequire(join(process.cwd(), 'package.json'));\n for (const name of names) {\n try {\n const module = (await import(pathToFileURL(project.resolve(name)).href)) as Record<string, unknown>;\n // A CommonJS package whose exports Node can't name, as playwright-core's `module.exports = require(…)`, has\n // them on `default` alone.\n const exported = module.default;\n return (typeof exported === 'object' && exported !== null ? { ...exported, ...module } : module) as T;\n } catch {\n // Not this one: the next name.\n }\n }\n return fail(`Needs ${names.join(' or ')} in the project: npm install -D ${names[0]}`);\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAM,OAAO;AAWb,MAAM,UAAU,SAAiB,KAAK,MAAM,aAAa,MAAM,MAAM,CAAC;;AAGtE,SAAS,QAAQ,MAAe,MAAsB;CACpD,MAAM,OAAO,KAAK,YAAY,MAAM,MAAM,EAAE,SAAS,IAAI;CACzD,IAAI,SAAS,KAAA,GAAW,KAAK,SAAS,KAAK,GAAG,UAAU,KAAK,EAAE;CAC/D,MAAM,OAAO,KAAK,YAAY,KAAK,OAAO,GAAG,UAAU,CAAC,GAAG,KAAK,IAAI;CACpE,SAAS,MAAM,IAAI;CACnB,OAAO;AACT;;;;;AAMA,eAAsB,cAAc,KAAyB,MAAM,GAAmB;CACpF,IAAI,QAAQ,KAAA,GAAW,KAAK,6EAA6E;CACzG,IAAI,KAAK,KAAK,GAAG,GAAG;EAClB,MAAM,OAAO,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c,CAAC;CACjE,KAAK,MAAM,QAAQ,OACjB,IAAI;EACF,MAAM,SAAU,MAAM,OAAO,cAAc,QAAQ,QAAQ,IAAI,CAAC,CAAC,CAAC;EAGlE,MAAM,WAAW,OAAO;EACxB,OAAQ,OAAO,aAAa,YAAY,aAAa,OAAO;GAAE,GAAG;GAAU,GAAG;EAAO,IAAI;CAC3F,QAAQ,CAER;CAEF,OAAO,KAAK,SAAS,MAAM,KAAK,MAAM,EAAE,kCAAkC,MAAM,IAAI;AACtF"}
@@ -24,6 +24,7 @@ async function run(ref, values) {
24
24
  mkdirSync(out, { recursive: true });
25
25
  const playwright = await fromProject("playwright-core", "playwright");
26
26
  let browser;
27
+ const tried = [];
27
28
  for (const channel of [
28
29
  void 0,
29
30
  "chrome",
@@ -31,8 +32,10 @@ async function run(ref, values) {
31
32
  ]) try {
32
33
  browser = await playwright.chromium.launch(channel === void 0 ? {} : { channel });
33
34
  break;
34
- } catch {}
35
- if (browser === void 0) fail("No Chromium to launch: npx playwright install chromium, or install Chrome or Edge.");
35
+ } catch (e) {
36
+ tried.push(`${channel ?? "Playwright's Chromium"}: ${(e instanceof Error ? e.message : String(e)).split("\n", 1)[0]}`);
37
+ }
38
+ if (browser === void 0) fail(`No Chromium to launch (${tried.join("; ")}): npx playwright install chromium, or install Chrome or Edge.`);
36
39
  try {
37
40
  const view = await browser.newPage({ viewport: kept.viewport });
38
41
  for (const t of times) {
@@ -1 +1 @@
1
- {"version":3,"file":"frame.js","names":[],"sources":["../../src/cli/frame.ts"],"sourcesContent":["/**\n * `deictic frame`: screenshots of a recording at moments of it, as its replay page shows them (marks and pointer\n * included), at the recorded viewport's size. By default: just after each change to the marks, and the end. Needs\n * the dev server running (it serves the replay) and Playwright in the project.\n */\nimport { mkdirSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { join, resolve } from 'node:path';\n\nimport type { Browser, chromium } from 'playwright-core';\n\nimport { clock, fail } from './board.ts';\nimport { fromProject, loadRecording } from './find.ts';\n\ninterface Marks {\n type: number;\n timestamp: number;\n data: { tag?: string; payload?: { svg?: string } };\n}\n\nexport async function run(ref: string, values: { nth: string; at?: string[]; every?: string; out?: string; base?: string }): Promise<void> {\n const { kept, id, replay } = await loadRecording(ref, Number(values.nth));\n // The replay is served by the dev server that recorded it, under deictic's routes.\n const page =\n values.base === undefined\n ? (replay ?? `${new URL(kept.page).origin}/__deictic/plugins/recordings/replay/${id}`)\n : `${values.base.replace(/\\/$/, '')}/__deictic/plugins/recordings/replay/${id}`;\n\n const events = kept.events as Marks[];\n const t0 = events[0]?.timestamp ?? 0;\n const end = kept.duration / 1000;\n let times = (values.at ?? []).map(Number);\n if (values.every !== undefined) for (let t = 0; t <= end; t += Number(values.every)) times.push(t);\n if (times.length === 0) {\n // Just after each change to the marks, so it's drawn, then the end.\n const marks = events.filter((e) => e.type === 5 && e.data.tag === 'deictic.annotations' && (e.data.payload?.svg ?? '') !== '');\n times = [...marks.map((e) => (e.timestamp - t0 + 50) / 1000), end];\n }\n times = [...new Set(times.map((t) => Math.min(Math.max(0, t), end)))].sort((a, b) => a - b);\n if (times.some((t) => !Number.isFinite(t))) fail('--at and --every take seconds: --at 4.2');\n\n const out = resolve(values.out ?? join(tmpdir(), 'deictic-frames', id));\n mkdirSync(out, { recursive: true });\n\n const playwright = await fromProject<{ chromium: typeof chromium }>('playwright-core', 'playwright');\n let browser: Browser | undefined;\n for (const channel of [undefined, 'chrome', 'msedge']) {\n try {\n browser = await playwright.chromium.launch(channel === undefined ? {} : { channel });\n break;\n } catch {\n // Not this one: the next.\n }\n }\n if (browser === undefined) fail('No Chromium to launch: npx playwright install chromium, or install Chrome or Edge.');\n try {\n // `bare`: the replay alone, at the recorded size, so a window that size shows it 1:1.\n const view = await browser.newPage({ viewport: kept.viewport });\n for (const t of times) {\n const url = new URL(page);\n url.searchParams.set('t', t.toFixed(2));\n url.searchParams.set('bare', '');\n const res = await view.goto(url.href).catch((e: unknown) => (e instanceof Error ? e.message.split('\\n')[0] : String(e)));\n if (typeof res === 'string' || !res?.ok()) {\n const why = typeof res === 'string' ? res : String(res?.status());\n await browser.close();\n fail(`${url.href}: ${why}. Is the dev server running? Start it, or pass --base with its URL.`);\n }\n await view.waitForSelector('body[data-ready]', { timeout: 15_000 });\n // The replayed page's images and fonts.\n await view.waitForLoadState('networkidle').catch(() => {});\n await view.waitForTimeout(200);\n const path = join(out, `${String(Math.round(t * 1000)).padStart(6, '0')}.png`);\n await view.screenshot({ path });\n console.log(`${clock(t * 1000).padStart(6)} ${path}`);\n }\n } finally {\n await browser.close();\n }\n}\n"],"mappings":";;;;;;;;;;;AAoBA,eAAsB,IAAI,KAAa,QAAoG;CACzI,MAAM,EAAE,MAAM,IAAI,WAAW,MAAM,cAAc,KAAK,OAAO,OAAO,GAAG,CAAC;CAExE,MAAM,OACJ,OAAO,SAAS,KAAA,IACX,UAAU,GAAG,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,OAAO,uCAAuC,OAC/E,GAAG,OAAO,KAAK,QAAQ,OAAO,EAAE,EAAE,uCAAuC;CAE/E,MAAM,SAAS,KAAK;CACpB,MAAM,KAAK,OAAO,EAAE,EAAE,aAAa;CACnC,MAAM,MAAM,KAAK,WAAW;CAC5B,IAAI,SAAS,OAAO,MAAM,CAAC,EAAA,CAAG,IAAI,MAAM;CACxC,IAAI,OAAO,UAAU,KAAA,GAAW,KAAK,IAAI,IAAI,GAAG,KAAK,KAAK,KAAK,OAAO,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;CACjG,IAAI,MAAM,WAAW,GAGnB,QAAQ,CAAC,GADK,OAAO,QAAQ,MAAM,EAAE,SAAS,KAAK,EAAE,KAAK,QAAQ,0BAA0B,EAAE,KAAK,SAAS,OAAO,QAAQ,EAC3G,CAAC,CAAC,KAAK,OAAO,EAAE,YAAY,KAAK,MAAM,GAAI,GAAG,GAAG;CAEnE,QAAQ,CAAC,GAAG,IAAI,IAAI,MAAM,KAAK,MAAM,KAAK,IAAI,KAAK,IAAI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K,iBAAiB,aAAa,CAAC,CAAC,YAAY,CAAC,CAAC;GACzD,MAAM,KAAK,eAAe,GAAG;GAC7B,MAAM,OAAO,KAAK,KAAK,GAAG,OAAO,KAAK,MAAM,IAAI,GAAI,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG,EAAE,KAAK;GAC7E,MAAM,KAAK,WAAW,EAAE,KAAK,CAAC;GAC9B,QAAQ,IAAI,GAAG,MAAM,IAAI,GAAI,CAAC,CAAC,SAAS,CAAC,EAAE,IAAI,MAAM;EACvD;CACF,UAAU;EACR,MAAM,QAAQ,MAAM;CACtB;AACF"}
1
+ {"version":3,"file":"frame.js","names":[],"sources":["../../src/cli/frame.ts"],"sourcesContent":["/**\n * `deictic frame`: screenshots of a recording at moments of it, as its replay page shows them (marks and pointer\n * included), at the recorded viewport's size. By default: just after each change to the marks, and the end. Needs\n * the dev server running (it serves the replay) and Playwright in the project.\n */\nimport { mkdirSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { join, resolve } from 'node:path';\n\nimport type { Browser, chromium } from 'playwright-core';\n\nimport { clock, fail } from './board.ts';\nimport { fromProject, loadRecording } from './find.ts';\n\ninterface Marks {\n type: number;\n timestamp: number;\n data: { tag?: string; payload?: { svg?: string } };\n}\n\nexport async function run(ref: string, values: { nth: string; at?: string[]; every?: string; out?: string; base?: string }): Promise<void> {\n const { kept, id, replay } = await loadRecording(ref, Number(values.nth));\n // The replay is served by the dev server that recorded it, under deictic's routes.\n const page =\n values.base === undefined\n ? (replay ?? `${new URL(kept.page).origin}/__deictic/plugins/recordings/replay/${id}`)\n : `${values.base.replace(/\\/$/, '')}/__deictic/plugins/recordings/replay/${id}`;\n\n const events = kept.events as Marks[];\n const t0 = events[0]?.timestamp ?? 0;\n const end = kept.duration / 1000;\n let times = (values.at ?? []).map(Number);\n if (values.every !== undefined) for (let t = 0; t <= end; t += Number(values.every)) times.push(t);\n if (times.length === 0) {\n // Just after each change to the marks, so it's drawn, then the end.\n const marks = events.filter((e) => e.type === 5 && e.data.tag === 'deictic.annotations' && (e.data.payload?.svg ?? '') !== '');\n times = [...marks.map((e) => (e.timestamp - t0 + 50) / 1000), end];\n }\n times = [...new Set(times.map((t) => Math.min(Math.max(0, t), end)))].sort((a, b) => a - b);\n if (times.some((t) => !Number.isFinite(t))) fail('--at and --every take seconds: --at 4.2');\n\n const out = resolve(values.out ?? join(tmpdir(), 'deictic-frames', id));\n mkdirSync(out, { recursive: true });\n\n const playwright = await fromProject<{ chromium: typeof chromium }>('playwright-core', 'playwright');\n let browser: Browser | undefined;\n // Why each browser didn't launch, said where none did.\n const tried: string[] = [];\n for (const channel of [undefined, 'chrome', 'msedge']) {\n try {\n browser = await playwright.chromium.launch(channel === undefined ? {} : { channel });\n break;\n } catch (e) {\n tried.push(`${channel ?? \"Playwright's Chromium\"}: ${(e instanceof Error ? e.message : String(e)).split('\\n', 1)[0]}`);\n }\n }\n if (browser === undefined)\n fail(`No Chromium to launch (${tried.join('; ')}): npx playwright install chromium, or install Chrome or Edge.`);\n try {\n // `bare`: the replay alone, at the recorded size, so a window that size shows it 1:1.\n const view = await browser.newPage({ viewport: kept.viewport });\n for (const t of times) {\n const url = new URL(page);\n url.searchParams.set('t', t.toFixed(2));\n url.searchParams.set('bare', '');\n const res = await view.goto(url.href).catch((e: unknown) => (e instanceof Error ? e.message.split('\\n')[0] : String(e)));\n if (typeof res === 'string' || !res?.ok()) {\n const why = typeof res === 'string' ? res : String(res?.status());\n await browser.close();\n fail(`${url.href}: ${why}. Is the dev server running? Start it, or pass --base with its URL.`);\n }\n await view.waitForSelector('body[data-ready]', { timeout: 15_000 });\n // The replayed page's images and fonts.\n await view.waitForLoadState('networkidle').catch(() => {});\n await view.waitForTimeout(200);\n const path = join(out, `${String(Math.round(t * 1000)).padStart(6, '0')}.png`);\n await view.screenshot({ path });\n console.log(`${clock(t * 1000).padStart(6)} ${path}`);\n }\n } finally {\n await browser.close();\n }\n}\n"],"mappings":";;;;;;;;;;;AAoBA,eAAsB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AAM,KAAK,WAAW,EAAE,KAAK,CAAC;GAC9B,QAAQ,IAAI,GAAG,MAAM,IAAI,GAAI,CAAC,CAAC,SAAS,CAAC,EAAE,IAAI,MAAM;EACvD;CACF,UAAU;EACR,MAAM,QAAQ,MAAM;CACtB;AACF"}
@@ -1,6 +1,6 @@
1
1
  // package.json
2
2
  var name = "deictic";
3
- var version = "0.8.0";
3
+ var version = "0.8.1";
4
4
  var bugs = { "url": "https://github.com/gkurt/deictic/issues" };
5
5
  var peerDependencies = {
6
6
  "@rrweb/rrweb-plugin-console-record": "^2.2.2",
@@ -1,4 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
+ import { t as CANVAS_SIZE } from "./canvas.js";
2
3
  // src/plugins/screenshots/playwright.ts
3
4
  /**
4
5
  * The `rrweb()` renderer's server half: rebuilds a page's snapshot in a browser beside the dev server and
@@ -75,7 +76,11 @@ async function render(input, options) {
75
76
  }));
76
77
  await page.goto(host);
77
78
  await page.addScriptTag({ path: bundle() });
78
- const found = await page.evaluate(async ({ snapshot, scroll, overlay, element }) => {
79
+ const given = {
80
+ ...shot,
81
+ size: CANVAS_SIZE
82
+ };
83
+ const found = await page.evaluate(async ({ snapshot, scroll, overlay, element, size }) => {
79
84
  const { rebuildIntoSandboxedIframe, createCache, createMirror } = globalThis.rrwebSnapshot;
80
85
  const mirror = createMirror();
81
86
  const { iframe } = rebuildIntoSandboxedIframe(snapshot, {
@@ -86,6 +91,20 @@ async function render(input, options) {
86
91
  });
87
92
  const doc = iframe.contentDocument;
88
93
  if (doc === null) throw new Error("screenshots: the snapshot was rebuilt where it cannot be read");
94
+ const isElement = (node) => node?.nodeType === 1;
95
+ const hidden = doc.createElement("style");
96
+ hidden.textContent = "noscript { display: none !important; }";
97
+ doc.head.append(hidden);
98
+ for (const canvas of doc.querySelectorAll(`canvas[${size}]`)) {
99
+ const meta = mirror.getMeta(canvas);
100
+ const [box, inline] = (canvas.getAttribute(size) ?? "").split(" ");
101
+ const [width, height] = (box ?? "").split("x");
102
+ if (meta === null || !("attributes" in meta) || typeof meta.attributes.rr_dataURL !== "string") continue;
103
+ const picture = doc.createElement("img");
104
+ picture.src = meta.attributes.rr_dataURL;
105
+ picture.style.cssText = `display:${inline === void 0 ? "block" : "inline"};width:${width}px;height:${height}px`;
106
+ canvas.replaceChildren(picture);
107
+ }
89
108
  await doc.fonts.ready;
90
109
  await Promise.all([...doc.images].map((img) => img.decode().catch(() => {})));
91
110
  iframe.contentWindow?.scrollTo({
@@ -93,7 +112,6 @@ async function render(input, options) {
93
112
  top: scroll.y,
94
113
  behavior: "instant"
95
114
  });
96
- const isElement = (node) => node?.nodeType === 1;
97
115
  for (const id of mirror.getIds()) {
98
116
  const node = mirror.getNode(id);
99
117
  const meta = node === null ? null : mirror.getMeta(node);
@@ -120,7 +138,7 @@ async function render(input, options) {
120
138
  marks.innerHTML = overlay;
121
139
  document.body.append(marks);
122
140
  return box;
123
- }, shot);
141
+ }, given);
124
142
  const clip = clamp(shot.clip === void 0 ? {
125
143
  x: 0,
126
144
  y: 0,
@@ -1 +1 @@
1
- {"version":3,"file":"playwright.js","names":[],"sources":["../../src/plugins/screenshots/playwright.ts"],"sourcesContent":["/**\n * The `rrweb()` renderer's server half: rebuilds a page's snapshot in a browser beside the dev server and\n * screenshots it at the page's viewport, scroll and pixel density, so text lays out as the page's does. The\n * browser is launched on the first shot and kept for the next; Playwright closes it with the process.\n *\n * The snapshot is rebuilt into a sandboxed iframe filling a blank page on the page's own origin, which\n * Playwright answers itself, so nothing asks the dev server for it: rrweb has made the snapshot's URLs\n * whole, and its stylesheets' fonts and images load from the dev server as the page's did.\n *\n * The browser is as big as the page's window, scrollbars and all, and shows its own: a media query asks the\n * window's width, and the page is laid out in what the scrollbar leaves. At the width without it, a window\n * right on a breakpoint (1024 wide, 1009 to lay out in) would render as the narrower layout. The shot is then\n * cut to the part the page is in.\n */\nimport { createRequire } from 'node:module';\n\nimport type { Browser } from 'playwright-core';\nimport type * as Rrweb from 'rrweb-snapshot';\n\nimport type { Box, BrowserOptions } from './index.ts';\n\n/** What the page sends: its snapshot and what's needed to show it as the page does. */\n/** A node of an rrweb snapshot, as `snapshot()` answers it. */\nexport type SnapshotNode = NonNullable<ReturnType<typeof Rrweb.snapshot>>;\n\nexport interface Snapshot {\n snapshot: SnapshotNode;\n url: string;\n viewport: { width: number; height: number };\n /** The window's size, scrollbars included, where it has any: what the page's media queries ask. */\n window?: { width: number; height: number };\n scroll: { x: number; y: number };\n scale: number;\n /** The element the shot is of, as the snapshot numbers its nodes: found again in the rebuilt page, for where it is there. */\n element?: number;\n /** The part of the viewport to keep, for a shot of an element alone: where the element was in the page. */\n clip?: Box;\n /** An SVG the viewport's size, drawn over the page: the annotations, where there are any. */\n overlay?: string;\n}\n\nconst HOST = '<!doctype html><html><body style=\"margin:0\"></body></html>';\n\nconst browsers = new Map<string, Promise<Browser>>();\n\n/** A browser by the options, launched once: the one named, or Playwright's own Chromium, then Chrome, then Edge. */\nexport function browserOf(options: BrowserOptions): Promise<Browser> {\n const key = JSON.stringify(options);\n const known = browsers.get(key);\n if (known !== undefined) return known;\n const launched = launch(options);\n browsers.set(key, launched);\n // A launch that failed is tried again on the next shot, after the user installs what it said to.\n launched.catch(() => browsers.delete(key));\n return launched;\n}\n\n/** Playwright hides a headless browser's scrollbars, and with them the room they take in the page. */\nconst SCROLLBARS = { ignoreDefaultArgs: ['--hide-scrollbars'] };\n\nasync function launch({ executablePath, channel }: BrowserOptions): Promise<Browser> {\n const { chromium } = await import('playwright-core').catch((e: unknown) => {\n throw new Error('the rrweb() renderer needs playwright-core: add it to your devDependencies', { cause: e });\n });\n if (executablePath !== undefined || channel !== undefined) return chromium.launch({ executablePath, channel, ...SCROLLBARS });\n const tried: string[] = [];\n for (const attempt of [{}, { channel: 'chrome' }, { channel: 'msedge' }]) {\n try {\n return await chromium.launch({ ...attempt, ...SCROLLBARS });\n } catch (e) {\n tried.push(\n `${'channel' in attempt ? attempt.channel : \"Playwright's Chromium\"}: ${(e instanceof Error ? e.message : String(e)).split('\\n', 1)[0]}`,\n );\n }\n }\n throw new Error(\n `the rrweb() renderer found no browser to render in (${tried.join('; ')}): run \\`npx playwright install chromium\\`, or pass rrweb({ executablePath })`,\n );\n}\n\n/** The rrweb-snapshot bundle that defines `rrwebSnapshot` in a page: its CommonJS entry is that bundle. */\nconst bundle = () => createRequire(import.meta.url).resolve('rrweb-snapshot');\n\n/**\n * The PNG, and where the element is in it. That's measured in the rebuilt page, not taken from the live one: the\n * two can lay out a few pixels apart (a font that loaded differently, a panel's own scroll), and an outline drawn\n * at the live page's box would then cross the element.\n */\nexport async function render(input: unknown, options: BrowserOptions): Promise<{ png: Uint8Array; box?: Box }> {\n const shot = input as Snapshot;\n if (typeof shot?.url !== 'string' || typeof shot.snapshot !== 'object' || typeof shot.viewport?.width !== 'number')\n throw new Error('screenshots: that is not a snapshot the rrweb() renderer took');\n const browser = await browserOf(options);\n const context = await browser.newContext({ viewport: shot.window ?? shot.viewport, deviceScaleFactor: shot.scale });\n try {\n const page = await context.newPage();\n const host = new URL('/__deictic/plugins/screenshots/host', shot.url).href;\n await page.route(host, (route) => route.fulfill({ contentType: 'text/html', body: HOST }));\n await page.goto(host);\n await page.addScriptTag({ path: bundle() });\n const found = await page.evaluate(async ({ snapshot, scroll, overlay, element }) => {\n const { rebuildIntoSandboxedIframe, createCache, createMirror } = (globalThis as unknown as { rrwebSnapshot: typeof Rrweb })\n .rrwebSnapshot;\n const mirror = createMirror();\n const { iframe } = rebuildIntoSandboxedIframe(snapshot, {\n root: document.body,\n cache: createCache(),\n mirror,\n iframeAttributes: { style: 'border:0;position:fixed;inset:0;width:100vw;height:100vh' },\n });\n const doc = iframe.contentDocument;\n if (doc === null) throw new Error('screenshots: the snapshot was rebuilt where it cannot be read');\n await doc.fonts.ready;\n await Promise.all([...doc.images].map((img) => img.decode().catch(() => {})));\n // At once: a page with `scroll-behavior: smooth` would glide there, and be shot on its way.\n iframe.contentWindow?.scrollTo({ left: scroll.x, top: scroll.y, behavior: 'instant' });\n // rrweb scrolled each element as it built it, before the fonts and images gave its content its height:\n // one that couldn't scroll that far yet is scrolled again now.\n // By its kind: the iframe's elements aren't instances of this page's `Element`.\n const isElement = (node: Node | null): node is Element => node?.nodeType === 1;\n for (const id of mirror.getIds()) {\n const node = mirror.getNode(id);\n const meta = node === null ? null : mirror.getMeta(node);\n if (!isElement(node) || meta === null || !('attributes' in meta)) continue;\n const { rr_scrollTop: top, rr_scrollLeft: left } = meta.attributes;\n if (typeof top !== 'number' && typeof left !== 'number') continue;\n node.scrollTo({\n top: typeof top === 'number' ? top : node.scrollTop,\n left: typeof left === 'number' ? left : node.scrollLeft,\n behavior: 'instant',\n });\n }\n const node = element === undefined ? null : mirror.getNode(element);\n // The iframe fills the page from its top left, so a box in it is one in the shot.\n const rect = isElement(node) ? node.getBoundingClientRect() : undefined;\n const box = rect === undefined ? undefined : { x: rect.x, y: rect.y, width: rect.width, height: rect.height };\n if (overlay === undefined) return box;\n // Over the page and its scroll: the SVG is the viewport's, already where it scrolled to.\n const marks = document.createElement('div');\n marks.style.cssText = 'position:fixed;inset:0;z-index:1;pointer-events:none';\n marks.innerHTML = overlay;\n document.body.append(marks);\n return box;\n }, shot);\n // Without the scrollbars: a shot is what the page is drawn in, which is what an element's box is from.\n // A shot of the element alone is cut where the element is here.\n const clip = clamp(shot.clip === undefined ? { x: 0, y: 0, ...shot.viewport } : (found ?? shot.clip), shot.viewport);\n const png = new Uint8Array(await page.screenshot({ type: 'png', ...(clip === undefined ? {} : { clip }) }));\n return { png, ...(found === undefined || shot.clip !== undefined ? {} : { box: found }) };\n } finally {\n await context.close();\n }\n}\n\n/** A box kept within the viewport: an element partly scrolled out of it shows only the part that's in. */\nfunction clamp(box: Box, viewport: { width: number; height: number }): Box | undefined {\n const x = Math.max(0, box.x);\n const y = Math.max(0, box.y);\n const width = Math.min(viewport.width, box.x + box.width) - x;\n const height = Math.min(viewport.height, box.y + box.height) - y;\n return width > 0 && height > 0 ? { x,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AAM,KAAU,UAA8D;CACrF,MAAM,IAAI,KAAK,IAAI,GAAG,IAAI,CAAC;CAC3B,MAAM,IAAI,KAAK,IAAI,GAAG,IAAI,CAAC;CAC3B,MAAM,QAAQ,KAAK,IAAI,SAAS,OAAO,IAAI,IAAI,IAAI,KAAK,IAAI;CAC5D,MAAM,SAAS,KAAK,IAAI,SAAS,QAAQ,IAAI,IAAI,IAAI,MAAM,IAAI;CAC/D,OAAO,QAAQ,KAAK,SAAS,IAAI;EAAE;EAAG;EAAG;EAAO;CAAO,IAAI,KAAA;AAC7D"}
1
+ {"version":3,"file":"playwright.js","names":[],"sources":["../../src/plugins/screenshots/playwright.ts"],"sourcesContent":["/**\n * The `rrweb()` renderer's server half: rebuilds a page's snapshot in a browser beside the dev server and\n * screenshots it at the page's viewport, scroll and pixel density, so text lays out as the page's does. The\n * browser is launched on the first shot and kept for the next; Playwright closes it with the process.\n *\n * The snapshot is rebuilt into a sandboxed iframe filling a blank page on the page's own origin, which\n * Playwright answers itself, so nothing asks the dev server for it: rrweb has made the snapshot's URLs\n * whole, and its stylesheets' fonts and images load from the dev server as the page's did.\n *\n * The browser is as big as the page's window, scrollbars and all, and shows its own: a media query asks the\n * window's width, and the page is laid out in what the scrollbar leaves. At the width without it, a window\n * right on a breakpoint (1024 wide, 1009 to lay out in) would render as the narrower layout. The shot is then\n * cut to the part the page is in.\n */\nimport { createRequire } from 'node:module';\n\nimport type { Browser } from 'playwright-core';\nimport type * as Rrweb from 'rrweb-snapshot';\n\nimport { CANVAS_SIZE } from './canvas.ts';\nimport type { Box, BrowserOptions } from './index.ts';\n\n/** What the page sends: its snapshot and what's needed to show it as the page does. */\n/** A node of an rrweb snapshot, as `snapshot()` answers it. */\nexport type SnapshotNode = NonNullable<ReturnType<typeof Rrweb.snapshot>>;\n\nexport interface Snapshot {\n snapshot: SnapshotNode;\n url: string;\n viewport: { width: number; height: number };\n /** The window's size, scrollbars included, where it has any: what the page's media queries ask. */\n window?: { width: number; height: number };\n scroll: { x: number; y: number };\n scale: number;\n /** The element the shot is of, as the snapshot numbers its nodes: found again in the rebuilt page, for where it is there. */\n element?: number;\n /** The part of the viewport to keep, for a shot of an element alone: where the element was in the page. */\n clip?: Box;\n /** An SVG the viewport's size, drawn over the page: the annotations, where there are any. */\n overlay?: string;\n}\n\nconst HOST = '<!doctype html><html><body style=\"margin:0\"></body></html>';\n\nconst browsers = new Map<string, Promise<Browser>>();\n\n/** A browser by the options, launched once: the one named, or Playwright's own Chromium, then Chrome, then Edge. */\nexport function browserOf(options: BrowserOptions): Promise<Browser> {\n const key = JSON.stringify(options);\n const known = browsers.get(key);\n if (known !== undefined) return known;\n const launched = launch(options);\n browsers.set(key, launched);\n // A launch that failed is tried again on the next shot, after the user installs what it said to.\n launched.catch(() => browsers.delete(key));\n return launched;\n}\n\n/** Playwright hides a headless browser's scrollbars, and with them the room they take in the page. */\nconst SCROLLBARS = { ignoreDefaultArgs: ['--hide-scrollbars'] };\n\nasync function launch({ executablePath, channel }: BrowserOptions): Promise<Browser> {\n const { chromium } = await import('playwright-core').catch((e: unknown) => {\n throw new Error('the rrweb() renderer needs playwright-core: add it to your devDependencies', { cause: e });\n });\n if (executablePath !== undefined || channel !== undefined) return chromium.launch({ executablePath, channel, ...SCROLLBARS });\n const tried: string[] = [];\n for (const attempt of [{}, { channel: 'chrome' }, { channel: 'msedge' }]) {\n try {\n return await chromium.launch({ ...attempt, ...SCROLLBARS });\n } catch (e) {\n tried.push(\n `${'channel' in attempt ? attempt.channel : \"Playwright's Chromium\"}: ${(e instanceof Error ? e.message : String(e)).split('\\n', 1)[0]}`,\n );\n }\n }\n throw new Error(\n `the rrweb() renderer found no browser to render in (${tried.join('; ')}): run \\`npx playwright install chromium\\`, or pass rrweb({ executablePath })`,\n );\n}\n\n/** The rrweb-snapshot bundle that defines `rrwebSnapshot` in a page: its CommonJS entry is that bundle. */\nconst bundle = () => createRequire(import.meta.url).resolve('rrweb-snapshot');\n\n/**\n * The PNG, and where the element is in it. That's measured in the rebuilt page, not taken from the live one: the\n * two can lay out a few pixels apart (a font that loaded differently, a panel's own scroll), and an outline drawn\n * at the live page's box would then cross the element.\n */\nexport async function render(input: unknown, options: BrowserOptions): Promise<{ png: Uint8Array; box?: Box }> {\n const shot = input as Snapshot;\n if (typeof shot?.url !== 'string' || typeof shot.snapshot !== 'object' || typeof shot.viewport?.width !== 'number')\n throw new Error('screenshots: that is not a snapshot the rrweb() renderer took');\n const browser = await browserOf(options);\n const context = await browser.newContext({ viewport: shot.window ?? shot.viewport, deviceScaleFactor: shot.scale });\n try {\n const page = await context.newPage();\n const host = new URL('/__deictic/plugins/screenshots/host', shot.url).href;\n await page.route(host, (route) => route.fulfill({ contentType: 'text/html', body: HOST }));\n await page.goto(host);\n await page.addScriptTag({ path: bundle() });\n // The shot, and the attribute that sizes each canvas's picture, which the page's code can't import.\n const given = { ...shot, size: CANVAS_SIZE };\n const found = await page.evaluate(async ({ snapshot, scroll, overlay, element, size }) => {\n const { rebuildIntoSandboxedIframe, createCache, createMirror } = (globalThis as unknown as { rrwebSnapshot: typeof Rrweb })\n .rrwebSnapshot;\n const mirror = createMirror();\n const { iframe } = rebuildIntoSandboxedIframe(snapshot, {\n root: document.body,\n cache: createCache(),\n mirror,\n iframeAttributes: { style: 'border:0;position:fixed;inset:0;width:100vw;height:100vh' },\n });\n const doc = iframe.contentDocument;\n if (doc === null) throw new Error('screenshots: the snapshot was rebuilt where it cannot be read');\n // By its kind: the iframe's elements aren't instances of this page's `Element`.\n const isElement = (node: Node | null): node is Element => node?.nodeType === 1;\n // rrweb rebuilds a script as a `noscript` holding SCRIPT_PLACEHOLDER, which the sandbox, running no scripts,\n // shows: hidden, as rrweb's own replayer hides it.\n const hidden = doc.createElement('style');\n hidden.textContent = 'noscript { display: none !important; }';\n doc.head.append(hidden);\n // The sandbox runs no scripts, and where scripts don't run, a canvas shows what's inside the canvas instead of\n // what was drawn on the canvas: so each canvas's picture goes inside the canvas, at the size the page laid the\n // canvas out at. rrweb's own drawing of the picture on the canvas never shows.\n for (const canvas of doc.querySelectorAll(`canvas[${size}]`)) {\n const meta = mirror.getMeta(canvas);\n const [box, inline] = (canvas.getAttribute(size) ?? '').split(' ');\n const [width, height] = (box ?? '').split('x');\n if (meta === null || !('attributes' in meta) || typeof meta.attributes.rr_dataURL !== 'string') continue;\n const picture = doc.createElement('img');\n picture.src = meta.attributes.rr_dataURL;\n // In a line as the canvas was, else the whole of the canvas's box.\n picture.style.cssText = `display:${inline === undefined ? 'block' : 'inline'};width:${width}px;height:${height}px`;\n canvas.replaceChildren(picture);\n }\n await doc.fonts.ready;\n await Promise.all([...doc.images].map((img) => img.decode().catch(() => {})));\n // At once: a page with `scroll-behavior: smooth` would glide there, and be shot on its way.\n iframe.contentWindow?.scrollTo({ left: scroll.x, top: scroll.y, behavior: 'instant' });\n // rrweb scrolled each element as it built it, before the fonts and images gave its content its height:\n // one that couldn't scroll that far yet is scrolled again now.\n for (const id of mirror.getIds()) {\n const node = mirror.getNode(id);\n const meta = node === null ? null : mirror.getMeta(node);\n if (!isElement(node) || meta === null || !('attributes' in meta)) continue;\n const { rr_scrollTop: top, rr_scrollLeft: left } = meta.attributes;\n if (typeof top !== 'number' && typeof left !== 'number') continue;\n node.scrollTo({\n top: typeof top === 'number' ? top : node.scrollTop,\n left: typeof left === 'number' ? left : node.scrollLeft,\n behavior: 'instant',\n });\n }\n const node = element === undefined ? null : mirror.getNode(element);\n // The iframe fills the page from its top left, so a box in it is one in the shot.\n const rect = isElement(node) ? node.getBoundingClientRect() : undefined;\n const box = rect === undefined ? undefined : { x: rect.x, y: rect.y, width: rect.width, height: rect.height };\n if (overlay === undefined) return box;\n // Over the page and its scroll: the SVG is the viewport's, already where it scrolled to.\n const marks = document.createElement('div');\n marks.style.cssText = 'position:fixed;inset:0;z-index:1;pointer-events:none';\n marks.innerHTML = overlay;\n document.body.append(marks);\n return box;\n }, given);\n // Without the scrollbars: a shot is what the page is drawn in, which is what an element's box is from.\n // A shot of the element alone is cut where the element is here.\n const clip = clamp(shot.clip === undefined ? { x: 0, y: 0, ...shot.viewport } : (found ?? shot.clip), shot.viewport);\n const png = new Uint8Array(await page.screenshot({ type: 'png', ...(clip === undefined ? {} : { clip }) }));\n return { png, ...(found === undefined || shot.clip !== undefined ? {} : { box: found }) };\n } finally {\n await context.close();\n }\n}\n\n/** A box kept within the viewport: an element partly scrolled out of it shows only the part that's in. */\nfunction clamp(box: Box, viewport: { width: number; height: number }): Box | undefined {\n const x = Math.max(0, box.x);\n const y = Math.max(0, box.y);\n const width = Math.min(viewport.width, box.x + box.width) - x;\n const height = Math.min(viewport.height, box.y + box.height) - y;\n return width > 0 && height > 0 ? { x, y, width, height } : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0CA,MAAM,OAAO;AAEb,MAAM,2BAAW,IAAI,IAA8B;;AAGnD,SAAgB,UAAU,SAA2C;CACnE,MAAM,MAAM,KAAK,UAAU,OAAO;CAClC,MAAM,QAAQ,SAAS,IAAI,GAAG;CAC9B,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,MAAM,WAAW,OAAO,OAAO;CAC/B,SAAS,IAAI,KAAK,QAAQ;CAE1B,SAAS,YAAY,SAAS,OAAO,GAAG,CAAC;CACzC,OAAO;AACT;;AAGA,MAAM,aAAa,EAAE,mBAAmB,CAAC,mBAAmB,EAAE;AAE9D,eAAe,OAAO,EAAE,gBAAgB,WAA6C;CACnF,MAAM,EAAE,aAAa,MAAM,OAAO,kBAAkB,CAAC,OAAO,MAAe;EACzE,MAAM,IAAI,MAAM,8EAA8E,EAAE,OAAO,EAAE,CAAC;CAC5G,CAAC;CACD,IAAI,mBAAmB,KAAA,KAAa,YAAY,KAAA,GAAW,OAAO,SAAS,OAAO;EAAE;EAAgB;EAAS,GAAG;CAAW,CAAC;CAC5H,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,WAAW;EAAC,CAAC;EAAG,EAAE,SAAS,SAAS;EAAG,EAAE,SAAS,SAAS;CAAC,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,IAAI,IAAI,KAAK,IAAI;CAC5D,MAAM,SAAS,KAAK,IAAI,SAAS,QAAQ,IAAI,IAAI,IAAI,MAAM,IAAI;CAC/D,OAAO,QAAQ,KAAK,SAAS,IAAI;EAAE;EAAG;EAAG;EAAO;CAAO,IAAI,KAAA;AAC7D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deictic",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "Point at an element in your running app and leave a task about it for your agent.",
5
5
  "keywords": [
6
6
  "annotations",
package/src/cli/find.ts CHANGED
@@ -140,7 +140,11 @@ export async function fromProject<T>(...names: string[]): Promise<T> {
140
140
  const project = createRequire(join(process.cwd(), 'package.json'));
141
141
  for (const name of names) {
142
142
  try {
143
- return (await import(pathToFileURL(project.resolve(name)).href)) as T;
143
+ const module = (await import(pathToFileURL(project.resolve(name)).href)) as Record<string, unknown>;
144
+ // A CommonJS package whose exports Node can't name, as playwright-core's `module.exports = require(…)`, has
145
+ // them on `default` alone.
146
+ const exported = module.default;
147
+ return (typeof exported === 'object' && exported !== null ? { ...exported, ...module } : module) as T;
144
148
  } catch {
145
149
  // Not this one: the next name.
146
150
  }
package/src/cli/frame.ts CHANGED
@@ -44,15 +44,18 @@ export async function run(ref: string, values: { nth: string; at?: string[]; eve
44
44
 
45
45
  const playwright = await fromProject<{ chromium: typeof chromium }>('playwright-core', 'playwright');
46
46
  let browser: Browser | undefined;
47
+ // Why each browser didn't launch, said where none did.
48
+ const tried: string[] = [];
47
49
  for (const channel of [undefined, 'chrome', 'msedge']) {
48
50
  try {
49
51
  browser = await playwright.chromium.launch(channel === undefined ? {} : { channel });
50
52
  break;
51
- } catch {
52
- // Not this one: the next.
53
+ } catch (e) {
54
+ tried.push(`${channel ?? "Playwright's Chromium"}: ${(e instanceof Error ? e.message : String(e)).split('\n', 1)[0]}`);
53
55
  }
54
56
  }
55
- if (browser === undefined) fail('No Chromium to launch: npx playwright install chromium, or install Chrome or Edge.');
57
+ if (browser === undefined)
58
+ fail(`No Chromium to launch (${tried.join('; ')}): npx playwright install chromium, or install Chrome or Edge.`);
56
59
  try {
57
60
  // `bare`: the replay alone, at the recorded size, so a window that size shows it 1:1.
58
61
  const view = await browser.newPage({ viewport: kept.viewport });
@@ -0,0 +1,27 @@
1
+ /** What the rrweb() renderer's two halves share about canvases, with no imports, as the page half runs in the page. */
2
+
3
+ /**
4
+ * The attribute the page half gives each canvas with a picture: the canvas's size as the page lays it out, `WxH` in
5
+ * CSS pixels, then ` inline` where the canvas sits in a line of text, as which the server shows the picture.
6
+ */
7
+ export const CANVAS_SIZE = 'data-deictic-canvas-size';
8
+
9
+ /**
10
+ * Has each WebGL canvas the page makes from here on keep what the canvas drew, where the page doesn't say: a WebGL
11
+ * canvas otherwise reads back cleared once the canvas's frame shows, so a shot of a page that drew and went still
12
+ * would have the canvas blank. rrweb's recorder does the same while the recorder records canvases. A page that clears
13
+ * each frame draws the same either way. Self-contained, as the rrweb() renderer's test runs the function in a page as it is.
14
+ */
15
+ export function keepWebGLDrawing(): void {
16
+ if (typeof HTMLCanvasElement === 'undefined') return;
17
+ const proto = HTMLCanvasElement.prototype;
18
+ // The page's own `getContext`, called on each canvas as the canvas's own.
19
+ const original: unknown = Object.getOwnPropertyDescriptor(proto, 'getContext')?.value;
20
+ if (typeof original !== 'function') return;
21
+ proto.getContext = function (this: HTMLCanvasElement, type: string, options?: unknown) {
22
+ const given = typeof options === 'object' && options !== null ? (options as Record<string, unknown>) : {};
23
+ const webgl = type === 'webgl' || type === 'webgl2' || type === 'experimental-webgl';
24
+ const kept = webgl && given.preserveDrawingBuffer === undefined ? { ...given, preserveDrawingBuffer: true } : options;
25
+ return Reflect.apply(original, this, [type, kept]) as RenderingContext | null;
26
+ } as typeof HTMLCanvasElement.prototype.getContext;
27
+ }
@@ -17,6 +17,7 @@ import { createRequire } from 'node:module';
17
17
  import type { Browser } from 'playwright-core';
18
18
  import type * as Rrweb from 'rrweb-snapshot';
19
19
 
20
+ import { CANVAS_SIZE } from './canvas.ts';
20
21
  import type { Box, BrowserOptions } from './index.ts';
21
22
 
22
23
  /** What the page sends: its snapshot and what's needed to show it as the page does. */
@@ -98,7 +99,9 @@ export async function render(input: unknown, options: BrowserOptions): Promise<{
98
99
  await page.route(host, (route) => route.fulfill({ contentType: 'text/html', body: HOST }));
99
100
  await page.goto(host);
100
101
  await page.addScriptTag({ path: bundle() });
101
- const found = await page.evaluate(async ({ snapshot, scroll, overlay, element }) => {
102
+ // The shot, and the attribute that sizes each canvas's picture, which the page's code can't import.
103
+ const given = { ...shot, size: CANVAS_SIZE };
104
+ const found = await page.evaluate(async ({ snapshot, scroll, overlay, element, size }) => {
102
105
  const { rebuildIntoSandboxedIframe, createCache, createMirror } = (globalThis as unknown as { rrwebSnapshot: typeof Rrweb })
103
106
  .rrwebSnapshot;
104
107
  const mirror = createMirror();
@@ -110,14 +113,33 @@ export async function render(input: unknown, options: BrowserOptions): Promise<{
110
113
  });
111
114
  const doc = iframe.contentDocument;
112
115
  if (doc === null) throw new Error('screenshots: the snapshot was rebuilt where it cannot be read');
116
+ // By its kind: the iframe's elements aren't instances of this page's `Element`.
117
+ const isElement = (node: Node | null): node is Element => node?.nodeType === 1;
118
+ // rrweb rebuilds a script as a `noscript` holding SCRIPT_PLACEHOLDER, which the sandbox, running no scripts,
119
+ // shows: hidden, as rrweb's own replayer hides it.
120
+ const hidden = doc.createElement('style');
121
+ hidden.textContent = 'noscript { display: none !important; }';
122
+ doc.head.append(hidden);
123
+ // The sandbox runs no scripts, and where scripts don't run, a canvas shows what's inside the canvas instead of
124
+ // what was drawn on the canvas: so each canvas's picture goes inside the canvas, at the size the page laid the
125
+ // canvas out at. rrweb's own drawing of the picture on the canvas never shows.
126
+ for (const canvas of doc.querySelectorAll(`canvas[${size}]`)) {
127
+ const meta = mirror.getMeta(canvas);
128
+ const [box, inline] = (canvas.getAttribute(size) ?? '').split(' ');
129
+ const [width, height] = (box ?? '').split('x');
130
+ if (meta === null || !('attributes' in meta) || typeof meta.attributes.rr_dataURL !== 'string') continue;
131
+ const picture = doc.createElement('img');
132
+ picture.src = meta.attributes.rr_dataURL;
133
+ // In a line as the canvas was, else the whole of the canvas's box.
134
+ picture.style.cssText = `display:${inline === undefined ? 'block' : 'inline'};width:${width}px;height:${height}px`;
135
+ canvas.replaceChildren(picture);
136
+ }
113
137
  await doc.fonts.ready;
114
138
  await Promise.all([...doc.images].map((img) => img.decode().catch(() => {})));
115
139
  // At once: a page with `scroll-behavior: smooth` would glide there, and be shot on its way.
116
140
  iframe.contentWindow?.scrollTo({ left: scroll.x, top: scroll.y, behavior: 'instant' });
117
141
  // rrweb scrolled each element as it built it, before the fonts and images gave its content its height:
118
142
  // one that couldn't scroll that far yet is scrolled again now.
119
- // By its kind: the iframe's elements aren't instances of this page's `Element`.
120
- const isElement = (node: Node | null): node is Element => node?.nodeType === 1;
121
143
  for (const id of mirror.getIds()) {
122
144
  const node = mirror.getNode(id);
123
145
  const meta = node === null ? null : mirror.getMeta(node);
@@ -141,7 +163,7 @@ export async function render(input: unknown, options: BrowserOptions): Promise<{
141
163
  marks.innerHTML = overlay;
142
164
  document.body.append(marks);
143
165
  return box;
144
- }, shot);
166
+ }, given);
145
167
  // Without the scrollbars: a shot is what the page is drawn in, which is what an element's box is from.
146
168
  // A shot of the element alone is cut where the element is here.
147
169
  const clip = clamp(shot.clip === undefined ? { x: 0, y: 0, ...shot.viewport } : (found ?? shot.clip), shot.viewport);
@@ -5,9 +5,13 @@
5
5
  * And which node of the snapshot the element is, so the server says where it is in what it drew.
6
6
  */
7
7
 
8
+ import { CANVAS_SIZE, keepWebGLDrawing } from './canvas.ts';
8
9
  import { boxOf, screenshotsClient } from './client.ts';
9
10
  import type { Snapshot, SnapshotNode } from './playwright.ts';
10
11
 
12
+ // As the page loads, before the page makes its canvases.
13
+ keepWebGLDrawing();
14
+
11
15
  /** The snapshot without deictic's overlay, which rrweb has no option to leave out. */
12
16
  function withoutOurs(node: SnapshotNode): SnapshotNode {
13
17
  if (!('childNodes' in node)) return node;
@@ -20,16 +24,33 @@ export default screenshotsClient(async (element, { area, masking, overlay }) =>
20
24
  throw new Error('the rrweb() renderer needs rrweb-snapshot: add it to your devDependencies', { cause: e });
21
25
  });
22
26
  const mirror = createMirror();
23
- const taken = snapshot(document, {
24
- mirror,
25
- inlineStylesheet: true,
26
- blockClass: masking.blockClass,
27
- blockSelector: masking.blockSelector ?? null,
28
- maskTextClass: masking.maskTextClass,
29
- maskTextSelector: masking.maskTextSelector ?? null,
30
- maskAllInputs: masking.maskAllInputs,
31
- });
27
+ // In a frame, after the page drew in it: a WebGL canvas reads back blank once its frame is shown, unless the page
28
+ // keeps its drawing buffer, and the page's own callbacks for the frame were asked for before this one.
29
+ const taken = await new Promise<ReturnType<typeof snapshot>>((done) =>
30
+ requestAnimationFrame(() =>
31
+ done(
32
+ snapshot(document, {
33
+ mirror,
34
+ inlineStylesheet: true,
35
+ // A canvas as a picture of what it shows, which the server draws on the canvas it rebuilds.
36
+ recordCanvas: true,
37
+ blockClass: masking.blockClass,
38
+ blockSelector: masking.blockSelector ?? null,
39
+ maskTextClass: masking.maskTextClass,
40
+ maskTextSelector: masking.maskTextSelector ?? null,
41
+ maskAllInputs: masking.maskAllInputs,
42
+ }),
43
+ ),
44
+ ),
45
+ );
32
46
  if (taken === null) throw new Error('screenshots: rrweb took no snapshot of this page');
47
+ // Each canvas's size as the page lays it out, and whether in a line, as which the server shows the canvas's picture.
48
+ for (const canvas of document.querySelectorAll('canvas')) {
49
+ const node = mirror.getMeta(canvas);
50
+ if (node === null || !('attributes' in node) || typeof node.attributes.rr_dataURL !== 'string') continue;
51
+ const inline = getComputedStyle(canvas).display === 'inline';
52
+ node.attributes[CANVAS_SIZE] = `${canvas.offsetWidth}x${canvas.offsetHeight}${inline ? ' inline' : ''}`;
53
+ }
33
54
  const box = boxOf(element, area);
34
55
  const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };
35
56
  // Over the viewport, which the server renders before cutting out an element's part.