@mushi-mushi/web 1.35.0 → 1.37.3
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/chunk-ONXNS7MQ.js +35 -0
- package/dist/chunks/chunk-ONXNS7MQ.js.map +1 -0
- package/dist/chunks/screenshot-dom-K3N2HPNN.js +653 -0
- package/dist/chunks/screenshot-dom-K3N2HPNN.js.map +1 -0
- package/dist/headless.cjs +744 -271
- package/dist/headless.cjs.map +1 -1
- package/dist/headless.d.cts +1 -1
- package/dist/headless.d.ts +4 -0
- package/dist/headless.js +744 -271
- package/dist/headless.js.map +1 -1
- package/dist/index.cjs +748 -271
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +52 -275
- package/dist/index.js.map +1 -1
- package/dist/mushi.loader.global.js +20 -19
- package/dist/test-utils.cjs +596 -0
- package/dist/test-utils.cjs.map +1 -1
- package/dist/test-utils.js +596 -0
- package/dist/test-utils.js.map +1 -1
- package/dist/{timeline-B8nMyZyM.d.cts → timeline-BUrJ4n9r.d.cts} +4 -0
- package/package.json +11 -5
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var reporterUi = require('@mushi-mushi/core/reporter-ui');
|
|
4
4
|
var core = require('@mushi-mushi/core');
|
|
5
|
+
var diagnostics = require('@mushi-mushi/core/diagnostics');
|
|
5
6
|
var reporterChannels = require('@mushi-mushi/core/reporter-channels');
|
|
6
7
|
|
|
7
8
|
var __defProp = Object.defineProperty;
|
|
@@ -253,6 +254,701 @@ var init_widget_views = __esm({
|
|
|
253
254
|
}
|
|
254
255
|
});
|
|
255
256
|
|
|
257
|
+
// src/capture/screenshot-dom.ts
|
|
258
|
+
var screenshot_dom_exports = {};
|
|
259
|
+
__export(screenshot_dom_exports, {
|
|
260
|
+
captureDomScreenshot: () => captureDomScreenshot
|
|
261
|
+
});
|
|
262
|
+
async function captureDomScreenshot(privacy, fail) {
|
|
263
|
+
const canvas = document.createElement("canvas");
|
|
264
|
+
const ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
265
|
+
if (!ctx) {
|
|
266
|
+
fail("unsupported");
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
const width = window.innerWidth;
|
|
270
|
+
const height = window.innerHeight;
|
|
271
|
+
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
272
|
+
canvas.width = width * dpr;
|
|
273
|
+
canvas.height = height * dpr;
|
|
274
|
+
ctx.scale(dpr, dpr);
|
|
275
|
+
const safeDocument = await buildPrivacySafeDocument(privacy);
|
|
276
|
+
const markup = new XMLSerializer().serializeToString(safeDocument).replace(XML_INVALID_CHARS, "");
|
|
277
|
+
const svgData = `
|
|
278
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}">
|
|
279
|
+
<foreignObject width="100%" height="100%">
|
|
280
|
+
<div xmlns="http://www.w3.org/1999/xhtml">
|
|
281
|
+
${markup}
|
|
282
|
+
</div>
|
|
283
|
+
</foreignObject>
|
|
284
|
+
</svg>
|
|
285
|
+
`;
|
|
286
|
+
const img = new Image();
|
|
287
|
+
const url = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgData)}`;
|
|
288
|
+
let cspBlocked = false;
|
|
289
|
+
const onViolation = (e) => {
|
|
290
|
+
const v = e;
|
|
291
|
+
if (/^img-src|^default-src/.test(v.violatedDirective ?? "") && /^data/.test(v.blockedURI ?? "")) cspBlocked = true;
|
|
292
|
+
};
|
|
293
|
+
document.addEventListener("securitypolicyviolation", onViolation);
|
|
294
|
+
return new Promise((resolve) => {
|
|
295
|
+
let settled = false;
|
|
296
|
+
const settle = (value, reason) => {
|
|
297
|
+
if (settled) return;
|
|
298
|
+
settled = true;
|
|
299
|
+
clearTimeout(timer);
|
|
300
|
+
document.removeEventListener("securitypolicyviolation", onViolation);
|
|
301
|
+
if (reason) fail(reason);
|
|
302
|
+
resolve(value);
|
|
303
|
+
};
|
|
304
|
+
const timer = setTimeout(() => settle(null, "timeout"), 5e3);
|
|
305
|
+
img.onload = () => {
|
|
306
|
+
try {
|
|
307
|
+
ctx.drawImage(img, 0, 0, width, height);
|
|
308
|
+
if (isCanvasBlank(ctx, width, height)) {
|
|
309
|
+
settle(null, "unsupported");
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
settle(canvas.toDataURL("image/jpeg", 0.7));
|
|
313
|
+
} catch {
|
|
314
|
+
settle(null, "taint");
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
img.onerror = () => setTimeout(() => settle(null, cspBlocked ? "csp" : "error"), 0);
|
|
318
|
+
img.src = url;
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
async function buildPrivacySafeDocument(privacy) {
|
|
322
|
+
const live = document.documentElement;
|
|
323
|
+
const clone = live.cloneNode(true);
|
|
324
|
+
const liveLinks = live.querySelectorAll("link");
|
|
325
|
+
const cloneLinks = clone.querySelectorAll("link");
|
|
326
|
+
const linkSlots = /* @__PURE__ */ new Map();
|
|
327
|
+
if (liveLinks.length === cloneLinks.length) liveLinks.forEach((l, i) => linkSlots.set(l, cloneLinks[i]));
|
|
328
|
+
const { offscreen, pins, backgrounds } = replayLiveState(live, clone);
|
|
329
|
+
fillScriptedStyleElements(live, clone);
|
|
330
|
+
const hidden = [
|
|
331
|
+
ALWAYS_REDACT_SELECTORS,
|
|
332
|
+
...privacy?.redactSelectors ?? DEFAULT_REDACT_SELECTORS,
|
|
333
|
+
...privacy?.maskSelectors ?? [],
|
|
334
|
+
...privacy?.blockSelectors ?? []
|
|
335
|
+
];
|
|
336
|
+
inlineMedia(
|
|
337
|
+
Array.from(live.querySelectorAll(MEDIA_SELECTOR)),
|
|
338
|
+
Array.from(clone.querySelectorAll(MEDIA_SELECTOR)),
|
|
339
|
+
(el) => offscreen.has(el) || hidden.some((selector) => matchesOrInside(el, selector))
|
|
340
|
+
);
|
|
341
|
+
pinOffscreen(pins);
|
|
342
|
+
await inlineBackgrounds(backgrounds.filter((bg) => !hidden.some((selector) => matchesOrInside(bg.live, selector))));
|
|
343
|
+
clone.querySelector("#mushi-mushi-widget")?.remove();
|
|
344
|
+
await inlineDocumentStyles(clone, linkSlots);
|
|
345
|
+
stripTaintSources(clone);
|
|
346
|
+
makeXmlSafe(clone);
|
|
347
|
+
freezeMotion(clone);
|
|
348
|
+
fillViewport(clone);
|
|
349
|
+
const redactSelectors = [
|
|
350
|
+
ALWAYS_REDACT_SELECTORS,
|
|
351
|
+
...privacy?.redactSelectors ?? DEFAULT_REDACT_SELECTORS
|
|
352
|
+
];
|
|
353
|
+
for (const selector of redactSelectors) {
|
|
354
|
+
for (const el of safeQueryAll(clone, selector)) {
|
|
355
|
+
redactElement(el);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
for (const selector of privacy?.blockSelectors ?? []) {
|
|
359
|
+
for (const el of safeQueryAll(clone, selector)) {
|
|
360
|
+
el.remove();
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
for (const selector of privacy?.maskSelectors ?? []) {
|
|
364
|
+
for (const el of safeQueryAll(clone, selector)) {
|
|
365
|
+
maskElement(el);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return clone;
|
|
369
|
+
}
|
|
370
|
+
function replayLiveState(live, clone) {
|
|
371
|
+
const offscreen = /* @__PURE__ */ new Set();
|
|
372
|
+
const pins = [];
|
|
373
|
+
const backgrounds = [];
|
|
374
|
+
const liveAll = [live, ...Array.from(live.querySelectorAll("*"))];
|
|
375
|
+
const cloneAll = [clone, ...Array.from(clone.querySelectorAll("*"))];
|
|
376
|
+
if (liveAll.length !== cloneAll.length) return { offscreen, pins, backgrounds };
|
|
377
|
+
const animated = animationTargets();
|
|
378
|
+
const styles = [];
|
|
379
|
+
const scroller = document.scrollingElement;
|
|
380
|
+
const pending = /* @__PURE__ */ new Map();
|
|
381
|
+
const set = (el, prop, value) => {
|
|
382
|
+
let decls = pending.get(el);
|
|
383
|
+
if (!decls) pending.set(el, decls = /* @__PURE__ */ new Map());
|
|
384
|
+
decls.set(prop, value);
|
|
385
|
+
};
|
|
386
|
+
const scrolled = [];
|
|
387
|
+
const withBackground = [];
|
|
388
|
+
let inBody = false;
|
|
389
|
+
for (let i = 0; i < liveAll.length; i++) {
|
|
390
|
+
const liveEl = liveAll[i];
|
|
391
|
+
const cloneEl = cloneAll[i];
|
|
392
|
+
const computed = getComputedStyle(liveEl);
|
|
393
|
+
styles.push(computed);
|
|
394
|
+
if (liveEl === document.body) inBody = true;
|
|
395
|
+
if (inBody) {
|
|
396
|
+
if (computed.display === "none") set(cloneEl, "display", "none");
|
|
397
|
+
else {
|
|
398
|
+
const parent = liveEl.parentElement;
|
|
399
|
+
if (computed.visibility !== "visible" && parent && getComputedStyle(parent).visibility === "visible") {
|
|
400
|
+
set(cloneEl, "visibility", computed.visibility);
|
|
401
|
+
}
|
|
402
|
+
if (computed.opacity === "0") set(cloneEl, "opacity", "0");
|
|
403
|
+
if (computed.backgroundImage.includes("url(")) withBackground.push(i);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (animated.has(liveEl)) {
|
|
407
|
+
for (const p of ANIMATED_PROPERTIES) set(cloneEl, p, computed.getPropertyValue(p));
|
|
408
|
+
}
|
|
409
|
+
if (computed.position === "sticky" && liveEl instanceof HTMLElement) {
|
|
410
|
+
const offset = stickyOffset(liveEl);
|
|
411
|
+
if (offset) {
|
|
412
|
+
set(cloneEl, "position", "relative");
|
|
413
|
+
set(cloneEl, "top", `${offset.top}px`);
|
|
414
|
+
set(cloneEl, "left", `${offset.left}px`);
|
|
415
|
+
set(cloneEl, "bottom", "auto");
|
|
416
|
+
set(cloneEl, "right", "auto");
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (liveEl !== scroller && (liveEl.scrollTop > 0 || liveEl.scrollLeft > 0)) scrolled.push(i);
|
|
420
|
+
}
|
|
421
|
+
for (const i of scrolled) {
|
|
422
|
+
const liveEl = liveAll[i];
|
|
423
|
+
const liveKids = liveEl.children;
|
|
424
|
+
const cloneKids = cloneAll[i].children;
|
|
425
|
+
for (let j = 0; j < liveKids.length && j < cloneKids.length; j++) {
|
|
426
|
+
const kid = getComputedStyle(liveKids[j]);
|
|
427
|
+
if (kid.position === "fixed") continue;
|
|
428
|
+
const own = pending.get(cloneKids[j])?.get("transform") ?? kid.transform;
|
|
429
|
+
const shift = `translate(${-liveEl.scrollLeft}px, ${-liveEl.scrollTop}px)`;
|
|
430
|
+
set(cloneKids[j], "transform", own && own !== "none" ? `${shift} ${own}` : shift);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
if (window.scrollX || window.scrollY) {
|
|
434
|
+
set(clone, "position", "relative");
|
|
435
|
+
set(clone, "top", `${-window.scrollY}px`);
|
|
436
|
+
set(clone, "left", `${-window.scrollX}px`);
|
|
437
|
+
}
|
|
438
|
+
for (const [el, decls] of pending) {
|
|
439
|
+
const held = Array.from(decls, ([p, v]) => `${p}:${v}!important`).join(";");
|
|
440
|
+
el.setAttribute("style", `${el.getAttribute("style") ?? ""};${held}`);
|
|
441
|
+
}
|
|
442
|
+
findOffscreen(liveAll, cloneAll, styles, offscreen, pins);
|
|
443
|
+
for (const i of withBackground) {
|
|
444
|
+
if (!offscreen.has(liveAll[i])) {
|
|
445
|
+
backgrounds.push({ live: liveAll[i], clone: cloneAll[i], value: styles[i].backgroundImage });
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return { offscreen, pins, backgrounds };
|
|
449
|
+
}
|
|
450
|
+
async function inlineBackgrounds(backgrounds) {
|
|
451
|
+
const urls = /* @__PURE__ */ new Map();
|
|
452
|
+
let bytes = 0;
|
|
453
|
+
const load = (url) => {
|
|
454
|
+
let pending = urls.get(url);
|
|
455
|
+
if (!pending) {
|
|
456
|
+
pending = urls.size >= MAX_BACKGROUND_URLS ? Promise.resolve(null) : readAsDataUrl(url).then((data) => {
|
|
457
|
+
if (!data || bytes + data.length > MAX_BACKGROUND_BYTES) return null;
|
|
458
|
+
bytes += data.length;
|
|
459
|
+
return data;
|
|
460
|
+
});
|
|
461
|
+
urls.set(url, pending);
|
|
462
|
+
}
|
|
463
|
+
return pending;
|
|
464
|
+
};
|
|
465
|
+
await Promise.all(
|
|
466
|
+
backgrounds.map(async (bg) => {
|
|
467
|
+
const refs = Array.from(bg.value.matchAll(CSS_URL), (m) => m[2].trim()).filter((u) => !u.startsWith("data:"));
|
|
468
|
+
if (refs.length === 0) return;
|
|
469
|
+
const data = await Promise.all(refs.map(load));
|
|
470
|
+
let value = bg.value;
|
|
471
|
+
refs.forEach((ref, k) => {
|
|
472
|
+
if (data[k]) value = value.split(ref).join(data[k]);
|
|
473
|
+
});
|
|
474
|
+
if (value !== bg.value) {
|
|
475
|
+
bg.clone.setAttribute("style", `${bg.clone.getAttribute("style") ?? ""};background-image:${value}!important`);
|
|
476
|
+
}
|
|
477
|
+
})
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
async function readAsDataUrl(url) {
|
|
481
|
+
if (typeof fetch !== "function") return null;
|
|
482
|
+
const abort = typeof AbortController === "function" ? new AbortController() : null;
|
|
483
|
+
const timer = setTimeout(() => abort?.abort(), SHEET_FETCH_TIMEOUT_MS);
|
|
484
|
+
try {
|
|
485
|
+
const res = await fetch(url, { cache: "force-cache", signal: abort?.signal });
|
|
486
|
+
if (!res.ok) return null;
|
|
487
|
+
const blob = await res.blob();
|
|
488
|
+
if (blob.size > MAX_BACKGROUND_IMAGE_BYTES || !blob.type.startsWith("image/")) return null;
|
|
489
|
+
const bytes = new Uint8Array(await blob.arrayBuffer());
|
|
490
|
+
let binary = "";
|
|
491
|
+
for (let i = 0; i < bytes.length; i += 32768) {
|
|
492
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + 32768));
|
|
493
|
+
}
|
|
494
|
+
return `data:${blob.type};base64,${btoa(binary)}`;
|
|
495
|
+
} catch {
|
|
496
|
+
return null;
|
|
497
|
+
} finally {
|
|
498
|
+
clearTimeout(timer);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
function findOffscreen(liveAll, cloneAll, styles, offscreen, pins) {
|
|
502
|
+
const bodyIndex = document.body ? liveAll.indexOf(document.body) : -1;
|
|
503
|
+
if (bodyIndex < 0) return;
|
|
504
|
+
const vw = window.innerWidth;
|
|
505
|
+
const vh = window.innerHeight;
|
|
506
|
+
const index = /* @__PURE__ */ new Map();
|
|
507
|
+
const visible = new Array(liveAll.length).fill(false);
|
|
508
|
+
const outside = new Array(liveAll.length).fill(false);
|
|
509
|
+
for (let i = bodyIndex; i < liveAll.length; i++) index.set(liveAll[i], i);
|
|
510
|
+
visible[bodyIndex] = true;
|
|
511
|
+
for (let i = liveAll.length - 1; i > bodyIndex; i--) {
|
|
512
|
+
const el = liveAll[i];
|
|
513
|
+
const r = el.getBoundingClientRect();
|
|
514
|
+
if (r.width > 0 || r.height > 0) {
|
|
515
|
+
if (r.bottom > 0 && r.top < vh && r.right > 0 && r.left < vw) visible[i] = true;
|
|
516
|
+
else outside[i] = true;
|
|
517
|
+
}
|
|
518
|
+
if (styles[i].position === "fixed") visible[i] = true;
|
|
519
|
+
if (visible[i]) {
|
|
520
|
+
outside[i] = false;
|
|
521
|
+
const parent = el.parentElement ? index.get(el.parentElement) : void 0;
|
|
522
|
+
if (parent !== void 0) visible[parent] = true;
|
|
523
|
+
} else if (outside[i]) {
|
|
524
|
+
offscreen.add(el);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
const covered = new Array(liveAll.length).fill(false);
|
|
528
|
+
for (let i = bodyIndex + 1; i < liveAll.length; i++) {
|
|
529
|
+
const el = liveAll[i];
|
|
530
|
+
const parentIndex = el.parentElement ? index.get(el.parentElement) : void 0;
|
|
531
|
+
if (parentIndex === void 0) continue;
|
|
532
|
+
if (covered[parentIndex]) {
|
|
533
|
+
covered[i] = true;
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
if (!outside[i] || !(el instanceof HTMLElement)) continue;
|
|
537
|
+
const s = styles[i];
|
|
538
|
+
if (!PINNABLE_DISPLAY.test(s.display)) continue;
|
|
539
|
+
covered[i] = true;
|
|
540
|
+
const inFlow = BLOCK_FLOW.test(styles[parentIndex].display) && s.float === "none" && (s.position === "static" || s.position === "relative");
|
|
541
|
+
pins.push({
|
|
542
|
+
clone: cloneAll[i],
|
|
543
|
+
width: el.offsetWidth,
|
|
544
|
+
height: el.offsetHeight,
|
|
545
|
+
marginTop: inFlow ? gapAbove(el) : null,
|
|
546
|
+
marginBottom: inFlow ? gapBelow(el) : null
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
function gapAbove(el) {
|
|
551
|
+
const prev = el.previousElementSibling;
|
|
552
|
+
if (!(prev instanceof HTMLElement) || prev.offsetParent !== el.offsetParent) return null;
|
|
553
|
+
return Math.max(0, el.offsetTop - (prev.offsetTop + prev.offsetHeight));
|
|
554
|
+
}
|
|
555
|
+
function gapBelow(el) {
|
|
556
|
+
const next = el.nextElementSibling;
|
|
557
|
+
if (!(next instanceof HTMLElement) || next.offsetParent !== el.offsetParent) return null;
|
|
558
|
+
return Math.max(0, next.offsetTop - (el.offsetTop + el.offsetHeight));
|
|
559
|
+
}
|
|
560
|
+
function pinOffscreen(pins) {
|
|
561
|
+
for (const pin of pins) {
|
|
562
|
+
pin.clone.replaceChildren();
|
|
563
|
+
let pinned = `width:${pin.width}px!important;height:${pin.height}px!important;box-sizing:border-box!important;min-width:0!important;min-height:0!important;max-width:none!important;max-height:none!important;content-visibility:visible!important;contain:none!important;`;
|
|
564
|
+
if (pin.marginTop !== null) pinned += `margin-top:${pin.marginTop}px!important;`;
|
|
565
|
+
if (pin.marginBottom !== null) pinned += `margin-bottom:${pin.marginBottom}px!important;`;
|
|
566
|
+
pin.clone.setAttribute("style", `${pin.clone.getAttribute("style") ?? ""};${pinned}`);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function animationTargets() {
|
|
570
|
+
try {
|
|
571
|
+
return new Set(
|
|
572
|
+
document.getAnimations().map((a) => a.effect?.target).filter((t) => t instanceof Element && !t.pseudoElement)
|
|
573
|
+
);
|
|
574
|
+
} catch {
|
|
575
|
+
return /* @__PURE__ */ new Set();
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
function stickyOffset(el) {
|
|
579
|
+
const stuck = el.getBoundingClientRect();
|
|
580
|
+
const value = el.style.getPropertyValue("position");
|
|
581
|
+
const priority = el.style.getPropertyPriority("position");
|
|
582
|
+
el.style.setProperty("position", "static", "important");
|
|
583
|
+
const flow = el.getBoundingClientRect();
|
|
584
|
+
el.style.removeProperty("position");
|
|
585
|
+
if (value) el.style.setProperty("position", value, priority);
|
|
586
|
+
const top = stuck.top - flow.top;
|
|
587
|
+
const left = stuck.left - flow.left;
|
|
588
|
+
return top || left ? { top, left } : null;
|
|
589
|
+
}
|
|
590
|
+
function inlineMedia(liveMedia, clonedMedia, isHidden) {
|
|
591
|
+
let count = 0;
|
|
592
|
+
let bytes = 0;
|
|
593
|
+
for (let i = 0; i < clonedMedia.length; i++) {
|
|
594
|
+
const cloned = clonedMedia[i];
|
|
595
|
+
const liveEl = liveMedia[i];
|
|
596
|
+
const rect = liveEl?.getBoundingClientRect();
|
|
597
|
+
const layout = liveEl instanceof HTMLElement && liveEl.offsetWidth > 0 ? { width: liveEl.offsetWidth, height: liveEl.offsetHeight } : rect && { width: rect.width, height: rect.height };
|
|
598
|
+
let pixels = null;
|
|
599
|
+
if (liveEl && layout && layout.width > 0 && layout.height > 0 && count < MAX_INLINED_MEDIA && bytes < MAX_INLINED_BYTES && !isHidden(liveEl)) {
|
|
600
|
+
pixels = readPixels(liveEl);
|
|
601
|
+
if (pixels) {
|
|
602
|
+
count++;
|
|
603
|
+
bytes += pixels.url.length;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
replaceMedia(cloned, pixels, layout);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
function readPixels(el) {
|
|
610
|
+
try {
|
|
611
|
+
let source = null;
|
|
612
|
+
let width = 0;
|
|
613
|
+
let height = 0;
|
|
614
|
+
if (el instanceof HTMLCanvasElement) {
|
|
615
|
+
[source, width, height] = [el, el.width, el.height];
|
|
616
|
+
} else if (el instanceof HTMLImageElement && el.complete && el.naturalWidth > 0) {
|
|
617
|
+
[source, width, height] = [el, el.naturalWidth, el.naturalHeight];
|
|
618
|
+
} else if (el instanceof HTMLVideoElement && el.readyState >= 2) {
|
|
619
|
+
[source, width, height] = [el, el.videoWidth, el.videoHeight];
|
|
620
|
+
}
|
|
621
|
+
if (!source || width <= 0 || height <= 0) return null;
|
|
622
|
+
const scale = Math.min(1, MAX_IMAGE_SIDE / Math.max(width, height));
|
|
623
|
+
const canvas = document.createElement("canvas");
|
|
624
|
+
canvas.width = Math.max(1, Math.round(width * scale));
|
|
625
|
+
canvas.height = Math.max(1, Math.round(height * scale));
|
|
626
|
+
const ctx = canvas.getContext("2d");
|
|
627
|
+
if (!ctx) return null;
|
|
628
|
+
ctx.drawImage(source, 0, 0, canvas.width, canvas.height);
|
|
629
|
+
const url = canvas.toDataURL("image/webp", 0.85);
|
|
630
|
+
return url === "data:," ? null : { url, width, height };
|
|
631
|
+
} catch {
|
|
632
|
+
return null;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
function matchesOrInside(el, selector) {
|
|
636
|
+
try {
|
|
637
|
+
return el.closest(selector) !== null;
|
|
638
|
+
} catch {
|
|
639
|
+
return false;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
function replaceMedia(cloned, pixels, layout) {
|
|
643
|
+
const box = cloned.ownerDocument.createElement(pixels ? "img" : "div");
|
|
644
|
+
for (const name of cloned.getAttributeNames()) {
|
|
645
|
+
if (!SOURCE_ATTRIBUTES.has(name)) box.setAttribute(name, cloned.getAttribute(name) ?? "");
|
|
646
|
+
}
|
|
647
|
+
const size = layout ? `width:${layout.width}px;height:${layout.height}px;` : "";
|
|
648
|
+
if (pixels) {
|
|
649
|
+
box.setAttribute("src", pixels.url);
|
|
650
|
+
box.setAttribute("alt", "");
|
|
651
|
+
if (!box.hasAttribute("width")) box.setAttribute("width", String(pixels.width));
|
|
652
|
+
if (!box.hasAttribute("height")) box.setAttribute("height", String(pixels.height));
|
|
653
|
+
box.setAttribute("style", `${box.getAttribute("style") ?? ""};${size}`);
|
|
654
|
+
} else {
|
|
655
|
+
box.setAttribute(
|
|
656
|
+
"style",
|
|
657
|
+
`${box.getAttribute("style") ?? ""};${size}background:#d4d4d4!important;display:${cloned.tagName === "IMG" || cloned.tagName === "CANVAS" ? "inline-block" : "block"};`
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
const parent = cloned.parentElement;
|
|
661
|
+
const target = parent && parent.tagName === "PICTURE" ? parent : cloned;
|
|
662
|
+
target.replaceWith(box);
|
|
663
|
+
}
|
|
664
|
+
function makeXmlSafe(root) {
|
|
665
|
+
const doc = root.ownerDocument;
|
|
666
|
+
const walker = doc.createTreeWalker(root, NodeFilter.SHOW_COMMENT);
|
|
667
|
+
const comments = [];
|
|
668
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) comments.push(n);
|
|
669
|
+
for (const c of comments) c.parentNode?.removeChild(c);
|
|
670
|
+
for (const el of [root, ...Array.from(root.querySelectorAll("*"))]) {
|
|
671
|
+
for (const name of el.getAttributeNames()) {
|
|
672
|
+
if (!XML_ATTRIBUTE_NAME.test(name)) el.removeAttribute(name);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
function safeQueryAll(root, selector) {
|
|
677
|
+
try {
|
|
678
|
+
return Array.from(root.querySelectorAll(selector));
|
|
679
|
+
} catch {
|
|
680
|
+
return [];
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
function redactElement(el) {
|
|
684
|
+
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
|
|
685
|
+
el.value = "";
|
|
686
|
+
el.setAttribute("value", "");
|
|
687
|
+
}
|
|
688
|
+
el.textContent = "";
|
|
689
|
+
el.setAttribute(
|
|
690
|
+
"style",
|
|
691
|
+
`${el.getAttribute("style") ?? ""};background:#000!important;color:#000!important;text-shadow:none!important;border-color:#000!important;`
|
|
692
|
+
);
|
|
693
|
+
el.setAttribute("data-mushi-redacted", "true");
|
|
694
|
+
while (el.firstChild) el.removeChild(el.firstChild);
|
|
695
|
+
}
|
|
696
|
+
function stripTaintSources(root) {
|
|
697
|
+
const pageOrigin = typeof location !== "undefined" ? location.origin : "";
|
|
698
|
+
for (const link of root.querySelectorAll('link[rel="stylesheet"], link[as="style"]')) {
|
|
699
|
+
link.remove();
|
|
700
|
+
}
|
|
701
|
+
for (const styleEl of root.querySelectorAll("style")) {
|
|
702
|
+
const cleaned = stripCssUrlRefs(styleEl.textContent ?? "", pageOrigin);
|
|
703
|
+
if (cleaned !== styleEl.textContent) styleEl.textContent = cleaned;
|
|
704
|
+
}
|
|
705
|
+
for (const el of root.querySelectorAll("[style]")) {
|
|
706
|
+
const s = el.getAttribute("style");
|
|
707
|
+
if (!s) continue;
|
|
708
|
+
const cleaned = stripCssUrlRefs(s, pageOrigin);
|
|
709
|
+
if (cleaned !== s) el.setAttribute("style", cleaned);
|
|
710
|
+
}
|
|
711
|
+
for (const script of root.querySelectorAll("script, noscript, template")) {
|
|
712
|
+
script.remove();
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
function stripCssUrlRefs(css, pageOrigin) {
|
|
716
|
+
return css.replace(/url\(\s*(['"]?)([^)'"]+)\1\s*\)/gi, (_match, _q, href) => {
|
|
717
|
+
const trimmed = href.trim();
|
|
718
|
+
if (!trimmed || trimmed.startsWith("data:") || trimmed.startsWith("#")) return _match;
|
|
719
|
+
if (isCrossOriginUrl(trimmed, pageOrigin)) return "none";
|
|
720
|
+
return _match;
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
async function inlineDocumentStyles(clone, linkSlots) {
|
|
724
|
+
const sheets = [
|
|
725
|
+
...Array.from(document.styleSheets),
|
|
726
|
+
...document.adoptedStyleSheets ?? []
|
|
727
|
+
];
|
|
728
|
+
const texts = await Promise.all(
|
|
729
|
+
sheets.map(async (sheet) => {
|
|
730
|
+
const owner = sheet.ownerNode;
|
|
731
|
+
if (sheet.disabled || owner instanceof Element && owner.tagName === "STYLE") return "";
|
|
732
|
+
return withMedia(await sheetSource(sheet) ?? serializeSheet(sheet), sheet);
|
|
733
|
+
})
|
|
734
|
+
);
|
|
735
|
+
const head = clone.querySelector("head") ?? clone;
|
|
736
|
+
sheets.forEach((sheet, i) => {
|
|
737
|
+
if (!texts[i]) return;
|
|
738
|
+
const styleEl = document.createElement("style");
|
|
739
|
+
styleEl.textContent = texts[i];
|
|
740
|
+
const slot = sheet.ownerNode ? linkSlots.get(sheet.ownerNode) : void 0;
|
|
741
|
+
if (slot && clone.contains(slot)) slot.replaceWith(styleEl);
|
|
742
|
+
else head.appendChild(styleEl);
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
async function sheetSource(sheet, depth = 0) {
|
|
746
|
+
const href = sheet.href;
|
|
747
|
+
if (!href || depth > 3 || typeof fetch !== "function") return null;
|
|
748
|
+
const abort = typeof AbortController === "function" ? new AbortController() : null;
|
|
749
|
+
const timer = setTimeout(() => abort?.abort(), SHEET_FETCH_TIMEOUT_MS);
|
|
750
|
+
try {
|
|
751
|
+
const res = await fetch(href, { cache: "force-cache", signal: abort?.signal });
|
|
752
|
+
if (!res.ok) return null;
|
|
753
|
+
let imported = "";
|
|
754
|
+
for (const rule of readableRules(sheet)) {
|
|
755
|
+
if (!(rule instanceof CSSImportRule) || !rule.styleSheet) continue;
|
|
756
|
+
const text = await sheetSource(rule.styleSheet, depth + 1) ?? serializeSheet(rule.styleSheet);
|
|
757
|
+
imported += wrapImport(text, rule);
|
|
758
|
+
}
|
|
759
|
+
const own = absolutizeCssUrls((await res.text()).replace(/@import\s[^;]*;/gi, ""), href);
|
|
760
|
+
return `${imported}
|
|
761
|
+
${own}`;
|
|
762
|
+
} catch {
|
|
763
|
+
return null;
|
|
764
|
+
} finally {
|
|
765
|
+
clearTimeout(timer);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
function readableRules(sheet) {
|
|
769
|
+
try {
|
|
770
|
+
return Array.from(sheet.cssRules);
|
|
771
|
+
} catch {
|
|
772
|
+
return [];
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
function wrapImport(text, rule) {
|
|
776
|
+
const layer = rule.layerName;
|
|
777
|
+
let out = layer == null ? text : `@layer ${layer}{${text}}`;
|
|
778
|
+
const media = rule.media?.mediaText;
|
|
779
|
+
if (media && media !== "all") out = `@media ${media}{${out}}`;
|
|
780
|
+
return `${out}
|
|
781
|
+
`;
|
|
782
|
+
}
|
|
783
|
+
function withMedia(text, sheet) {
|
|
784
|
+
const media = sheet.media?.mediaText;
|
|
785
|
+
return text && media && media !== "all" ? `@media ${media}{${text}}` : text;
|
|
786
|
+
}
|
|
787
|
+
function absolutizeCssUrls(css, base) {
|
|
788
|
+
return css.replace(/url\(\s*(['"]?)([^)'"]+)\1\s*\)/gi, (match, quote, ref) => {
|
|
789
|
+
const trimmed = ref.trim();
|
|
790
|
+
if (!trimmed || /^(data:|#|[a-z][a-z\d+.-]*:)/i.test(trimmed)) return match;
|
|
791
|
+
try {
|
|
792
|
+
return `url(${quote}${new URL(trimmed, base).href}${quote})`;
|
|
793
|
+
} catch {
|
|
794
|
+
return match;
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
function fillScriptedStyleElements(live, clone) {
|
|
799
|
+
const liveStyles = live.querySelectorAll("style");
|
|
800
|
+
const cloneStyles = clone.querySelectorAll("style");
|
|
801
|
+
if (liveStyles.length !== cloneStyles.length) return;
|
|
802
|
+
liveStyles.forEach((el, i) => {
|
|
803
|
+
if ((el.textContent ?? "").trim() || !el.sheet) return;
|
|
804
|
+
const text = serializeSheet(el.sheet);
|
|
805
|
+
if (text) cloneStyles[i].textContent = text;
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
function fillViewport(clone) {
|
|
809
|
+
const clear = (c) => !c || c === "transparent" || /^rgba\(.*,\s*0\)$/.test(c);
|
|
810
|
+
let bg = getComputedStyle(document.documentElement).backgroundColor;
|
|
811
|
+
if (clear(bg) && document.body) bg = getComputedStyle(document.body).backgroundColor;
|
|
812
|
+
const root = clone;
|
|
813
|
+
root.style.setProperty("background-color", clear(bg) ? "Canvas" : bg);
|
|
814
|
+
root.style.setProperty("min-height", `${window.innerHeight}px`);
|
|
815
|
+
}
|
|
816
|
+
function freezeMotion(clone) {
|
|
817
|
+
const styleEl = document.createElement("style");
|
|
818
|
+
styleEl.textContent = FREEZE_MOTION_CSS;
|
|
819
|
+
(clone.querySelector("head") ?? clone).appendChild(styleEl);
|
|
820
|
+
}
|
|
821
|
+
function serializeSheet(sheet) {
|
|
822
|
+
let rules;
|
|
823
|
+
try {
|
|
824
|
+
rules = sheet.cssRules;
|
|
825
|
+
} catch {
|
|
826
|
+
return "";
|
|
827
|
+
}
|
|
828
|
+
let text = "";
|
|
829
|
+
for (const rule of Array.from(rules)) {
|
|
830
|
+
if (rule instanceof CSSImportRule) {
|
|
831
|
+
if (rule.styleSheet) text += serializeSheet(rule.styleSheet);
|
|
832
|
+
continue;
|
|
833
|
+
}
|
|
834
|
+
text += `${rule.cssText}
|
|
835
|
+
`;
|
|
836
|
+
}
|
|
837
|
+
return text;
|
|
838
|
+
}
|
|
839
|
+
function isCanvasBlank(ctx, width, height) {
|
|
840
|
+
try {
|
|
841
|
+
const stepX = Math.max(1, Math.floor(width / 8));
|
|
842
|
+
const stepY = Math.max(1, Math.floor(height / 8));
|
|
843
|
+
for (let y = 0; y < height; y += stepY) {
|
|
844
|
+
for (let x = 0; x < width; x += stepX) {
|
|
845
|
+
if (ctx.getImageData(x, y, 1, 1).data[3] !== 0) return false;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
return true;
|
|
849
|
+
} catch {
|
|
850
|
+
return false;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
function isCrossOriginUrl(raw, pageOrigin) {
|
|
854
|
+
if (!raw || raw.startsWith("data:") || raw.startsWith("blob:")) return false;
|
|
855
|
+
try {
|
|
856
|
+
const resolved = new URL(raw, typeof location !== "undefined" ? location.href : "http://localhost/");
|
|
857
|
+
return Boolean(pageOrigin) && resolved.origin !== pageOrigin;
|
|
858
|
+
} catch {
|
|
859
|
+
return true;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
function maskElement(el) {
|
|
863
|
+
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
|
|
864
|
+
el.value = "";
|
|
865
|
+
el.setAttribute("value", "");
|
|
866
|
+
el.setAttribute("placeholder", "\u2022\u2022\u2022\u2022");
|
|
867
|
+
}
|
|
868
|
+
el.textContent = el.children.length === 0 ? "\u2022\u2022\u2022\u2022" : el.textContent;
|
|
869
|
+
el.setAttribute(
|
|
870
|
+
"style",
|
|
871
|
+
`${el.getAttribute("style") ?? ""};background:#8f8f8f!important;color:transparent!important;text-shadow:none!important;`
|
|
872
|
+
);
|
|
873
|
+
el.setAttribute("data-mushi-masked", "true");
|
|
874
|
+
}
|
|
875
|
+
var XML_INVALID_CHARS, XML_ATTRIBUTE_NAME, MAX_INLINED_MEDIA, MAX_INLINED_BYTES, MEDIA_SELECTOR, DEFAULT_REDACT_SELECTORS, ANIMATED_PROPERTIES, MAX_BACKGROUND_URLS, MAX_BACKGROUND_BYTES, MAX_BACKGROUND_IMAGE_BYTES, CSS_URL, PINNABLE_DISPLAY, BLOCK_FLOW, MAX_IMAGE_SIDE, SOURCE_ATTRIBUTES, SHEET_FETCH_TIMEOUT_MS, FREEZE_MOTION_CSS;
|
|
876
|
+
var init_screenshot_dom = __esm({
|
|
877
|
+
"src/capture/screenshot-dom.ts"() {
|
|
878
|
+
init_screenshot();
|
|
879
|
+
XML_INVALID_CHARS = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
|
|
880
|
+
XML_ATTRIBUTE_NAME = /^[A-Za-z_][\w.:-]*$/;
|
|
881
|
+
MAX_INLINED_MEDIA = 60;
|
|
882
|
+
MAX_INLINED_BYTES = 12 * 1024 * 1024;
|
|
883
|
+
MEDIA_SELECTOR = "img, video, canvas, iframe, object, embed";
|
|
884
|
+
DEFAULT_REDACT_SELECTORS = ["[data-mushi-redact]"];
|
|
885
|
+
ANIMATED_PROPERTIES = [
|
|
886
|
+
"transform",
|
|
887
|
+
"translate",
|
|
888
|
+
"scale",
|
|
889
|
+
"rotate",
|
|
890
|
+
"opacity",
|
|
891
|
+
"visibility",
|
|
892
|
+
"clip-path",
|
|
893
|
+
"object-position",
|
|
894
|
+
"background-position",
|
|
895
|
+
"left",
|
|
896
|
+
"top",
|
|
897
|
+
"width",
|
|
898
|
+
"height",
|
|
899
|
+
"color",
|
|
900
|
+
"background-color"
|
|
901
|
+
];
|
|
902
|
+
MAX_BACKGROUND_URLS = 40;
|
|
903
|
+
MAX_BACKGROUND_BYTES = 6 * 1024 * 1024;
|
|
904
|
+
MAX_BACKGROUND_IMAGE_BYTES = 2 * 1024 * 1024;
|
|
905
|
+
CSS_URL = /url\(\s*(['"]?)([^)'"]+)\1\s*\)/gi;
|
|
906
|
+
PINNABLE_DISPLAY = /^(block|flow-root|flex|grid|list-item|inline-block|inline-flex|inline-grid|table)$/;
|
|
907
|
+
BLOCK_FLOW = /^(block|flow-root|list-item)$/;
|
|
908
|
+
MAX_IMAGE_SIDE = 2048;
|
|
909
|
+
SOURCE_ATTRIBUTES = /* @__PURE__ */ new Set(["src", "srcset", "sizes", "poster", "data", "loading", "decoding"]);
|
|
910
|
+
SHEET_FETCH_TIMEOUT_MS = 2500;
|
|
911
|
+
FREEZE_MOTION_CSS = "*,*::before,*::after{animation:none!important;transition:none!important}";
|
|
912
|
+
}
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
// src/capture/screenshot.ts
|
|
916
|
+
function createScreenshotCapture(options = {}) {
|
|
917
|
+
let activeOptions = options;
|
|
918
|
+
const fail = (reason) => {
|
|
919
|
+
activeOptions.onFailed?.(reason);
|
|
920
|
+
emitScreenshotFailed(reason);
|
|
921
|
+
};
|
|
922
|
+
async function take() {
|
|
923
|
+
try {
|
|
924
|
+
if (typeof document === "undefined") return null;
|
|
925
|
+
const { captureDomScreenshot: captureDomScreenshot2 } = await Promise.resolve().then(() => (init_screenshot_dom(), screenshot_dom_exports));
|
|
926
|
+
return await captureDomScreenshot2(activeOptions.privacy, fail);
|
|
927
|
+
} catch {
|
|
928
|
+
fail("error");
|
|
929
|
+
return null;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
return {
|
|
933
|
+
take,
|
|
934
|
+
updateOptions(nextOptions) {
|
|
935
|
+
activeOptions = nextOptions;
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
function emitScreenshotFailed(reason) {
|
|
940
|
+
try {
|
|
941
|
+
document.dispatchEvent(new CustomEvent("mushi:screenshot_failed", { detail: { reason }, bubbles: false }));
|
|
942
|
+
} catch {
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
var ALWAYS_REDACT_SELECTORS;
|
|
946
|
+
var init_screenshot = __esm({
|
|
947
|
+
"src/capture/screenshot.ts"() {
|
|
948
|
+
ALWAYS_REDACT_SELECTORS = 'input[type="password"],input[autocomplete^="cc-"],[data-private],[data-mushi-mask]';
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
|
|
256
952
|
// src/journey-recording.ts
|
|
257
953
|
var journey_recording_exports = {};
|
|
258
954
|
__export(journey_recording_exports, {
|
|
@@ -5301,36 +5997,51 @@ function createConsoleCapture() {
|
|
|
5301
5997
|
const originals = {};
|
|
5302
5998
|
const wrappers = {};
|
|
5303
5999
|
const levels = ["log", "warn", "error", "info", "debug"];
|
|
6000
|
+
const str = (arg) => {
|
|
6001
|
+
if (arg instanceof Error) return `${arg.name}: ${arg.message}`;
|
|
6002
|
+
try {
|
|
6003
|
+
return typeof arg === "string" ? arg : JSON.stringify(arg);
|
|
6004
|
+
} catch {
|
|
6005
|
+
return String(arg);
|
|
6006
|
+
}
|
|
6007
|
+
};
|
|
6008
|
+
const record = (level, message, err, extra) => {
|
|
6009
|
+
const entry = { level, message: message.slice(0, MAX_MESSAGE_LENGTH), timestamp: Date.now(), ...extra };
|
|
6010
|
+
if (err instanceof Error && err.stack) entry.stack = err.stack.slice(0, 1e3);
|
|
6011
|
+
entries.push(entry);
|
|
6012
|
+
if (entries.length > MAX_ENTRIES2) entries.shift();
|
|
6013
|
+
};
|
|
5304
6014
|
for (const level of levels) {
|
|
5305
6015
|
const original = console[level];
|
|
5306
6016
|
originals[level] = original;
|
|
5307
6017
|
const wrapper = (...args) => {
|
|
5308
|
-
const message = args.map((arg) => {
|
|
5309
|
-
try {
|
|
5310
|
-
return typeof arg === "string" ? arg : JSON.stringify(arg);
|
|
5311
|
-
} catch {
|
|
5312
|
-
return String(arg);
|
|
5313
|
-
}
|
|
5314
|
-
}).join(" ").slice(0, MAX_MESSAGE_LENGTH);
|
|
5315
6018
|
const correlationId = getActiveCorrelationId();
|
|
5316
|
-
|
|
6019
|
+
record(
|
|
5317
6020
|
level,
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
if (level === "error" && args[0] instanceof Error) {
|
|
5323
|
-
entry.stack = args[0].stack?.slice(0, 1e3);
|
|
5324
|
-
}
|
|
5325
|
-
entries.push(entry);
|
|
5326
|
-
if (entries.length > MAX_ENTRIES2) {
|
|
5327
|
-
entries.shift();
|
|
5328
|
-
}
|
|
6021
|
+
args.map(str).join(" "),
|
|
6022
|
+
level === "error" ? args.find((a) => a instanceof Error) : void 0,
|
|
6023
|
+
correlationId ? { correlationId } : void 0
|
|
6024
|
+
);
|
|
5329
6025
|
original.call(console, ...args);
|
|
5330
6026
|
};
|
|
5331
6027
|
wrappers[level] = wrapper;
|
|
5332
6028
|
console[level] = wrapper;
|
|
5333
6029
|
}
|
|
6030
|
+
const onUncaught = (event) => {
|
|
6031
|
+
if (event.type === "unhandledrejection") {
|
|
6032
|
+
const reason = event.reason;
|
|
6033
|
+
record("error", `Unhandled rejection: ${str(reason)}`, reason);
|
|
6034
|
+
} else {
|
|
6035
|
+
const e = event;
|
|
6036
|
+
const where = e.filename ? ` (${e.filename}:${e.lineno}:${e.colno})` : "";
|
|
6037
|
+
record("error", `Uncaught ${str(e.error ?? (e.message || "error"))}${where}`, e.error);
|
|
6038
|
+
}
|
|
6039
|
+
};
|
|
6040
|
+
const canListen = typeof window !== "undefined" && typeof window.addEventListener === "function";
|
|
6041
|
+
if (canListen) {
|
|
6042
|
+
window.addEventListener("error", onUncaught);
|
|
6043
|
+
window.addEventListener("unhandledrejection", onUncaught);
|
|
6044
|
+
}
|
|
5334
6045
|
return {
|
|
5335
6046
|
getEntries() {
|
|
5336
6047
|
return [...entries];
|
|
@@ -5344,261 +6055,16 @@ function createConsoleCapture() {
|
|
|
5344
6055
|
console[level] = originals[level];
|
|
5345
6056
|
}
|
|
5346
6057
|
}
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
// src/capture/screenshot.ts
|
|
5352
|
-
function createScreenshotCapture(options = {}) {
|
|
5353
|
-
let activeOptions = options;
|
|
5354
|
-
async function take() {
|
|
5355
|
-
try {
|
|
5356
|
-
if (typeof document === "undefined") return null;
|
|
5357
|
-
const canvas = document.createElement("canvas");
|
|
5358
|
-
const ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
5359
|
-
if (!ctx) {
|
|
5360
|
-
activeOptions.onFailed?.("unsupported");
|
|
5361
|
-
emitScreenshotFailed("unsupported");
|
|
5362
|
-
return null;
|
|
6058
|
+
if (canListen) {
|
|
6059
|
+
window.removeEventListener("error", onUncaught);
|
|
6060
|
+
window.removeEventListener("unhandledrejection", onUncaught);
|
|
5363
6061
|
}
|
|
5364
|
-
const width = window.innerWidth;
|
|
5365
|
-
const height = window.innerHeight;
|
|
5366
|
-
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
5367
|
-
canvas.width = width * dpr;
|
|
5368
|
-
canvas.height = height * dpr;
|
|
5369
|
-
ctx.scale(dpr, dpr);
|
|
5370
|
-
const safeDocument = buildPrivacySafeDocument(activeOptions.privacy);
|
|
5371
|
-
const svgData = `
|
|
5372
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}">
|
|
5373
|
-
<foreignObject width="100%" height="100%">
|
|
5374
|
-
<div xmlns="http://www.w3.org/1999/xhtml">
|
|
5375
|
-
${new XMLSerializer().serializeToString(safeDocument)}
|
|
5376
|
-
</div>
|
|
5377
|
-
</foreignObject>
|
|
5378
|
-
</svg>
|
|
5379
|
-
`;
|
|
5380
|
-
const img = new Image();
|
|
5381
|
-
const url = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgData)}`;
|
|
5382
|
-
let cspBlocked = false;
|
|
5383
|
-
const onViolation = (e) => {
|
|
5384
|
-
const v = e;
|
|
5385
|
-
if (/^img-src|^default-src/.test(v.violatedDirective ?? "") && /^data/.test(v.blockedURI ?? "")) cspBlocked = true;
|
|
5386
|
-
};
|
|
5387
|
-
document.addEventListener("securitypolicyviolation", onViolation);
|
|
5388
|
-
return new Promise((resolve) => {
|
|
5389
|
-
let settled = false;
|
|
5390
|
-
const settle = (value, reason) => {
|
|
5391
|
-
if (settled) return;
|
|
5392
|
-
settled = true;
|
|
5393
|
-
clearTimeout(timer);
|
|
5394
|
-
document.removeEventListener("securitypolicyviolation", onViolation);
|
|
5395
|
-
if (reason) {
|
|
5396
|
-
activeOptions.onFailed?.(reason);
|
|
5397
|
-
emitScreenshotFailed(reason);
|
|
5398
|
-
}
|
|
5399
|
-
resolve(value);
|
|
5400
|
-
};
|
|
5401
|
-
const timer = setTimeout(() => settle(null, "timeout"), 5e3);
|
|
5402
|
-
img.onload = () => {
|
|
5403
|
-
try {
|
|
5404
|
-
ctx.drawImage(img, 0, 0, width, height);
|
|
5405
|
-
if (isCanvasBlank(ctx, width, height)) {
|
|
5406
|
-
settle(null, "unsupported");
|
|
5407
|
-
return;
|
|
5408
|
-
}
|
|
5409
|
-
settle(canvas.toDataURL("image/jpeg", 0.7));
|
|
5410
|
-
} catch {
|
|
5411
|
-
settle(null, "taint");
|
|
5412
|
-
}
|
|
5413
|
-
};
|
|
5414
|
-
img.onerror = () => setTimeout(() => settle(null, cspBlocked ? "csp" : "error"), 0);
|
|
5415
|
-
img.src = url;
|
|
5416
|
-
});
|
|
5417
|
-
} catch {
|
|
5418
|
-
activeOptions.onFailed?.("error");
|
|
5419
|
-
emitScreenshotFailed("error");
|
|
5420
|
-
return null;
|
|
5421
|
-
}
|
|
5422
|
-
}
|
|
5423
|
-
return {
|
|
5424
|
-
take,
|
|
5425
|
-
updateOptions(nextOptions) {
|
|
5426
|
-
activeOptions = nextOptions;
|
|
5427
6062
|
}
|
|
5428
6063
|
};
|
|
5429
6064
|
}
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
} catch {
|
|
5434
|
-
}
|
|
5435
|
-
}
|
|
5436
|
-
var ALWAYS_REDACT_SELECTORS = 'input[type="password"],input[autocomplete^="cc-"],[data-private],[data-mushi-mask]';
|
|
5437
|
-
var DEFAULT_REDACT_SELECTORS = ["[data-mushi-redact]"];
|
|
5438
|
-
function buildPrivacySafeDocument(privacy) {
|
|
5439
|
-
const clone = document.documentElement.cloneNode(true);
|
|
5440
|
-
clone.querySelector("#mushi-mushi-widget")?.remove();
|
|
5441
|
-
stripTaintSources(clone);
|
|
5442
|
-
inlineDocumentStyles(clone);
|
|
5443
|
-
freezeMotion(clone);
|
|
5444
|
-
fillViewport(clone);
|
|
5445
|
-
const redactSelectors = [
|
|
5446
|
-
ALWAYS_REDACT_SELECTORS,
|
|
5447
|
-
...privacy?.redactSelectors ?? DEFAULT_REDACT_SELECTORS
|
|
5448
|
-
];
|
|
5449
|
-
for (const selector of redactSelectors) {
|
|
5450
|
-
for (const el of safeQueryAll(clone, selector)) {
|
|
5451
|
-
redactElement(el);
|
|
5452
|
-
}
|
|
5453
|
-
}
|
|
5454
|
-
for (const selector of privacy?.blockSelectors ?? []) {
|
|
5455
|
-
for (const el of safeQueryAll(clone, selector)) {
|
|
5456
|
-
el.remove();
|
|
5457
|
-
}
|
|
5458
|
-
}
|
|
5459
|
-
for (const selector of privacy?.maskSelectors ?? []) {
|
|
5460
|
-
for (const el of safeQueryAll(clone, selector)) {
|
|
5461
|
-
maskElement(el);
|
|
5462
|
-
}
|
|
5463
|
-
}
|
|
5464
|
-
return clone;
|
|
5465
|
-
}
|
|
5466
|
-
function safeQueryAll(root, selector) {
|
|
5467
|
-
try {
|
|
5468
|
-
return Array.from(root.querySelectorAll(selector));
|
|
5469
|
-
} catch {
|
|
5470
|
-
return [];
|
|
5471
|
-
}
|
|
5472
|
-
}
|
|
5473
|
-
function redactElement(el) {
|
|
5474
|
-
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
|
|
5475
|
-
el.value = "";
|
|
5476
|
-
el.setAttribute("value", "");
|
|
5477
|
-
}
|
|
5478
|
-
el.textContent = "";
|
|
5479
|
-
el.setAttribute(
|
|
5480
|
-
"style",
|
|
5481
|
-
`${el.getAttribute("style") ?? ""};background:#000!important;color:#000!important;text-shadow:none!important;border-color:#000!important;`
|
|
5482
|
-
);
|
|
5483
|
-
el.setAttribute("data-mushi-redacted", "true");
|
|
5484
|
-
while (el.firstChild) el.removeChild(el.firstChild);
|
|
5485
|
-
}
|
|
5486
|
-
function stripTaintSources(root) {
|
|
5487
|
-
const pageOrigin = typeof location !== "undefined" ? location.origin : "";
|
|
5488
|
-
for (const el of root.querySelectorAll("img, video, iframe, object, embed, picture")) {
|
|
5489
|
-
el.remove();
|
|
5490
|
-
}
|
|
5491
|
-
for (const link of root.querySelectorAll('link[rel="stylesheet"], link[as="style"]')) {
|
|
5492
|
-
link.remove();
|
|
5493
|
-
}
|
|
5494
|
-
for (const styleEl of root.querySelectorAll("style")) {
|
|
5495
|
-
const cleaned = stripCssUrlRefs(styleEl.textContent ?? "", pageOrigin);
|
|
5496
|
-
if (cleaned !== styleEl.textContent) styleEl.textContent = cleaned;
|
|
5497
|
-
}
|
|
5498
|
-
for (const el of root.querySelectorAll("[style]")) {
|
|
5499
|
-
const s = el.getAttribute("style");
|
|
5500
|
-
if (!s) continue;
|
|
5501
|
-
const cleaned = stripCssUrlRefs(s, pageOrigin);
|
|
5502
|
-
if (cleaned !== s) el.setAttribute("style", cleaned);
|
|
5503
|
-
}
|
|
5504
|
-
for (const script of root.querySelectorAll("script")) {
|
|
5505
|
-
script.remove();
|
|
5506
|
-
}
|
|
5507
|
-
}
|
|
5508
|
-
function stripCssUrlRefs(css, pageOrigin) {
|
|
5509
|
-
return css.replace(/url\(\s*(['"]?)([^)'"]+)\1\s*\)/gi, (_match, _q, href) => {
|
|
5510
|
-
const trimmed = href.trim();
|
|
5511
|
-
if (!trimmed || trimmed.startsWith("data:") || trimmed.startsWith("#")) return _match;
|
|
5512
|
-
if (isCrossOriginUrl(trimmed, pageOrigin)) return "none";
|
|
5513
|
-
return _match;
|
|
5514
|
-
});
|
|
5515
|
-
}
|
|
5516
|
-
function inlineDocumentStyles(clone) {
|
|
5517
|
-
const pageOrigin = typeof location !== "undefined" ? location.origin : "";
|
|
5518
|
-
const chunks = [];
|
|
5519
|
-
const sheets = [
|
|
5520
|
-
...Array.from(document.styleSheets),
|
|
5521
|
-
...document.adoptedStyleSheets ?? []
|
|
5522
|
-
];
|
|
5523
|
-
for (const sheet of sheets) {
|
|
5524
|
-
const owner = sheet.ownerNode;
|
|
5525
|
-
if (owner instanceof Element && owner.tagName === "STYLE") continue;
|
|
5526
|
-
chunks.push(serializeSheet(sheet));
|
|
5527
|
-
}
|
|
5528
|
-
const css = stripCssUrlRefs(chunks.filter(Boolean).join("\n"), pageOrigin);
|
|
5529
|
-
if (!css) return;
|
|
5530
|
-
const styleEl = document.createElement("style");
|
|
5531
|
-
styleEl.textContent = css;
|
|
5532
|
-
(clone.querySelector("head") ?? clone).appendChild(styleEl);
|
|
5533
|
-
}
|
|
5534
|
-
var FREEZE_MOTION_CSS = "*,*::before,*::after{animation:none!important;transition:none!important}";
|
|
5535
|
-
function fillViewport(clone) {
|
|
5536
|
-
const clear = (c) => !c || c === "transparent" || /^rgba\(.*,\s*0\)$/.test(c);
|
|
5537
|
-
let bg = getComputedStyle(document.documentElement).backgroundColor;
|
|
5538
|
-
if (clear(bg) && document.body) bg = getComputedStyle(document.body).backgroundColor;
|
|
5539
|
-
const root = clone;
|
|
5540
|
-
root.style.setProperty("background-color", clear(bg) ? "Canvas" : bg);
|
|
5541
|
-
root.style.setProperty("min-height", `${window.innerHeight}px`);
|
|
5542
|
-
}
|
|
5543
|
-
function freezeMotion(clone) {
|
|
5544
|
-
const styleEl = document.createElement("style");
|
|
5545
|
-
styleEl.textContent = FREEZE_MOTION_CSS;
|
|
5546
|
-
(clone.querySelector("head") ?? clone).appendChild(styleEl);
|
|
5547
|
-
}
|
|
5548
|
-
function serializeSheet(sheet) {
|
|
5549
|
-
let rules;
|
|
5550
|
-
try {
|
|
5551
|
-
rules = sheet.cssRules;
|
|
5552
|
-
} catch {
|
|
5553
|
-
return "";
|
|
5554
|
-
}
|
|
5555
|
-
let text = "";
|
|
5556
|
-
for (const rule of Array.from(rules)) {
|
|
5557
|
-
if (rule instanceof CSSImportRule) {
|
|
5558
|
-
if (rule.styleSheet) text += serializeSheet(rule.styleSheet);
|
|
5559
|
-
continue;
|
|
5560
|
-
}
|
|
5561
|
-
text += `${rule.cssText}
|
|
5562
|
-
`;
|
|
5563
|
-
}
|
|
5564
|
-
return text;
|
|
5565
|
-
}
|
|
5566
|
-
function isCanvasBlank(ctx, width, height) {
|
|
5567
|
-
try {
|
|
5568
|
-
const stepX = Math.max(1, Math.floor(width / 8));
|
|
5569
|
-
const stepY = Math.max(1, Math.floor(height / 8));
|
|
5570
|
-
for (let y = 0; y < height; y += stepY) {
|
|
5571
|
-
for (let x = 0; x < width; x += stepX) {
|
|
5572
|
-
if (ctx.getImageData(x, y, 1, 1).data[3] !== 0) return false;
|
|
5573
|
-
}
|
|
5574
|
-
}
|
|
5575
|
-
return true;
|
|
5576
|
-
} catch {
|
|
5577
|
-
return false;
|
|
5578
|
-
}
|
|
5579
|
-
}
|
|
5580
|
-
function isCrossOriginUrl(raw, pageOrigin) {
|
|
5581
|
-
if (!raw || raw.startsWith("data:") || raw.startsWith("blob:")) return false;
|
|
5582
|
-
try {
|
|
5583
|
-
const resolved = new URL(raw, typeof location !== "undefined" ? location.href : "http://localhost/");
|
|
5584
|
-
return Boolean(pageOrigin) && resolved.origin !== pageOrigin;
|
|
5585
|
-
} catch {
|
|
5586
|
-
return true;
|
|
5587
|
-
}
|
|
5588
|
-
}
|
|
5589
|
-
function maskElement(el) {
|
|
5590
|
-
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
|
|
5591
|
-
el.value = "";
|
|
5592
|
-
el.setAttribute("value", "");
|
|
5593
|
-
el.setAttribute("placeholder", "\u2022\u2022\u2022\u2022");
|
|
5594
|
-
}
|
|
5595
|
-
el.textContent = el.children.length === 0 ? "\u2022\u2022\u2022\u2022" : el.textContent;
|
|
5596
|
-
el.setAttribute(
|
|
5597
|
-
"style",
|
|
5598
|
-
`${el.getAttribute("style") ?? ""};background:#8f8f8f!important;color:transparent!important;text-shadow:none!important;`
|
|
5599
|
-
);
|
|
5600
|
-
el.setAttribute("data-mushi-masked", "true");
|
|
5601
|
-
}
|
|
6065
|
+
|
|
6066
|
+
// src/capture/index.ts
|
|
6067
|
+
init_screenshot();
|
|
5602
6068
|
|
|
5603
6069
|
// src/capture/performance.ts
|
|
5604
6070
|
var INP_DURATION_THRESHOLD_MS = 40;
|
|
@@ -6339,6 +6805,9 @@ async function createReplayCapture(opts) {
|
|
|
6339
6805
|
};
|
|
6340
6806
|
}
|
|
6341
6807
|
|
|
6808
|
+
// src/mushi.ts
|
|
6809
|
+
init_screenshot();
|
|
6810
|
+
|
|
6342
6811
|
// src/sentry.ts
|
|
6343
6812
|
function getSentryGlobal() {
|
|
6344
6813
|
try {
|
|
@@ -6834,7 +7303,7 @@ function createProactiveManager(config = {}) {
|
|
|
6834
7303
|
|
|
6835
7304
|
// src/version.ts
|
|
6836
7305
|
var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
|
|
6837
|
-
var MUSHI_SDK_VERSION = "1.
|
|
7306
|
+
var MUSHI_SDK_VERSION = "1.37.3" ;
|
|
6838
7307
|
function resolveReportAppVersion(config, environment) {
|
|
6839
7308
|
if (config.appVersion) return config.appVersion;
|
|
6840
7309
|
const vercelId = config.integrations?.vercel?.analyticsId;
|
|
@@ -7171,6 +7640,7 @@ function createInstance(config) {
|
|
|
7171
7640
|
let userInfo = null;
|
|
7172
7641
|
let lastIdentifySig = null;
|
|
7173
7642
|
const customMetadata = {};
|
|
7643
|
+
let diagnosticsProvider = null;
|
|
7174
7644
|
const stickyTags = {};
|
|
7175
7645
|
const breadcrumbs = core.createBreadcrumbBuffer({ max: 50 });
|
|
7176
7646
|
breadcrumbs.add({
|
|
@@ -7846,6 +8316,7 @@ function createInstance(config) {
|
|
|
7846
8316
|
log.warn("Screenshot dropped \u2014 could not compress under wire budget");
|
|
7847
8317
|
}
|
|
7848
8318
|
const capturedEnvironment = core.captureEnvironment();
|
|
8319
|
+
const hostDiagnostics = await diagnostics.collectDiagnostics(diagnosticsProvider);
|
|
7849
8320
|
const report = {
|
|
7850
8321
|
id: core.newUuid(),
|
|
7851
8322
|
projectId: config.projectId,
|
|
@@ -7863,6 +8334,7 @@ function createInstance(config) {
|
|
|
7863
8334
|
...replayCap ? { replayEvents: replayCap.flush() } : {},
|
|
7864
8335
|
metadata: {
|
|
7865
8336
|
...customMetadata,
|
|
8337
|
+
...hostDiagnostics ?? {},
|
|
7866
8338
|
...userInfo ? { user: userInfo } : {},
|
|
7867
8339
|
...sentryCtx?.release ? { sentryRelease: sentryCtx.release } : {}
|
|
7868
8340
|
},
|
|
@@ -8047,6 +8519,9 @@ function createInstance(config) {
|
|
|
8047
8519
|
setMetadata(key, value) {
|
|
8048
8520
|
customMetadata[key] = value;
|
|
8049
8521
|
},
|
|
8522
|
+
setDiagnosticsProvider(provider) {
|
|
8523
|
+
diagnosticsProvider = provider;
|
|
8524
|
+
},
|
|
8050
8525
|
setScreen(screen) {
|
|
8051
8526
|
timelineCap.setScreen(screen);
|
|
8052
8527
|
},
|
|
@@ -8657,6 +9132,8 @@ function createNoopInstance() {
|
|
|
8657
9132
|
},
|
|
8658
9133
|
setMetadata: () => {
|
|
8659
9134
|
},
|
|
9135
|
+
setDiagnosticsProvider: () => {
|
|
9136
|
+
},
|
|
8660
9137
|
setScreen: () => {
|
|
8661
9138
|
},
|
|
8662
9139
|
isOpen: () => false,
|