@mushi-mushi/web 1.29.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 +1 -1
- package/dist/chunks/display-capture-5ZJSTBUK.js +34 -0
- package/dist/chunks/display-capture-5ZJSTBUK.js.map +1 -0
- package/dist/chunks/screenshot-annotation-IG7C5B6Z.js +132 -0
- package/dist/chunks/screenshot-annotation-IG7C5B6Z.js.map +1 -0
- package/dist/headless.cjs +22 -12
- package/dist/headless.cjs.map +1 -1
- package/dist/headless.d.cts +1 -1
- package/dist/headless.d.ts +72 -2
- package/dist/headless.js +22 -12
- package/dist/headless.js.map +1 -1
- package/dist/i18n/index.cjs +80 -4
- package/dist/i18n/index.cjs.map +1 -1
- package/dist/i18n/index.d.cts +30 -0
- package/dist/i18n/index.d.ts +30 -0
- package/dist/i18n/index.js +80 -4
- package/dist/i18n/index.js.map +1 -1
- package/dist/index.cjs +2144 -3592
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -8
- package/dist/index.d.ts +349 -11
- package/dist/index.js +1151 -2783
- package/dist/index.js.map +1 -1
- package/dist/mushi.loader.global.js +471 -2246
- package/dist/test-utils.cjs +173 -1
- package/dist/test-utils.cjs.map +1 -1
- package/dist/test-utils.js +173 -1
- package/dist/test-utils.js.map +1 -1
- package/dist/{timeline-BuqAn2FH.d.cts → timeline-B8nMyZyM.d.cts} +12 -2
- package/package.json +10 -4
- package/dist/timeline-BuqAn2FH.d.ts +0 -63
package/README.md
CHANGED
|
@@ -323,4 +323,4 @@ MIT
|
|
|
323
323
|
<!-- mushi-readme-stats-footer -->
|
|
324
324
|
---
|
|
325
325
|
|
|
326
|
-
<sub>Monorepo scale (July 2026):
|
|
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,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AAA;AACrB,IAAA,MAAA,CAAO,SAAS,KAAA,CAAM,WAAA;AACtB,IAAA,MAAA,CAAO,WAAW,IAAI,CAAA,EAAG,SAAA,CAAU,KAAA,EAAO,GAAG,CAAC,CAAA;AAC9C,IAAA,OAAO,MAAA,CAAO,SAAA,CAAU,YAAA,EAAc,GAAG,CAAA;AAAA,EAC3C,CAAA,SAAE;AACA,IAAA,MAAA,CAAO,WAAU,CAAE,OAAA,CAAQ,CAAC,KAAA,KAAU,KAAA,CAAM,MAAM,CAAA;AAClD,IAAA,KAAA,CAAM,SAAA,GAAY,IAAA;AAClB,IAAA,IAAA,CAAK,MAAA,EAAO;AAAA,EACd;AACF","file":"display-capture-5ZJSTBUK.js","sourcesContent":["/**\n * Explicit, user-consented fallback for when the DOM capturer can't produce 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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;AACZ,UAAA,GAAA,CAAI,MAAA,GAAS,CAAA;AACb,UAAA,MAAM,GAAA,GAAM,GAAA,CAAI,UAAA,CAAW,IAAI,CAAA;AAC/B,UAAA,IAAI,CAAC,KAAK,OAAO,YAAA;AACjB,UAAA,GAAA,CAAI,SAAA,CAAU,IAAA,EAAM,CAAA,EAAG,CAAC,CAAA;AACxB,UAAA,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)
|
|
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
|
|
372
|
-
|
|
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
|
-
|
|
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, "
|
|
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, "
|
|
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
|
|
422
|
-
|
|
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 =
|
|
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);
|