@mushi-mushi/web 1.28.0 → 1.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -127,20 +127,30 @@ The details step renders the attached screenshot as a visible preview (not just
127
127
  <details>
128
128
  <summary><b>Session replay</b> — opt-in rolling buffer attached on submit</summary>
129
129
 
130
+ ```bash
131
+ npm install rrweb # only for replay: 'rrweb' — your app installs it
132
+ ```
133
+
130
134
  ```typescript
131
135
  Mushi.init({
132
136
  projectId: 'proj_xxx',
133
137
  apiKey: 'mushi_xxx',
134
138
  capture: {
135
- // 'rrweb' — full DOM replay (lazy-loaded; text + inputs masked by default)
136
- // 'lite' — dependency-free coarse fallback
139
+ // 'rrweb' — full DOM replay (every text node and input masked)
140
+ // 'lite' — dependency-free, records clicks only
137
141
  // 'sentry'— reuse an installed @sentry/replay session
138
142
  // 'off' — default
139
143
  replay: 'rrweb',
144
+ // Hand the SDK your own import of rrweb.
145
+ rrweb: () => import('rrweb'),
140
146
  },
141
147
  });
142
148
  ```
143
149
 
150
+ `replay: 'rrweb'` needs `rrweb` in your app (`npm install rrweb`). It is an optional peer dependency, so apps that don't record replay don't download it.
151
+
152
+ `rrweb: () => import('rrweb')` is what makes `'rrweb'` mode work in a bundled app. The SDK cannot import rrweb itself: a published package's `import('rrweb')` is invisible to your bundler, so rrweb never reaches your build. An import written in your code is one your bundler sees, and it code-splits rrweb into its own chunk that loads only for sessions sampled into replay. Without the loader the SDK tries a global `rrweb` (the UMD build from a `<script>` tag), then a bare `import('rrweb')` (which resolves only under an import map); if neither works, it records clicks only (`'lite'`) and warns once in the console. The `rrweb` option ships in `@mushi-mushi/web` 1.29.
153
+
144
154
  Records continuously from init (so you capture the moments *before* the report), trimmed to a rolling window. Already on Sentry Replay? See [coexistence](https://kensaur.us/mushi-mushi/docs/sdks/sentry-replay-coexistence).
145
155
  </details>
146
156
 
@@ -152,13 +162,13 @@ const mushi = Mushi.init({ projectId: 'proj_xxx', apiKey: 'mushi_xxx' });
152
162
 
153
163
  mushi.identify('usr_42', { email: 'aya@example.com', segment: 'beta' });
154
164
  mushi.setTags({ plan: 'pro', region: 'apac' });
155
- mushi.addBreadcrumb({ category: 'business', message: 'cart.checkout_started', data: { itemCount: 3 } });
165
+ mushi.addBreadcrumb({ category: 'custom', level: 'info', message: 'cart.checkout_started', data: { itemCount: 3 } });
156
166
 
157
167
  try {
158
168
  await runCheckout();
159
169
  } catch (err) {
160
170
  // Normalises any throw, attaches breadcrumbs + sticky tags + Sentry context.
161
- mushi.captureException(err, { level: 'error', tags: { surface: 'checkout' } });
171
+ mushi.captureException(err, { severity: 'high', tags: { surface: 'checkout' } });
162
172
  }
163
173
  ```
164
174
 
@@ -171,6 +181,25 @@ try {
171
181
  The widget's "Your reports" tab lets reporters see team replies and respond, signed via HMAC against the public API key (no auth user required): `mushi.listMyReports()`, `mushi.listMyComments(id)`, `mushi.replyToReport(id, text)`. Call `mushi.identify()` and add a `rewards` block to track activity, tiers, and points. See [Rewards & contributor identity](https://kensaur.us/mushi-mushi/docs/concepts/rewards).
172
182
  </details>
173
183
 
184
+ <details>
185
+ <summary><b>Product analytics</b> — <code>track()</code>, funnels, paths and people in the same console</summary>
186
+
187
+ ```typescript
188
+ const mushi = Mushi.init({
189
+ projectId: 'proj_xxx',
190
+ apiKey: 'mushi_xxx',
191
+ // Optional. Defaults: enabled, consent 'implied', DNT/GPC respected, sampleRate 1.
192
+ analytics: { consent: 'required' },
193
+ });
194
+
195
+ mushi.setConsent('granted'); // only needed with consent: 'required'
196
+ mushi.track('checkout_started', { plan: 'pro' }); // snake_case names, flat properties
197
+ mushi.identify('usr_42'); // stitches earlier anonymous events to the person
198
+ ```
199
+
200
+ Events batch to `POST /v1/sdk/events` (20 per batch or every 5 s, flushed on `pagehide`, spilled to `localStorage` when offline). Names must match `^[a-z][a-z0-9_]{1,63}$`; properties are flat `string | number | boolean | null`, PII-looking keys (`email`, `phone`, `token`, …) are dropped, and string values run through the PII scrubber. `analytics.enabled: false` turns it off; `navigator.doNotTrack` / Global Privacy Control are honoured by default. The console's **Users & Funnels** page reads the same events; retention defaults to 90 days per project.
201
+ </details>
202
+
174
203
  <details>
175
204
  <summary><b>Runtime control &amp; self-noise filters</b> — imperative APIs and CSP-safe defaults</summary>
176
205
 
@@ -285,7 +314,7 @@ Screenshot capture uses canvas / SVG `foreignObject` serialization — it does n
285
314
 
286
315
  ## Bundle size
287
316
 
288
- ~7 KB brotli, enforced at 89 KB gzipped (105 KB uncompressed) in CI. Requires `@mushi-mushi/core` (installed automatically, not bundled inline). The widget's visual system — washi paper, sumi ink, vermillion 朱 accent, system serif — lives in [`src/styles.ts`](./src/styles.ts).
317
+ ~7 KB brotli, enforced at 89.5 KB gzipped (105 KB uncompressed) in CI. Requires `@mushi-mushi/core` (installed automatically, not bundled inline). The widget's visual system — washi paper, sumi ink, vermillion 朱 accent, system serif — lives in [`src/styles.ts`](./src/styles.ts).
289
318
 
290
319
  ## License
291
320
 
@@ -294,4 +323,4 @@ MIT
294
323
  <!-- mushi-readme-stats-footer -->
295
324
  ---
296
325
 
297
- <sub>Monorepo scale (July 2026): 58 edge functions · 347 SQL migrations · 13 outbound plugins · 11 inbound adapters · 19 pipeline agents. Canonical counts: <a href="https://github.com/kensaurus/mushi-mushi/blob/master/docs/stats.md">docs/stats.md</a> · <code>pnpm docs-stats</code></sub>
326
+ <sub>Monorepo scale (July 2026): 60 edge functions · 383 SQL migrations · 13 outbound plugins · 11 inbound adapters · 19 pipeline agents. Canonical counts: <a href="https://github.com/kensaurus/mushi-mushi/blob/master/docs/stats.md">docs/stats.md</a> · <code>pnpm docs-stats</code></sub>
@@ -0,0 +1,34 @@
1
+ // src/capture/display-capture.ts
2
+ async function grabMaskedTabFrame(pendingStream, maskSelectors) {
3
+ const stream = await pendingStream;
4
+ const surface = stream.getVideoTracks?.()[0]?.getSettings?.().displaySurface;
5
+ if (surface && surface !== "browser") {
6
+ stream.getTracks().forEach((track) => track.stop());
7
+ throw Object.assign(new Error("Only this tab can be captured"), { name: "NotAllowedError" });
8
+ }
9
+ const selectors = maskSelectors.join(",");
10
+ const mask = document.createElement("style");
11
+ mask.setAttribute("data-mushi-capture-mask", "");
12
+ mask.textContent = `:is(${selectors}){background:#000!important;color:transparent!important;-webkit-text-fill-color:transparent!important;text-shadow:none!important}:is(${selectors}) *{visibility:hidden!important}`;
13
+ document.head.appendChild(mask);
14
+ const video = document.createElement("video");
15
+ try {
16
+ video.muted = true;
17
+ video.srcObject = stream;
18
+ await video.play();
19
+ await new Promise((resolve) => setTimeout(resolve, 150));
20
+ const canvas = document.createElement("canvas");
21
+ canvas.width = video.videoWidth;
22
+ canvas.height = video.videoHeight;
23
+ canvas.getContext("2d")?.drawImage(video, 0, 0);
24
+ return canvas.toDataURL("image/jpeg", 0.7);
25
+ } finally {
26
+ stream.getTracks().forEach((track) => track.stop());
27
+ video.srcObject = null;
28
+ mask.remove();
29
+ }
30
+ }
31
+
32
+ export { grabMaskedTabFrame };
33
+ //# sourceMappingURL=display-capture-5ZJSTBUK.js.map
34
+ //# sourceMappingURL=display-capture-5ZJSTBUK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/capture/display-capture.ts"],"names":[],"mappings":";AAiBA,eAAsB,kBAAA,CACpB,eACA,aAAA,EACiB;AACjB,EAAA,MAAM,SAAS,MAAM,aAAA;AAKrB,EAAA,MAAM,UAAU,MAAA,CAAO,cAAA,KAAmB,CAAC,CAAA,EAAG,eAAc,CAAE,cAAA;AAC9D,EAAA,IAAI,OAAA,IAAW,YAAY,SAAA,EAAW;AACpC,IAAA,MAAA,CAAO,WAAU,CAAE,OAAA,CAAQ,CAAC,KAAA,KAAU,KAAA,CAAM,MAAM,CAAA;AAClD,IAAA,MAAM,MAAA,CAAO,OAAO,IAAI,KAAA,CAAM,+BAA+B,CAAA,EAAG,EAAE,IAAA,EAAM,iBAAA,EAAmB,CAAA;AAAA,EAC7F;AACA,EAAA,MAAM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ce an\n * image: the browser's own picker asks the reporter to share this tab, one\n * frame is grabbed, and every track stops immediately. Loaded lazily — only a\n * reporter who clicks \"Share this tab instead\" pays for it.\n *\n * The caller requests the stream itself, synchronously inside the click\n * (getDisplayMedia needs the transient user activation, which an awaited\n * dynamic import would lose), and passes the pending stream in.\n *\n * A tab share is real pixels, so DOM-level redaction can't reach it. While the\n * frame is taken, a temporary stylesheet blacks out the same sensitive\n * selectors on the live page; the caller passes them (the always-on baseline\n * plus the host's lists) so this chunk imports nothing from the main bundle.\n * The reporter still reviews the preview before anything is sent.\n * Rejects with the browser's error (NotAllowedError when the reporter cancels).\n */\nexport async function grabMaskedTabFrame(\n pendingStream: Promise<MediaStream>,\n maskSelectors: readonly string[],\n): Promise<string> {\n const stream = await pendingStream;\n // Masking only reaches this page: refuse a window or the whole screen rather\n // than capture it unmasked. (A different browser tab also reports 'browser'\n // and can't be told apart here; preferCurrentTab makes this tab the default\n // choice, and the reporter reviews the preview before sending.)\n const surface = stream.getVideoTracks?.()[0]?.getSettings?.().displaySurface;\n if (surface && surface !== 'browser') {\n stream.getTracks().forEach((track) => track.stop());\n throw Object.assign(new Error('Only this tab can be captured'), { name: 'NotAllowedError' });\n }\n const selectors = maskSelectors.join(',');\n const mask = document.createElement('style');\n mask.setAttribute('data-mushi-capture-mask', '');\n mask.textContent =\n `:is(${selectors}){background:#000!important;color:transparent!important;-webkit-text-fill-color:transparent!important;text-shadow:none!important}` +\n `:is(${selectors}) *{visibility:hidden!important}`;\n document.head.appendChild(mask);\n const video = document.createElement('video');\n try {\n video.muted = true;\n video.srcObject = stream;\n await video.play();\n // Let the masked page reach the stream before grabbing a frame.\n await new Promise((resolve) => setTimeout(resolve, 150));\n const canvas = document.createElement('canvas');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n canvas.getContext('2d')?.drawImage(video, 0, 0);\n return canvas.toDataURL('image/jpeg', 0.7);\n } finally {\n stream.getTracks().forEach((track) => track.stop());\n video.srcObject = null;\n mask.remove();\n }\n}\n"]}
@@ -0,0 +1,132 @@
1
+ // src/capture/screenshot-annotation.ts
2
+ function createScreenshotAnnotation(imageDataUrl, container) {
3
+ return new Promise((resolve, reject) => {
4
+ const img = new Image();
5
+ img.onload = () => {
6
+ const wrap = document.createElement("div");
7
+ wrap.style.position = "relative";
8
+ wrap.style.display = "inline-block";
9
+ wrap.style.maxWidth = "100%";
10
+ const base = document.createElement("canvas");
11
+ const overlay = document.createElement("canvas");
12
+ const scale = Math.min(1, 720 / img.width);
13
+ const w = Math.round(img.width * scale);
14
+ const h = Math.round(img.height * scale);
15
+ for (const c of [base, overlay]) {
16
+ c.width = w;
17
+ c.height = h;
18
+ c.style.width = "100%";
19
+ c.style.height = "auto";
20
+ c.style.display = "block";
21
+ }
22
+ overlay.style.position = "absolute";
23
+ overlay.style.left = "0";
24
+ overlay.style.top = "0";
25
+ overlay.style.cursor = "crosshair";
26
+ const bctx = base.getContext("2d");
27
+ const octx = overlay.getContext("2d");
28
+ if (!bctx || !octx) {
29
+ reject(new Error("Canvas not supported"));
30
+ return;
31
+ }
32
+ bctx.drawImage(img, 0, 0, w, h);
33
+ wrap.appendChild(base);
34
+ wrap.appendChild(overlay);
35
+ container.appendChild(wrap);
36
+ let tool = "highlight";
37
+ let drawing = false;
38
+ let start = null;
39
+ const strokes = [];
40
+ const toLocal = (ev) => {
41
+ const rect = overlay.getBoundingClientRect();
42
+ const touch = "touches" in ev ? ev.touches[0] ?? ev.changedTouches[0] : null;
43
+ const clientX = touch ? touch.clientX : ev.clientX;
44
+ const clientY = touch ? touch.clientY : ev.clientY;
45
+ return {
46
+ x: (clientX - rect.left) / rect.width * w,
47
+ y: (clientY - rect.top) / rect.height * h
48
+ };
49
+ };
50
+ const redraw = () => {
51
+ octx.clearRect(0, 0, w, h);
52
+ for (const s of strokes) {
53
+ if (s.tool === "highlight" && s.points.length >= 2) {
54
+ const [a, b] = s.points;
55
+ octx.fillStyle = "rgba(255, 230, 0, 0.35)";
56
+ octx.fillRect(
57
+ Math.min(a.x, b.x),
58
+ Math.min(a.y, b.y),
59
+ Math.abs(b.x - a.x),
60
+ Math.abs(b.y - a.y)
61
+ );
62
+ } else if (s.tool === "arrow" && s.points.length >= 2) {
63
+ const [a, b] = s.points;
64
+ octx.strokeStyle = "#ef4444";
65
+ octx.lineWidth = 3;
66
+ octx.beginPath();
67
+ octx.moveTo(a.x, a.y);
68
+ octx.lineTo(b.x, b.y);
69
+ octx.stroke();
70
+ }
71
+ }
72
+ };
73
+ const onDown = (ev) => {
74
+ drawing = true;
75
+ start = toLocal(ev);
76
+ };
77
+ const onUp = (ev) => {
78
+ if (!drawing || !start) return;
79
+ drawing = false;
80
+ const end = toLocal(ev);
81
+ if (tool === "blur") {
82
+ const x = Math.min(start.x, end.x);
83
+ const y = Math.min(start.y, end.y);
84
+ const bw = Math.abs(end.x - start.x);
85
+ const bh = Math.abs(end.y - start.y);
86
+ if (bw >= 1 && bh >= 1) {
87
+ bctx.filter = "blur(8px)";
88
+ bctx.drawImage(base, x, y, bw, bh, x, y, bw, bh);
89
+ bctx.filter = "none";
90
+ }
91
+ } else {
92
+ strokes.push({ tool, points: [start, end] });
93
+ }
94
+ start = null;
95
+ redraw();
96
+ };
97
+ overlay.addEventListener("mousedown", onDown);
98
+ overlay.addEventListener("mouseup", onUp);
99
+ overlay.addEventListener("touchstart", onDown, { passive: true });
100
+ overlay.addEventListener("touchend", onUp);
101
+ resolve({
102
+ canvas: base,
103
+ setTool(t) {
104
+ tool = t;
105
+ },
106
+ getDataUrl() {
107
+ const out = document.createElement("canvas");
108
+ out.width = w;
109
+ out.height = h;
110
+ const ctx = out.getContext("2d");
111
+ if (!ctx) return imageDataUrl;
112
+ ctx.drawImage(base, 0, 0);
113
+ ctx.drawImage(overlay, 0, 0);
114
+ return out.toDataURL("image/jpeg", 0.85);
115
+ },
116
+ destroy() {
117
+ overlay.removeEventListener("mousedown", onDown);
118
+ overlay.removeEventListener("mouseup", onUp);
119
+ overlay.removeEventListener("touchstart", onDown);
120
+ overlay.removeEventListener("touchend", onUp);
121
+ wrap.remove();
122
+ }
123
+ });
124
+ };
125
+ img.onerror = () => reject(new Error("Failed to load screenshot"));
126
+ img.src = imageDataUrl;
127
+ });
128
+ }
129
+
130
+ export { createScreenshotAnnotation };
131
+ //# sourceMappingURL=screenshot-annotation-IG7C5B6Z.js.map
132
+ //# sourceMappingURL=screenshot-annotation-IG7C5B6Z.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/capture/screenshot-annotation.ts"],"names":[],"mappings":";AAoBO,SAAS,0BAAA,CACd,cACA,SAAA,EAC4B;AAC5B,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAA,KAAW;AACtC,IAAA,MAAM,GAAA,GAAM,IAAI,KAAA,EAAM;AACtB,IAAA,GAAA,CAAI,SAAS,MAAM;AACjB,MAAA,MAAM,IAAA,GAAO,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AACzC,MAAA,IAAA,CAAK,MAAM,QAAA,GAAW,UAAA;AACtB,MAAA,IAAA,CAAK,MAAM,OAAA,GAAU,cAAA;AACrB,MAAA,IAAA,CAAK,MAAM,QAAA,GAAW,MAAA;AAEtB,MAAA,MAAM,IAAA,GAAO,QAAA,CAAS,aAAA,CAAc,QAAQ,CAAA;AAC5C,MAAA,MAAM,OAAA,GAAU,QAAA,CAAS,aAAA,CAAc,QAAQ,CAAA;AAC/C,MAAA,MAAM,QAAQ,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,GAAA,GAAM,IAAI,KAAK,CAAA;AACzC,MAAA,MAAM,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,QAAQ,KAAK,CAAA;AACtC,MAAA,MAAM,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,SAAS,KAAK,CAAA;AACvC,MAAA,KAAA,MAAW,CAAA,IAAK,CAAC,IAAA,EAAM,OAAO,CAAA,EAAG;AAC/B,QAAA,CAAA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AAA,GAAA,CAAI,SAAA,CAAU,OAAA,EAAS,CAAA,EAAG,CAAC,CAAA;AAC3B,UAAA,OAAO,GAAA,CAAI,SAAA,CAAU,YAAA,EAAc,IAAI,CAAA;AAAA,QACzC,CAAA;AAAA,QACA,OAAA,GAAU;AACR,UAAA,OAAA,CAAQ,mBAAA,CAAoB,aAAa,MAAM,CAAA;AAC/C,UAAA,OAAA,CAAQ,mBAAA,CAAoB,WAAW,IAAI,CAAA;AAC3C,UAAA,OAAA,CAAQ,mBAAA,CAAoB,cAAc,MAAM,CAAA;AAChD,UAAA,OAAA,CAAQ,mBAAA,CAAoB,YAAY,IAAI,CAAA;AAC5C,UAAA,IAAA,CAAK,MAAA,EAAO;AAAA,QACd;AAAA,OACD,CAAA;AAAA,IACH,CAAA;AACA,IAAA,GAAA,CAAI,UAAU,MAAM,MAAA,CAAO,IAAI,KAAA,CAAM,2BAA2B,CAAC,CAAA;AACjE,IAAA,GAAA,CAAI,GAAA,GAAM,YAAA;AAAA,EACZ,CAAC,CAAA;AACH","file":"screenshot-annotation-IG7C5B6Z.js","sourcesContent":["/**\n * Lightweight canvas overlay for screenshot markup (highlight / blur / arrow).\n * Blur doubles as client-side PII redaction before upload.\n */\n\nexport type AnnotationTool = 'highlight' | 'blur' | 'arrow'\n\nexport interface AnnotationStroke {\n tool: AnnotationTool\n points: Array<{ x: number; y: number }>\n color?: string\n}\n\nexport interface AnnotationSession {\n canvas: HTMLCanvasElement\n getDataUrl(): string\n setTool(tool: AnnotationTool): void\n destroy(): void\n}\n\nexport function createScreenshotAnnotation(\n imageDataUrl: string,\n container: HTMLElement,\n): Promise<AnnotationSession> {\n return new Promise((resolve, reject) => {\n const img = new Image()\n img.onload = () => {\n const wrap = document.createElement('div')\n wrap.style.position = 'relative'\n wrap.style.display = 'inline-block'\n wrap.style.maxWidth = '100%'\n\n const base = document.createElement('canvas')\n const overlay = document.createElement('canvas')\n const scale = Math.min(1, 720 / img.width)\n const w = Math.round(img.width * scale)\n const h = Math.round(img.height * scale)\n for (const c of [base, overlay]) {\n c.width = w\n c.height = h\n c.style.width = '100%'\n c.style.height = 'auto'\n c.style.display = 'block'\n }\n overlay.style.position = 'absolute'\n overlay.style.left = '0'\n overlay.style.top = '0'\n overlay.style.cursor = 'crosshair'\n\n const bctx = base.getContext('2d')\n const octx = overlay.getContext('2d')\n if (!bctx || !octx) {\n reject(new Error('Canvas not supported'))\n return\n }\n bctx.drawImage(img, 0, 0, w, h)\n\n wrap.appendChild(base)\n wrap.appendChild(overlay)\n container.appendChild(wrap)\n\n let tool: AnnotationTool = 'highlight'\n let drawing = false\n let start: { x: number; y: number } | null = null\n const strokes: AnnotationStroke[] = []\n\n const toLocal = (ev: MouseEvent | TouchEvent): { x: number; y: number } => {\n const rect = overlay.getBoundingClientRect()\n // On `touchend`, `ev.touches` is empty (the finger lifted) — the final\n // coordinates live in `changedTouches`. Reading `touches[0]` there\n // would land every stroke at (0,0) on touch devices.\n const touch = 'touches' in ev ? (ev.touches[0] ?? ev.changedTouches[0]) : null\n const clientX = touch ? touch.clientX : (ev as MouseEvent).clientX\n const clientY = touch ? touch.clientY : (ev as MouseEvent).clientY\n return {\n x: ((clientX - rect.left) / rect.width) * w,\n y: ((clientY - rect.top) / rect.height) * h,\n }\n }\n\n // Blur is baked destructively into `base` (see onUp) so the exported\n // pixels contain no original PII — keep only highlight/arrow on the\n // re-drawable overlay here.\n const redraw = () => {\n octx.clearRect(0, 0, w, h)\n for (const s of strokes) {\n if (s.tool === 'highlight' && s.points.length >= 2) {\n const [a, b] = s.points\n octx.fillStyle = 'rgba(255, 230, 0, 0.35)'\n octx.fillRect(\n Math.min(a.x, b.x),\n Math.min(a.y, b.y),\n Math.abs(b.x - a.x),\n Math.abs(b.y - a.y),\n )\n } else if (s.tool === 'arrow' && s.points.length >= 2) {\n const [a, b] = s.points\n octx.strokeStyle = '#ef4444'\n octx.lineWidth = 3\n octx.beginPath()\n octx.moveTo(a.x, a.y)\n octx.lineTo(b.x, b.y)\n octx.stroke()\n }\n }\n }\n\n const onDown = (ev: MouseEvent | TouchEvent) => {\n drawing = true\n start = toLocal(ev)\n }\n const onUp = (ev: MouseEvent | TouchEvent) => {\n if (!drawing || !start) return\n drawing = false\n const end = toLocal(ev)\n if (tool === 'blur') {\n // Redaction must be irreversible in the exported image: bake an\n // opaque blurred patch into the base canvas, overwriting the\n // original pixels (the overlay's feathered alpha would otherwise\n // leak the source pixels around the region's edge).\n const x = Math.min(start.x, end.x)\n const y = Math.min(start.y, end.y)\n const bw = Math.abs(end.x - start.x)\n const bh = Math.abs(end.y - start.y)\n if (bw >= 1 && bh >= 1) {\n bctx.filter = 'blur(8px)'\n bctx.drawImage(base, x, y, bw, bh, x, y, bw, bh)\n bctx.filter = 'none'\n }\n } else {\n strokes.push({ tool, points: [start, end] })\n }\n start = null\n redraw()\n }\n\n overlay.addEventListener('mousedown', onDown)\n overlay.addEventListener('mouseup', onUp)\n overlay.addEventListener('touchstart', onDown, { passive: true })\n overlay.addEventListener('touchend', onUp)\n\n resolve({\n canvas: base,\n setTool(t: AnnotationTool) {\n tool = t\n },\n getDataUrl() {\n const out = document.createElement('canvas')\n out.width = w\n out.height = h\n const ctx = out.getContext('2d')\n if (!ctx) return imageDataUrl\n ctx.drawImage(base, 0, 0)\n ctx.drawImage(overlay, 0, 0)\n return out.toDataURL('image/jpeg', 0.85)\n },\n destroy() {\n overlay.removeEventListener('mousedown', onDown)\n overlay.removeEventListener('mouseup', onUp)\n overlay.removeEventListener('touchstart', onDown)\n overlay.removeEventListener('touchend', onUp)\n wrap.remove()\n },\n })\n }\n img.onerror = () => reject(new Error('Failed to load screenshot'))\n img.src = imageDataUrl\n })\n}\n"]}
package/dist/headless.cjs CHANGED
@@ -350,7 +350,11 @@ function createScreenshotCapture(options = {}) {
350
350
  if (typeof document === "undefined") return null;
351
351
  const canvas = document.createElement("canvas");
352
352
  const ctx = canvas.getContext("2d");
353
- if (!ctx) return null;
353
+ if (!ctx) {
354
+ activeOptions.onFailed?.("unsupported");
355
+ emitScreenshotFailed("unsupported");
356
+ return null;
357
+ }
354
358
  const width = window.innerWidth;
355
359
  const height = window.innerHeight;
356
360
  const dpr = Math.min(window.devicePixelRatio || 1, 2);
@@ -368,27 +372,32 @@ function createScreenshotCapture(options = {}) {
368
372
  </svg>
369
373
  `;
370
374
  const img = new Image();
371
- const blob = new Blob([svgData], { type: "image/svg+xml;charset=utf-8" });
372
- const url = URL.createObjectURL(blob);
375
+ const url = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgData)}`;
376
+ let cspBlocked = false;
377
+ const onViolation = (e) => {
378
+ const v = e;
379
+ if (/^img-src|^default-src/.test(v.violatedDirective ?? "") && /^data/.test(v.blockedURI ?? "")) cspBlocked = true;
380
+ };
381
+ document.addEventListener("securitypolicyviolation", onViolation);
373
382
  return new Promise((resolve) => {
374
383
  let settled = false;
375
384
  const settle = (value, reason) => {
376
385
  if (settled) return;
377
386
  settled = true;
378
387
  clearTimeout(timer);
379
- URL.revokeObjectURL(url);
388
+ document.removeEventListener("securitypolicyviolation", onViolation);
380
389
  if (reason) {
381
390
  activeOptions.onFailed?.(reason);
382
391
  emitScreenshotFailed(reason);
383
392
  }
384
393
  resolve(value);
385
394
  };
386
- const timer = setTimeout(() => settle(null, "error"), 5e3);
395
+ const timer = setTimeout(() => settle(null, "timeout"), 5e3);
387
396
  img.onload = () => {
388
397
  try {
389
398
  ctx.drawImage(img, 0, 0, width, height);
390
399
  if (isCanvasBlank(ctx, width, height)) {
391
- settle(null, "error");
400
+ settle(null, "unsupported");
392
401
  return;
393
402
  }
394
403
  settle(canvas.toDataURL("image/jpeg", 0.7));
@@ -396,7 +405,7 @@ function createScreenshotCapture(options = {}) {
396
405
  settle(null, "taint");
397
406
  }
398
407
  };
399
- img.onerror = () => settle(null, "error");
408
+ img.onerror = () => setTimeout(() => settle(null, cspBlocked ? "csp" : "error"), 0);
400
409
  img.src = url;
401
410
  });
402
411
  } catch {
@@ -418,16 +427,17 @@ function emitScreenshotFailed(reason) {
418
427
  } catch {
419
428
  }
420
429
  }
421
- var DEFAULT_REDACT_SELECTORS = [
422
- 'input[type="password"]',
423
- "[data-mushi-redact]"
424
- ];
430
+ var ALWAYS_REDACT_SELECTORS = 'input[type="password"],input[autocomplete^="cc-"],[data-private],[data-mushi-mask]';
431
+ var DEFAULT_REDACT_SELECTORS = ["[data-mushi-redact]"];
425
432
  function buildPrivacySafeDocument(privacy) {
426
433
  const clone = document.documentElement.cloneNode(true);
427
434
  clone.querySelector("#mushi-mushi-widget")?.remove();
428
435
  stripTaintSources(clone);
429
436
  inlineDocumentStyles(clone);
430
- const redactSelectors = privacy?.redactSelectors !== void 0 ? privacy.redactSelectors : DEFAULT_REDACT_SELECTORS;
437
+ const redactSelectors = [
438
+ ALWAYS_REDACT_SELECTORS,
439
+ ...privacy?.redactSelectors ?? DEFAULT_REDACT_SELECTORS
440
+ ];
431
441
  for (const selector of redactSelectors) {
432
442
  for (const el of safeQueryAll(clone, selector)) {
433
443
  redactElement(el);