@mushi-mushi/web 1.29.0 → 1.31.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 +19 -5
- 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/chunks/widget-views-DX3OYHGR.js +233 -0
- package/dist/chunks/widget-views-DX3OYHGR.js.map +1 -0
- package/dist/headless.cjs +39 -13
- 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 +39 -13
- package/dist/headless.js.map +1 -1
- package/dist/i18n/index.cjs +178 -234
- package/dist/i18n/index.cjs.map +1 -1
- package/dist/i18n/index.d.cts +114 -32
- package/dist/i18n/index.d.ts +114 -32
- package/dist/i18n/index.js +178 -234
- package/dist/i18n/index.js.map +1 -1
- package/dist/index.cjs +2495 -4386
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +203 -181
- package/dist/index.d.ts +541 -183
- package/dist/index.js +2011 -4325
- package/dist/index.js.map +1 -1
- package/dist/mushi.loader.global.js +21 -2279
- package/dist/test-utils.cjs +410 -1
- package/dist/test-utils.cjs.map +1 -1
- package/dist/test-utils.js +410 -1
- package/dist/test-utils.js.map +1 -1
- package/dist/{timeline-BuqAn2FH.d.cts → timeline-B8nMyZyM.d.cts} +12 -2
- package/package.json +19 -4
- package/dist/timeline-BuqAn2FH.d.ts +0 -63
package/dist/headless.d.ts
CHANGED
|
@@ -1,7 +1,77 @@
|
|
|
1
|
-
|
|
1
|
+
import { MushiConsoleEntry, MushiNetworkEntry, MushiUrlMatcher, MushiTracePropagationConfig, MushiPrivacyConfig, MushiPerformanceMetrics, MushiSelectedElement, MushiTimelineEntry } from '@mushi-mushi/core';
|
|
2
2
|
export { DEFAULT_API_ENDPOINT, MushiCaptureEventInput, MushiConsoleEntry, MushiNetworkEntry, MushiPerformanceMetrics, MushiReportCategory, MushiTimelineEntry, MushiTimelineKind } from '@mushi-mushi/core';
|
|
3
3
|
export { BrowserOtelSpan, BrowserOtelSpanProcessor, BrowserOtelSpanProcessorOptions, createBrowserOtelSpanProcessor } from './otel.js';
|
|
4
4
|
|
|
5
|
+
interface ConsoleCapture {
|
|
6
|
+
getEntries(): MushiConsoleEntry[];
|
|
7
|
+
clear(): void;
|
|
8
|
+
destroy(): void;
|
|
9
|
+
}
|
|
10
|
+
declare function createConsoleCapture(): ConsoleCapture;
|
|
11
|
+
|
|
12
|
+
interface NetworkCapture {
|
|
13
|
+
getEntries(): MushiNetworkEntry[];
|
|
14
|
+
clear(): void;
|
|
15
|
+
updateOptions(options: NetworkCaptureOptions): void;
|
|
16
|
+
destroy(): void;
|
|
17
|
+
}
|
|
18
|
+
interface NetworkCaptureOptions {
|
|
19
|
+
apiEndpoint?: string;
|
|
20
|
+
ignoreUrls?: MushiUrlMatcher[];
|
|
21
|
+
tracePropagation?: MushiTracePropagationConfig;
|
|
22
|
+
sessionId?: string;
|
|
23
|
+
}
|
|
24
|
+
declare function createNetworkCapture(options?: NetworkCaptureOptions): NetworkCapture;
|
|
25
|
+
|
|
26
|
+
interface ScreenshotCapture {
|
|
27
|
+
take(): Promise<string | null>;
|
|
28
|
+
updateOptions(options: ScreenshotCaptureOptions): void;
|
|
29
|
+
}
|
|
30
|
+
interface ScreenshotCaptureOptions {
|
|
31
|
+
privacy?: MushiPrivacyConfig;
|
|
32
|
+
/** Callback invoked when capture fails (taint, security policy, etc.). */
|
|
33
|
+
onFailed?: (reason: ScreenshotFailureReason) => void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Why a capture produced no image. Also the `detail.reason` of the
|
|
37
|
+
* `mushi:screenshot_failed` document event.
|
|
38
|
+
* - taint: cross-origin content made the canvas unreadable
|
|
39
|
+
* - timeout: the SVG never loaded or errored within 5 s
|
|
40
|
+
* - unsupported: no 2D canvas, or the engine rasterised nothing (WebKit)
|
|
41
|
+
* - csp: the host's Content-Security-Policy img-src blocks data: images
|
|
42
|
+
* - error: anything else
|
|
43
|
+
*/
|
|
44
|
+
type ScreenshotFailureReason = 'taint' | 'timeout' | 'unsupported' | 'csp' | 'error';
|
|
45
|
+
declare function createScreenshotCapture(options?: ScreenshotCaptureOptions): ScreenshotCapture;
|
|
46
|
+
|
|
47
|
+
interface PerformanceCapture {
|
|
48
|
+
getMetrics(): MushiPerformanceMetrics;
|
|
49
|
+
destroy(): void;
|
|
50
|
+
}
|
|
51
|
+
declare function createPerformanceCapture(): PerformanceCapture;
|
|
52
|
+
|
|
53
|
+
interface ElementSelector {
|
|
54
|
+
activate(): Promise<MushiSelectedElement | null>;
|
|
55
|
+
deactivate(): void;
|
|
56
|
+
isActive(): boolean;
|
|
57
|
+
}
|
|
58
|
+
declare function createElementSelector(): ElementSelector;
|
|
59
|
+
|
|
60
|
+
interface TimelineCapture {
|
|
61
|
+
setScreen(screen: {
|
|
62
|
+
name: string;
|
|
63
|
+
route?: string;
|
|
64
|
+
feature?: string;
|
|
65
|
+
}): void;
|
|
66
|
+
getEntries(input?: {
|
|
67
|
+
consoleLogs?: MushiConsoleEntry[] | null;
|
|
68
|
+
networkLogs?: MushiNetworkEntry[] | null;
|
|
69
|
+
}): MushiTimelineEntry[];
|
|
70
|
+
clear(): void;
|
|
71
|
+
destroy(): void;
|
|
72
|
+
}
|
|
73
|
+
declare function createTimelineCapture(): TimelineCapture;
|
|
74
|
+
|
|
5
75
|
/**
|
|
6
76
|
* FILE: packages/web/src/headless.ts
|
|
7
77
|
* PURPOSE: Headless (no-widget) entry for @mushi-mushi/web.
|
|
@@ -85,4 +155,4 @@ interface HeadlessCaptureInstance {
|
|
|
85
155
|
*/
|
|
86
156
|
declare function createHeadlessCapture(opts: HeadlessCaptureOptions): HeadlessCaptureInstance;
|
|
87
157
|
|
|
88
|
-
export { type HeadlessCaptureEventInput, type HeadlessCaptureInstance, type HeadlessCaptureOptions, type HeadlessCaptureResult, createHeadlessCapture };
|
|
158
|
+
export { type ConsoleCapture, type ElementSelector, type HeadlessCaptureEventInput, type HeadlessCaptureInstance, type HeadlessCaptureOptions, type HeadlessCaptureResult, type NetworkCapture, type PerformanceCapture, type ScreenshotCapture, type TimelineCapture, createConsoleCapture, createElementSelector, createHeadlessCapture, createNetworkCapture, createPerformanceCapture, createScreenshotCapture, createTimelineCapture };
|
package/dist/headless.js
CHANGED
|
@@ -348,8 +348,12 @@ function createScreenshotCapture(options = {}) {
|
|
|
348
348
|
try {
|
|
349
349
|
if (typeof document === "undefined") return null;
|
|
350
350
|
const canvas = document.createElement("canvas");
|
|
351
|
-
const ctx = canvas.getContext("2d");
|
|
352
|
-
if (!ctx)
|
|
351
|
+
const ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
352
|
+
if (!ctx) {
|
|
353
|
+
activeOptions.onFailed?.("unsupported");
|
|
354
|
+
emitScreenshotFailed("unsupported");
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
353
357
|
const width = window.innerWidth;
|
|
354
358
|
const height = window.innerHeight;
|
|
355
359
|
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
@@ -367,27 +371,32 @@ function createScreenshotCapture(options = {}) {
|
|
|
367
371
|
</svg>
|
|
368
372
|
`;
|
|
369
373
|
const img = new Image();
|
|
370
|
-
const
|
|
371
|
-
|
|
374
|
+
const url = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgData)}`;
|
|
375
|
+
let cspBlocked = false;
|
|
376
|
+
const onViolation = (e) => {
|
|
377
|
+
const v = e;
|
|
378
|
+
if (/^img-src|^default-src/.test(v.violatedDirective ?? "") && /^data/.test(v.blockedURI ?? "")) cspBlocked = true;
|
|
379
|
+
};
|
|
380
|
+
document.addEventListener("securitypolicyviolation", onViolation);
|
|
372
381
|
return new Promise((resolve) => {
|
|
373
382
|
let settled = false;
|
|
374
383
|
const settle = (value, reason) => {
|
|
375
384
|
if (settled) return;
|
|
376
385
|
settled = true;
|
|
377
386
|
clearTimeout(timer);
|
|
378
|
-
|
|
387
|
+
document.removeEventListener("securitypolicyviolation", onViolation);
|
|
379
388
|
if (reason) {
|
|
380
389
|
activeOptions.onFailed?.(reason);
|
|
381
390
|
emitScreenshotFailed(reason);
|
|
382
391
|
}
|
|
383
392
|
resolve(value);
|
|
384
393
|
};
|
|
385
|
-
const timer = setTimeout(() => settle(null, "
|
|
394
|
+
const timer = setTimeout(() => settle(null, "timeout"), 5e3);
|
|
386
395
|
img.onload = () => {
|
|
387
396
|
try {
|
|
388
397
|
ctx.drawImage(img, 0, 0, width, height);
|
|
389
398
|
if (isCanvasBlank(ctx, width, height)) {
|
|
390
|
-
settle(null, "
|
|
399
|
+
settle(null, "unsupported");
|
|
391
400
|
return;
|
|
392
401
|
}
|
|
393
402
|
settle(canvas.toDataURL("image/jpeg", 0.7));
|
|
@@ -395,7 +404,7 @@ function createScreenshotCapture(options = {}) {
|
|
|
395
404
|
settle(null, "taint");
|
|
396
405
|
}
|
|
397
406
|
};
|
|
398
|
-
img.onerror = () => settle(null, "error");
|
|
407
|
+
img.onerror = () => setTimeout(() => settle(null, cspBlocked ? "csp" : "error"), 0);
|
|
399
408
|
img.src = url;
|
|
400
409
|
});
|
|
401
410
|
} catch {
|
|
@@ -417,16 +426,19 @@ function emitScreenshotFailed(reason) {
|
|
|
417
426
|
} catch {
|
|
418
427
|
}
|
|
419
428
|
}
|
|
420
|
-
var
|
|
421
|
-
|
|
422
|
-
"[data-mushi-redact]"
|
|
423
|
-
];
|
|
429
|
+
var ALWAYS_REDACT_SELECTORS = 'input[type="password"],input[autocomplete^="cc-"],[data-private],[data-mushi-mask]';
|
|
430
|
+
var DEFAULT_REDACT_SELECTORS = ["[data-mushi-redact]"];
|
|
424
431
|
function buildPrivacySafeDocument(privacy) {
|
|
425
432
|
const clone = document.documentElement.cloneNode(true);
|
|
426
433
|
clone.querySelector("#mushi-mushi-widget")?.remove();
|
|
427
434
|
stripTaintSources(clone);
|
|
428
435
|
inlineDocumentStyles(clone);
|
|
429
|
-
|
|
436
|
+
freezeMotion(clone);
|
|
437
|
+
fillViewport(clone);
|
|
438
|
+
const redactSelectors = [
|
|
439
|
+
ALWAYS_REDACT_SELECTORS,
|
|
440
|
+
...privacy?.redactSelectors ?? DEFAULT_REDACT_SELECTORS
|
|
441
|
+
];
|
|
430
442
|
for (const selector of redactSelectors) {
|
|
431
443
|
for (const el of safeQueryAll(clone, selector)) {
|
|
432
444
|
redactElement(el);
|
|
@@ -512,6 +524,20 @@ function inlineDocumentStyles(clone) {
|
|
|
512
524
|
styleEl.textContent = css;
|
|
513
525
|
(clone.querySelector("head") ?? clone).appendChild(styleEl);
|
|
514
526
|
}
|
|
527
|
+
var FREEZE_MOTION_CSS = "*,*::before,*::after{animation:none!important;transition:none!important}";
|
|
528
|
+
function fillViewport(clone) {
|
|
529
|
+
const clear = (c) => !c || c === "transparent" || /^rgba\(.*,\s*0\)$/.test(c);
|
|
530
|
+
let bg = getComputedStyle(document.documentElement).backgroundColor;
|
|
531
|
+
if (clear(bg) && document.body) bg = getComputedStyle(document.body).backgroundColor;
|
|
532
|
+
const root = clone;
|
|
533
|
+
root.style.setProperty("background-color", clear(bg) ? "Canvas" : bg);
|
|
534
|
+
root.style.setProperty("min-height", `${window.innerHeight}px`);
|
|
535
|
+
}
|
|
536
|
+
function freezeMotion(clone) {
|
|
537
|
+
const styleEl = document.createElement("style");
|
|
538
|
+
styleEl.textContent = FREEZE_MOTION_CSS;
|
|
539
|
+
(clone.querySelector("head") ?? clone).appendChild(styleEl);
|
|
540
|
+
}
|
|
515
541
|
function serializeSheet(sheet) {
|
|
516
542
|
let rules;
|
|
517
543
|
try {
|