ionblink-js 0.1.2 → 0.1.7

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.
@@ -108,7 +108,7 @@ var init_scrub = __esm({
108
108
  "use strict";
109
109
  EMAIL = /[^\s@<>()[\]"',;:]{1,64}@[^\s@<>()[\]"',;:]{1,253}\.[a-z]{2,}/gi;
110
110
  JWT = /\beyJ[\w-]{6,500}\.[\w-]{6,}\.[\w-]{6,}/g;
111
- KEYS = /\b(?:sk_live_|sk_test_|rk_live_|pk_live_|ib_sk_|ghp_|gho_|ghs_|github_pat_|xox[abpr]-|AKIA|AIza|ya29\.)[\w.-]{8,}/g;
111
+ KEYS = /\b(?:sk_(?:live|test)_|[rp]k_live_|ib_sk_|sk-(?:proj|ant)-|gh[opsu]_|github_pat_|xox[abpr]-|AKIA|AIza|ya29\.)[\w.-]{8,}/g;
112
112
  SSN = /\b\d{3}-\d{2}-\d{4}\b/g;
113
113
  IBAN = /\b[A-Z]{2}\d{2}(?: ?[A-Z0-9]{4}){2,7}(?: ?[A-Z0-9]{1,4})?\b/g;
114
114
  DIGITS = /\+?\(?\d[\d\s().-]{7,}\d/g;
@@ -118,6 +118,35 @@ var init_scrub = __esm({
118
118
  }
119
119
  });
120
120
 
121
+ // src/dom.ts
122
+ function closest(el, sel) {
123
+ if (!el || !el.closest) return null;
124
+ try {
125
+ return el.closest(sel);
126
+ } catch (e) {
127
+ return null;
128
+ }
129
+ }
130
+ function actionable(target) {
131
+ const raw = target;
132
+ if (!raw || raw.nodeType !== 1) return null;
133
+ return closest(raw, INTERACTIVE) || raw;
134
+ }
135
+ function boxOf(el) {
136
+ try {
137
+ return el ? el.getBoundingClientRect() : null;
138
+ } catch (e) {
139
+ return null;
140
+ }
141
+ }
142
+ var INTERACTIVE;
143
+ var init_dom = __esm({
144
+ "src/dom.ts"() {
145
+ "use strict";
146
+ INTERACTIVE = "a,button,input,select,textarea,label,summary,[role=button],[role=link],[role=tab],[role=menuitem],[role=checkbox],[role=option],[role=switch],[onclick],[data-ib-name]";
147
+ }
148
+ });
149
+
121
150
  // src/util.ts
122
151
  function rnd(n) {
123
152
  const a = new Uint8Array(n);
@@ -140,11 +169,11 @@ function uuid4() {
140
169
  b[8] = b[8] & 63 | 128;
141
170
  return fmt(b);
142
171
  }
143
- function uuid7(ms = now()) {
172
+ function uuid7(ms2 = now()) {
144
173
  const b = rnd(16);
145
174
  for (let i = 5; i >= 0; i--) {
146
- b[i] = ms % 256;
147
- ms = Math.floor(ms / 256);
175
+ b[i] = ms2 % 256;
176
+ ms2 = Math.floor(ms2 / 256);
148
177
  }
149
178
  b[6] = b[6] & 15 | 112;
150
179
  b[8] = b[8] & 63 | 128;
@@ -171,11 +200,11 @@ function report(where, err) {
171
200
  reporter = r;
172
201
  }
173
202
  }
174
- function tick(ms) {
175
- perf.total += ms;
176
- if (ms > perf.max) perf.max = ms;
177
- if (ms > 4) perf.over4++;
178
- if (ms > 50) perf.over50++;
203
+ function tick(ms2) {
204
+ perf.total += ms2;
205
+ if (ms2 > perf.max) perf.max = ms2;
206
+ if (ms2 > 4) perf.over4++;
207
+ if (ms2 > 50) perf.over50++;
179
208
  }
180
209
  function guard(where, fn) {
181
210
  return function(...a) {
@@ -195,13 +224,12 @@ function idle(fn, timeout = 3e3) {
195
224
  if (w && w.requestIdleCallback) w.requestIdleCallback(fn, { timeout });
196
225
  else setTimeout(fn, 1);
197
226
  }
198
- var VERSION, now, clamp, perf, reporter, hasReporter, pnow;
227
+ var VERSION, now, perf, reporter, hasReporter, pnow;
199
228
  var init_util = __esm({
200
229
  "src/util.ts"() {
201
230
  "use strict";
202
- VERSION = true ? "0.1.2" : "0.0.0-dev";
231
+ VERSION = true ? "0.1.7" : "0.0.0-dev";
203
232
  now = () => Date.now();
204
- clamp = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
205
233
  perf = { total: 0, max: 0, over4: 0, over50: 0, errors: 0 };
206
234
  reporter = null;
207
235
  hasReporter = () => reporter !== null;
@@ -209,35 +237,6 @@ var init_util = __esm({
209
237
  }
210
238
  });
211
239
 
212
- // src/dom.ts
213
- function closest(el, sel) {
214
- if (!el || !el.closest) return null;
215
- try {
216
- return el.closest(sel);
217
- } catch (e) {
218
- return null;
219
- }
220
- }
221
- function actionable(target) {
222
- const raw = target;
223
- if (!raw || raw.nodeType !== 1) return null;
224
- return closest(raw, INTERACTIVE) || raw;
225
- }
226
- function boxOf(el) {
227
- try {
228
- return el ? el.getBoundingClientRect() : null;
229
- } catch (e) {
230
- return null;
231
- }
232
- }
233
- var INTERACTIVE;
234
- var init_dom = __esm({
235
- "src/dom.ts"() {
236
- "use strict";
237
- INTERACTIVE = "a,button,input,select,textarea,label,summary,[role=button],[role=link],[role=tab],[role=menuitem],[role=checkbox],[role=option],[role=switch],[onclick],[data-ib-name]";
238
- }
239
- });
240
-
241
240
  // src/mask.ts
242
241
  function attr(el, n) {
243
242
  return (el.getAttribute(n) || "").toLowerCase();
@@ -312,14 +311,30 @@ function deep(el, sel) {
312
311
  }
313
312
  function maskTextFn(level, extraMask) {
314
313
  const masked = MASKED + extraMask;
315
- return (text, el) => {
316
- if (!text || !text.trim()) return text;
317
- if (level === "text" || deep(el, masked) || typed(el)) return stars2(text);
318
- if (level === "controls" && !deep(el, CONTROLS)) return stars2(text);
319
- return scrub(text);
314
+ return (text2, el) => {
315
+ if (!text2 || !text2.trim()) return text2;
316
+ if (level === "text" || deep(el, masked) || typed(el)) return stars2(text2);
317
+ if (level === "controls" && !deep(el, CONTROLS)) return stars2(text2);
318
+ return scrub(text2);
320
319
  };
321
320
  }
322
- function scrubUrl(href) {
321
+ function assetSeg(x) {
322
+ const m = HASHED.exec(x);
323
+ return m && /[g-z]/i.test(m[1]) && scrub(m[1]) === m[1] ? x : seg(x);
324
+ }
325
+ function publicSeg(x) {
326
+ return /^[\w-]+$/.test(x) ? /\d{9}/.test(x.replace(/[-_]/g, "")) || new RegExp(KEYS.source.slice(2)).test(x) ? ":redacted" : x : assetSeg(x);
327
+ }
328
+ function publicPaths(list, origin2) {
329
+ if (!Array.isArray(list)) return void 0;
330
+ const res = [];
331
+ for (const g of list.slice(0, 20)) {
332
+ if (typeof g == "string" && g[0] == "/" && g.length <= 200)
333
+ res.push(new RegExp("^" + (origin2 + g).replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*\*?/g, (m) => m[1] ? ".*" : "[^/]*") + "$"));
334
+ }
335
+ return res.length ? (u) => res.some((r) => r.test(u.origin + u.pathname)) : void 0;
336
+ }
337
+ function scrubUrl(href, pub) {
323
338
  if (scrub(href) === href) return href;
324
339
  try {
325
340
  const u = new URL(href, location.href);
@@ -327,20 +342,23 @@ function scrubUrl(href) {
327
342
  u.searchParams.forEach((v, k) => {
328
343
  q += (q ? "&" : "?") + encodeURIComponent(k) + "=" + encodeURIComponent(scrub(v));
329
344
  });
330
- return u.origin + seg(u.pathname) + q;
345
+ return u.origin + u.pathname.split("/").map(pub && pub(u) ? publicSeg : assetSeg).join("/") + q;
331
346
  } catch (e) {
332
347
  return scrub(href);
333
348
  }
334
349
  }
335
- function maskAttrsFn(level, extraMask) {
336
- const text = maskTextFn(level, extraMask);
350
+ function maskAttrsFn(level, extraMask, pub) {
351
+ const text2 = maskTextFn(level, extraMask);
337
352
  const masked = MASKED + extraMask;
353
+ const pubOf = (el, n) => pub && level !== "text" && el && (n === "srcset" || n === "src" && el.tagName === "IMG") && !deep(el, masked) ? pub : void 0;
338
354
  return (a, el, mut) => {
339
355
  for (const k in a) {
340
356
  const v = a[k];
341
357
  if (typeof v !== "string" || !v) continue;
342
358
  const n = k.toLowerCase();
343
- if (DROP_ATTR.test(n)) {
359
+ if (n === "_csstext") {
360
+ if (v.length > 1e6) a[k] = v.replace(BIG_DATA, "data:,");
361
+ } else if (DROP_ATTR.test(n)) {
344
362
  if (mut) a[k] = null;
345
363
  else delete a[k];
346
364
  } else if (n === "value" && field(el)) a[k] = maskInputFn(v, el);
@@ -349,15 +367,17 @@ function maskAttrsFn(level, extraMask) {
349
367
  const scheme = /^\s*([a-z][\w+.-]*):/i.exec(v);
350
368
  const sc = scheme ? scheme[1].toLowerCase() : "";
351
369
  a[k] = sc === "javascript" ? "#" : sc && sc !== "http" && sc !== "https" ? sc + ":*" : maskUrl(v).url || "#";
352
- } else if (SRC_ATTR.test(n)) a[k] = /^\s*(blob|data):/i.test(v) ? "" : n === "srcset" ? v.replace(/[^\s,]+/g, scrubUrl) : scrubUrl(v);
353
- else if (n.indexOf("data-") === 0) a[k] = level === "text" || deep(el, masked) ? stars2(v) : UI_WORD.test(v) ? v : text(v, el);
354
- else if (TEXT_ATTR.test(n)) a[k] = text(v, el);
370
+ } else if (SRC_ATTR.test(n)) {
371
+ const p = pubOf(el, n);
372
+ a[k] = /^\s*(blob|data):/i.test(v) ? "" : n === "srcset" ? v.replace(/[^\s,]+/g, (u) => scrubUrl(u, p)) : scrubUrl(v, p);
373
+ } else if (n.indexOf("data-") === 0) a[k] = level === "text" || deep(el, masked) ? stars2(v) : UI_WORD.test(v) ? v : text2(v, el);
374
+ else if (TEXT_ATTR.test(n)) a[k] = text2(v, el);
355
375
  }
356
376
  };
357
377
  }
358
- function maskInputFn(text, el) {
378
+ function maskInputFn(text2, el) {
359
379
  if (isSensitive(el)) return "********";
360
- return text ? "*".repeat(text.length) : text;
380
+ return text2 ? "*".repeat(text2.length) : text2;
361
381
  }
362
382
  function validSelectors(list, doc) {
363
383
  if (!Array.isArray(list)) return "";
@@ -416,7 +436,7 @@ function selector(el) {
416
436
  }
417
437
  return parts.join(">");
418
438
  }
419
- var NAME_TOKENS, SENSITIVE, SENSITIVE_RE, CONTROLS, MASKED, NO_CAPTURE, BLOCKED, BLOCKED_TEXT, iFlag, stars2, typed, LINK_ATTR, SRC_ATTR, TEXT_ATTR, DROP_ATTR, UI_WORD, field;
439
+ var NAME_TOKENS, SENSITIVE, SENSITIVE_RE, CONTROLS, MASKED, NO_CAPTURE, BLOCKED, BLOCKED_TEXT, iFlag, stars2, typed, HASHED, LINK_ATTR, SRC_ATTR, TEXT_ATTR, DROP_ATTR, BIG_DATA, UI_WORD, field;
420
440
  var init_mask = __esm({
421
441
  "src/mask.ts"() {
422
442
  "use strict";
@@ -426,16 +446,18 @@ var init_mask = __esm({
426
446
  SENSITIVE = "input[type=password],input[type=email],input[type=tel],input[type=hidden],[autocomplete^=cc-],[autocomplete=one-time-code],[autocomplete=current-password],[autocomplete=new-password],[autocomplete=email],[autocomplete=tel],input[name=pin i],input[id=pin i],textarea[name=pin i]," + NAME_TOKENS.map((t) => `input[name*=${t} i],input[id*=${t} i],textarea[name*=${t} i]`).join(",");
427
447
  SENSITIVE_RE = /pass|pwd|card|cc-?num|cvc|cvv|iban|ssn|otp|secret|token|email|phone|^pin$/i;
428
448
  CONTROLS = "button,a,label,nav,th,summary,option,select,legend,[role=button],[role=link],[role=tab],[role=menuitem],[role=option],[role=checkbox],[role=radio],[role=switch],input[type=submit],input[type=button],input[type=reset],[data-ib-unmask]";
429
- MASKED = "[data-ib-mask],.ib-mask";
430
- NO_CAPTURE = "[data-ib-no-capture],.ib-no-capture,[data-ib-block],.ib-block";
431
- BLOCKED = '[data-ib-block],.ib-block,input[type=file],img[src^="blob:"],img[src^="data:"],img[srcset*="blob:"],img[srcset*="data:"],source[srcset*="blob:"],source[srcset*="data:"],video[src^="blob:"],image[href^="data:"],image[href^="blob:"]';
449
+ MASKED = "[data-ib-mask],.ib-mask,[data-ph-mask],.ph-mask,.ph-sensitive";
450
+ NO_CAPTURE = "[data-ib-no-capture],.ib-no-capture,[data-ib-block],.ib-block,.ph-no-capture";
451
+ BLOCKED = '[data-ib-block],.ib-block,.ph-no-capture,[data-testid=ph-no-capture],input[type=file],img[src^="blob:"],img[src^="data:"],img[srcset*="blob:"],img[srcset*="data:"],source[srcset*="blob:"],source[srcset*="data:"],video[src^="blob:"],image[href^="data:"],image[href^="blob:"]';
432
452
  BLOCKED_TEXT = ",img,picture,video,image";
433
453
  stars2 = (t) => t.replace(/\S/g, "*");
434
454
  typed = (el) => !!el && (!!deep(el, "[contenteditable]:not([contenteditable=false])") || el.ownerDocument.designMode === "on");
455
+ HASHED = /^((?:[a-z\d]{1,23}[-_.])+)[\da-f]{8,64}\.[a-z\d]{2,5}$/i;
435
456
  LINK_ATTR = /^(href|action|formaction|cite|ping|xlink:href|rr_src)$/;
436
457
  SRC_ATTR = /^(src|srcset|poster|background|data)$/;
437
458
  TEXT_ATTR = /^(title|alt|placeholder|label|value|summary|abbr|aria-label|aria-description|aria-valuetext|aria-placeholder|aria-roledescription|aria-braillelabel|aria-brailleroledescription)$/;
438
459
  DROP_ATTR = /^(on|nonce$|srcdoc$)/;
460
+ BIG_DATA = /data:[\w/+.-]+;base64,[\w+/=]{32768,}/g;
439
461
  UI_WORD = /^[a-z][a-z-]{0,15}$/;
440
462
  field = (el) => !el || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName) && !/^(submit|button|reset|image|checkbox|radio)$/i.test(el.getAttribute("type") || "");
441
463
  }
@@ -444,11 +466,11 @@ var init_mask = __esm({
444
466
  // src/rage.ts
445
467
  function createRage(o = {}) {
446
468
  const n = o.n || 3;
447
- const ms = o.ms || 1e3;
469
+ const ms2 = o.ms || 1e3;
448
470
  const px = o.px || 30;
449
471
  let lt = -1e12, lx = 0, ly = 0, count = 0;
450
472
  return (t, x, y) => {
451
- if (t - lt <= ms && Math.abs(x - lx) + Math.abs(y - ly) <= px) count++;
473
+ if (t - lt <= ms2 && Math.abs(x - lx) + Math.abs(y - ly) <= px) count++;
452
474
  else count = 1;
453
475
  lt = t;
454
476
  lx = x;
@@ -478,11 +500,11 @@ function errInfo(e) {
478
500
  }
479
501
  function targetOf(el, level, rect) {
480
502
  const t = { tag: el.tagName.toLowerCase(), sel: selector(el) };
481
- const text = textFor(el, level);
503
+ const text2 = textFor(el, level);
482
504
  const label = labelFor(el, level);
483
505
  const role = el.getAttribute("role");
484
506
  const name = el.getAttribute("data-ib-name");
485
- if (text) t.text = text;
507
+ if (text2) t.text = text2;
486
508
  if (label) t.label = label;
487
509
  if (role) t.role = role.slice(0, 20);
488
510
  if (name) t.name = name.slice(0, 64);
@@ -539,17 +561,17 @@ function createAuto(ctx) {
539
561
  });
540
562
  mo.observe(document.documentElement, { childList: true, subtree: true, attributes: true, characterData: true });
541
563
  }
542
- function err(kind, type, message, source, stack) {
564
+ function err(kind2, type, message, source, stack) {
543
565
  if (!ctx.on("errors") || errors >= 20) return;
544
566
  if (message === "Script error." || message === "Script error") {
545
567
  if (scriptErrors++ > 0) return;
546
568
  }
547
- const k = kind + type + message + (source || "");
569
+ const k = kind2 + type + message + (source || "");
548
570
  seen[k] = (seen[k] || 0) + 1;
549
571
  if (seen[k] > 5) return;
550
572
  errors++;
551
573
  const p = {
552
- kind,
574
+ kind: kind2,
553
575
  type: type.slice(0, 64),
554
576
  message: scrub(message).slice(0, 500)
555
577
  };
@@ -558,6 +580,19 @@ function createAuto(ctx) {
558
580
  if (seen[k] > 1) p.n = seen[k];
559
581
  ctx.capture("$error", p, now());
560
582
  }
583
+ function field2(target, action, t) {
584
+ const el = target;
585
+ if (!ctx.on("forms") || !el || !/^(INPUT|SELECT|TEXTAREA)$/.test(el.tagName) || closest(el, NO_CAPTURE)) return;
586
+ const type = el.tagName === "INPUT" ? (el.getAttribute("type") || "text").toLowerCase() : el.tagName.toLowerCase();
587
+ if (type === "hidden" || type === "submit" || type === "button") return;
588
+ const fd = { type };
589
+ const label = fieldLabel(el, ctx.level());
590
+ const name = el.getAttribute("name");
591
+ if (label) fd.label = label;
592
+ if (name) fd.name = scrub(name.slice(0, 40));
593
+ if (isSensitive(el)) fd.sensitive = true;
594
+ ctx.capture("$field", { action, field: fd }, t);
595
+ }
561
596
  return {
562
597
  click(e, t, box, late) {
563
598
  const el = actionable(e.target);
@@ -592,21 +627,10 @@ function createAuto(ctx) {
592
627
  selection(t) {
593
628
  lastSel = t;
594
629
  },
595
- field(e, focus, t) {
596
- const el = e.target;
597
- if (!ctx.on("forms") || !el || !/^(INPUT|SELECT|TEXTAREA)$/.test(el.tagName) || closest(el, NO_CAPTURE)) return;
598
- const type = el.tagName === "INPUT" ? (el.getAttribute("type") || "text").toLowerCase() : el.tagName.toLowerCase();
599
- if (type === "hidden" || type === "submit" || type === "button") return;
600
- const field2 = { type };
601
- const label = fieldLabel(el, ctx.level());
602
- const name = el.getAttribute("name");
603
- if (label) field2.label = label;
604
- if (name) field2.name = scrub(name.slice(0, 40));
605
- if (isSensitive(el)) field2.sensitive = true;
606
- ctx.capture("$field", { action: focus ? "focus" : "blur", field: field2 }, t);
607
- },
630
+ field: field2,
608
631
  input(e, t) {
609
632
  const el = e.target;
633
+ if (el && /^(select|checkbox|radio)/.test(el.type)) field2(el, "change", t);
610
634
  const f = el && el.form;
611
635
  if (!ctx.on("forms") || !f || started.has(f) || closest(f, NO_CAPTURE)) return;
612
636
  started.add(f);
@@ -648,12 +672,18 @@ var init_auto = __esm({
648
672
  function createReplay(api) {
649
673
  let loading = false;
650
674
  let budget = false;
675
+ const waits = () => {
676
+ const s = api.rs();
677
+ return !!s.cfg && s.mode !== "replay";
678
+ };
679
+ let waited = waits();
651
680
  const blocked = (path) => {
652
681
  const g = api.rs().opts.blockPaths;
653
682
  return !!g && g.some((x) => typeof x === "string" && glob(x).test(path));
654
683
  };
655
684
  function gate() {
656
685
  const s = api.rs();
686
+ if (waits()) waited = true;
657
687
  if (s.mode !== "replay" || !s.sid) return "mode";
658
688
  if (s.killed === "replay" || s.killed === "all") return "killed";
659
689
  if (!s.cfg) return s.failed ? "no_config" : "wait";
@@ -674,7 +704,7 @@ function createReplay(api) {
674
704
  afterLoad(() => idle(
675
705
  guard("replay.idle", () => {
676
706
  Promise.resolve().then(() => api.loadReplay()).then(
677
- guard("replay.start", (start3) => {
707
+ guard("replay.start", (start5) => {
678
708
  loading = false;
679
709
  const g2 = gate();
680
710
  if (g2) {
@@ -686,7 +716,7 @@ function createReplay(api) {
686
716
  api.rset({ on: true });
687
717
  let handle;
688
718
  try {
689
- handle = start3({
719
+ handle = start5({
690
720
  level: api.level(),
691
721
  mask: arr(s.opts.maskSelectors).concat(arr(rc && rc.mask_selectors)),
692
722
  block: arr(s.opts.blockSelectors).concat(arr(rc && rc.block_selectors)),
@@ -696,7 +726,13 @@ function createReplay(api) {
696
726
  if (r === "budget") budget = true;
697
727
  stop(r);
698
728
  },
699
- report
729
+ report,
730
+ cfg: () => {
731
+ const c = api.rs().cfg;
732
+ return c ? c.replay : void 0;
733
+ },
734
+ opts: s.opts,
735
+ fresh: !waited
700
736
  });
701
737
  } catch (e) {
702
738
  off("unsupported");
@@ -721,16 +757,16 @@ function createReplay(api) {
721
757
  ));
722
758
  }
723
759
  function stop(reason) {
724
- const cur = api.rget();
760
+ const cur2 = api.rget();
725
761
  api.rset(reason ? { on: false, off: reason } : { on: false });
726
- if (cur.handle) {
762
+ if (cur2.handle) {
727
763
  try {
728
- cur.handle.stop();
764
+ cur2.handle.stop();
729
765
  } catch (e) {
730
766
  report("replay.stop", e);
731
767
  }
732
768
  }
733
- if (cur.on) api.capture("$replay", { state: "stopped", reason: reason || "paused" }, now(), false);
769
+ if (cur2.on) api.capture("$replay", { state: "stopped", reason: reason || "paused" }, now(), false);
734
770
  }
735
771
  return {
736
772
  maybe,
@@ -741,9 +777,9 @@ function createReplay(api) {
741
777
  maybe();
742
778
  },
743
779
  nav(path) {
744
- const cur = api.rget();
745
- if (cur.on && blocked(path)) stop("blocked_path");
746
- else if (!cur.on && cur.off === "blocked_path") maybe();
780
+ const cur2 = api.rget();
781
+ if (cur2.on && blocked(path)) stop("blocked_path");
782
+ else if (!cur2.on && cur2.off === "blocked_path") maybe();
747
783
  }
748
784
  };
749
785
  }
@@ -926,8 +962,8 @@ function cv(a) {
926
962
  function push(a, v, cap = 200) {
927
963
  if (a.length < cap) a.push(v);
928
964
  }
929
- function createSignals(start3) {
930
- let s0 = start3;
965
+ function createSignals(start5) {
966
+ let s0 = start5;
931
967
  let ttfi;
932
968
  let ptype = "none";
933
969
  let moves = 0, steps = 0, flicks = 0, clicks = 0, noApproach = 0, offLt3 = 0, pressLt25 = 0;
@@ -1156,6 +1192,7 @@ var init_signals = __esm({
1156
1192
  // src/vitals.ts
1157
1193
  function watchVitals() {
1158
1194
  let lcp;
1195
+ let lcpEl;
1159
1196
  let cls = 0;
1160
1197
  let win = 0;
1161
1198
  let winStart = 0;
@@ -1178,6 +1215,7 @@ function watchVitals() {
1178
1215
  }
1179
1216
  observe("largest-contentful-paint", (e) => {
1180
1217
  lcp = e.startTime;
1218
+ lcpEl = e.element;
1181
1219
  });
1182
1220
  observe("layout-shift", (e) => {
1183
1221
  const s = e;
@@ -1201,6 +1239,7 @@ function watchVitals() {
1201
1239
  read() {
1202
1240
  const out = {};
1203
1241
  if (lcp !== void 0) out.lcp = Math.round(lcp);
1242
+ if (lcpEl) out.lcp_el = selector(lcpEl);
1204
1243
  if (types.indexOf("layout-shift") >= 0) out.cls = Math.round(cls * 1e3) / 1e3;
1205
1244
  const d = Object.keys(inter).map((k) => inter[+k]).sort((a, b) => b - a);
1206
1245
  if (d.length) out.inp = Math.round(d[Math.min(d.length - 1, Math.floor(d.length / 50))]);
@@ -1220,6 +1259,7 @@ function watchVitals() {
1220
1259
  var init_vitals = __esm({
1221
1260
  "src/vitals.ts"() {
1222
1261
  "use strict";
1262
+ init_mask();
1223
1263
  init_util();
1224
1264
  }
1225
1265
  });
@@ -1254,6 +1294,10 @@ function start(api, navStart) {
1254
1294
  if (lastA) eng += Math.min(Math.max(0, t - lastA), 5e3);
1255
1295
  lastA = t;
1256
1296
  };
1297
+ const page = () => ({
1298
+ engaged_ms: Math.round(eng),
1299
+ scroll_pct: Math.min(100, Math.round((maxY + window.innerHeight) / (document.documentElement.scrollHeight || 1) * 100))
1300
+ });
1257
1301
  const h = {
1258
1302
  pointermove: (e, t) => {
1259
1303
  act(t);
@@ -1298,13 +1342,14 @@ function start(api, navStart) {
1298
1342
  },
1299
1343
  copy: () => c() && sig.copy(),
1300
1344
  paste: () => c() && sig.paste(),
1301
- focusin: (e, t) => auto.field(e, true, t),
1302
- focusout: (e, t) => auto.field(e, false, t),
1345
+ focusin: (e, t) => auto.field(e.target, "focus", t),
1346
+ focusout: (e, t) => auto.field(e.target, "blur", t),
1303
1347
  submit: (e, t) => auto.submit(e, t),
1304
1348
  selectionchange: (_e, t) => auto.selection(t),
1305
1349
  error: (e) => e instanceof ErrorEvent && auto.error(e),
1306
1350
  unhandledrejection: (e) => auto.rejection(e),
1307
1351
  securitypolicyviolation: (e) => {
1352
+ if (e.disposition === "report") return;
1308
1353
  auto.csp(e);
1309
1354
  cspHint(e);
1310
1355
  },
@@ -1326,11 +1371,10 @@ function start(api, navStart) {
1326
1371
  if (f) f(e, t, extra, late);
1327
1372
  },
1328
1373
  dirty: sig.dirty,
1329
- summary: sig.summary,
1330
- page: () => ({
1331
- engaged_ms: Math.round(eng),
1332
- scroll_pct: Math.min(100, Math.round((maxY + window.innerHeight) / (document.documentElement.scrollHeight || 1) * 100))
1333
- }),
1374
+ // a page hidden for good without a pagehide (in-app browsers, a killed tab) sends no $page_leave: its last
1375
+ // $signals carries the depth and engaged time instead
1376
+ summary: (t) => ({ ...sig.summary(t), ...page() }),
1377
+ page,
1334
1378
  vitals: () => vit ? vit.read() : {},
1335
1379
  automation: readAutomation,
1336
1380
  queue: (name) => openQueue(name),
@@ -1354,15 +1398,11 @@ var init_x = __esm({
1354
1398
  });
1355
1399
 
1356
1400
  // src/replay.ts
1357
- var replay_exports = {};
1358
- __export(replay_exports, {
1359
- start: () => start2
1360
- });
1361
- function start2(api) {
1401
+ function start2(api, loadInspect) {
1362
1402
  if (CRAWLER.test(navigator.userAgent)) return "crawler";
1363
1403
  if (document.getElementsByTagName("*").length > MAX_ELEMENTS) return "dom_too_large";
1364
1404
  const extraMask = validSelectors(api.mask);
1365
- const fix = maskAttrsFn(api.level, extraMask);
1405
+ const fix = maskAttrsFn(api.level, extraMask, publicPaths(api.opts && api.opts.publicImages, location.origin));
1366
1406
  const el = (id) => {
1367
1407
  const n = import_record.record.mirror.getNode(id);
1368
1408
  return n && n.nodeType === 1 ? n : null;
@@ -1410,7 +1450,7 @@ function start2(api) {
1410
1450
  maskEvent(ev);
1411
1451
  buf.push(ev);
1412
1452
  const d = ev.data;
1413
- const est = ev.type === 2 ? CHUNK : 120 + (d && d.adds ? d.adds.length * 400 : 0) + (d && d.texts ? d.texts.length * 60 : 0) + (d && d.attributes ? d.attributes.length * 80 : 0);
1453
+ const est = ev.type === 2 ? CHUNK : ev.type === 6 ? 60 + JSON.stringify(d).length : 120 + (d && d.adds ? d.adds.length * 400 : 0) + (d && d.texts ? d.texts.length * 60 : 0) + (d && d.attributes ? d.attributes.length * 80 : 0);
1414
1454
  bytes += est;
1415
1455
  total += est;
1416
1456
  if (bytes >= CHUNK) flush();
@@ -1437,9 +1477,51 @@ function start2(api) {
1437
1477
  return true;
1438
1478
  }
1439
1479
  });
1480
+ let ins = null;
1481
+ const o = api.opts;
1482
+ const net2 = o.network;
1483
+ const allow = (k) => {
1484
+ const c = api.cfg();
1485
+ return !!c && c[k] === true && o[k] !== false;
1486
+ };
1487
+ if (loadInspect && (allow("console") || allow("network")))
1488
+ loadInspect().then(
1489
+ (start5) => {
1490
+ if (!live) return;
1491
+ try {
1492
+ ins = start5({
1493
+ get console() {
1494
+ return allow("console");
1495
+ },
1496
+ get network() {
1497
+ return allow("network");
1498
+ },
1499
+ star: api.level === "text",
1500
+ fresh: api.fresh,
1501
+ keep: net2 && typeof net2 === "object" && Array.isArray(net2.keepParams) ? net2.keepParams.filter((k) => typeof k === "string").slice(0, 20) : [],
1502
+ push: (e) => {
1503
+ try {
1504
+ emit(e);
1505
+ } catch (x) {
1506
+ api.report("inspect.emit", x);
1507
+ }
1508
+ },
1509
+ report: api.report,
1510
+ scrub,
1511
+ seg
1512
+ });
1513
+ } catch (e) {
1514
+ api.report("inspect.start", e);
1515
+ }
1516
+ },
1517
+ (e) => api.report("inspect.load", e)
1518
+ // blocked or offline: the recording goes on without them
1519
+ );
1440
1520
  return {
1441
1521
  flush,
1442
1522
  stop() {
1523
+ if (ins) ins.stop();
1524
+ ins = null;
1443
1525
  live = false;
1444
1526
  if (stop) stop();
1445
1527
  flush();
@@ -1461,6 +1543,459 @@ var init_replay = __esm({
1461
1543
  }
1462
1544
  });
1463
1545
 
1546
+ // src/inspect.ts
1547
+ var inspect_exports = {};
1548
+ __export(inspect_exports, {
1549
+ BURST: () => BURST,
1550
+ LINE: () => LINE,
1551
+ MAX_CHARS: () => MAX_CHARS,
1552
+ MAX_LINES: () => MAX_LINES,
1553
+ MAX_REQS: () => MAX_REQS,
1554
+ RATE: () => RATE,
1555
+ cleanUrl: () => cleanUrl,
1556
+ frames: () => frames,
1557
+ line: () => line,
1558
+ resetForTests: () => resetForTests,
1559
+ start: () => start3,
1560
+ str: () => str,
1561
+ text: () => text
1562
+ });
1563
+ function note(text2) {
1564
+ if (cur) cur.push(plugin(CONSOLE_PLUGIN, { level: "warn", trace: [], payload: [JSON.stringify("[ionblink] " + text2)] }));
1565
+ }
1566
+ function take(b, max, what) {
1567
+ if (b.done) return false;
1568
+ if (b.used >= max || b.chars > MAX_CHARS) {
1569
+ b.done = true;
1570
+ note(what + " capture stopped for this page after " + b.used);
1571
+ return false;
1572
+ }
1573
+ const t = Date.now();
1574
+ b.n = Math.min(BURST, b.n + (t - b.at) * RATE / 1e3);
1575
+ b.at = t;
1576
+ if (b.n < 1) {
1577
+ if (!b.skipped++)
1578
+ setTimeout(() => {
1579
+ if (b.skipped && !b.done) note(b.skipped + " " + what + " skipped: more than " + RATE + " a second");
1580
+ b.skipped = 0;
1581
+ }, 1e3);
1582
+ return false;
1583
+ }
1584
+ b.n--;
1585
+ b.used++;
1586
+ return true;
1587
+ }
1588
+ function str(s, max) {
1589
+ let t = s.slice(0, max + 320);
1590
+ t = cur && cur.star ? stars3(t) : scrub2(t.replace(AUTHZ, stars3).replace(URLS, (u) => cleanUrl(u, []) || u.split(/[?#]/)[0]));
1591
+ return t.length > max ? t.slice(0, max - 1) + "\u2026" : t;
1592
+ }
1593
+ function text(v, room) {
1594
+ if (typeof v === "string") return JSON.stringify(str(v, room));
1595
+ let n = 0;
1596
+ const seen = [];
1597
+ const walk = (x, d) => {
1598
+ if (++n > 100) return "\u2026";
1599
+ if (x === null || typeof x === "boolean") return x;
1600
+ switch (typeof x) {
1601
+ case "string":
1602
+ return str(x, 300);
1603
+ case "number":
1604
+ return isFinite(x) ? x : String(x);
1605
+ case "undefined":
1606
+ return "undefined";
1607
+ case "bigint":
1608
+ return x + "n";
1609
+ case "symbol":
1610
+ return String(x);
1611
+ case "function":
1612
+ return "\u0192 " + (x.name ? str(x.name, 60) : "anonymous");
1613
+ }
1614
+ const o = x;
1615
+ if (o instanceof Error) return str(o.name + ": " + o.message, 300);
1616
+ if (o instanceof Date) return isNaN(o.getTime()) ? "Invalid Date" : o.toISOString();
1617
+ if (o instanceof RegExp) return String(o);
1618
+ if (typeof Node !== "undefined" && o instanceof Node) return "<" + o.nodeName.toLowerCase() + ">";
1619
+ if (o === window) return "[Window]";
1620
+ if (seen.indexOf(o) >= 0) return "[Circular]";
1621
+ if (o instanceof Map || o instanceof Set) return (o instanceof Map ? "Map(" : "Set(") + o.size + ")";
1622
+ if (ArrayBuffer.isView(o)) return kind(o) + "(" + (o.length ?? o.byteLength) + ")";
1623
+ if (!Array.isArray(o) && !plain(o)) return "[" + kind(o) + "]";
1624
+ if (d > 2) return Array.isArray(o) ? "[Array(" + o.length + ")]" : "[Object]";
1625
+ seen.push(o);
1626
+ let r;
1627
+ if (Array.isArray(o)) {
1628
+ const a = o.slice(0, 20).map((y) => walk(y, d + 1));
1629
+ if (o.length > 20) a.push("\u2026 " + (o.length - 20) + " more");
1630
+ r = a;
1631
+ } else {
1632
+ const out = {};
1633
+ const ks = Object.keys(o);
1634
+ for (const k of ks.slice(0, 20)) {
1635
+ if (k === "__proto__") continue;
1636
+ let y;
1637
+ try {
1638
+ y = o[k];
1639
+ } catch (e) {
1640
+ y = "[unreadable]";
1641
+ }
1642
+ out[str(k, 100)] = SECRET.test(k) && y !== null && y !== void 0 && y !== "" ? "********" : walk(y, d + 1);
1643
+ }
1644
+ if (ks.length > 20) out["\u2026"] = ks.length - 20 + " more keys";
1645
+ r = out;
1646
+ }
1647
+ seen.pop();
1648
+ return r;
1649
+ };
1650
+ try {
1651
+ const j = JSON.stringify(walk(v, 0));
1652
+ return j === void 0 ? String(v) : j;
1653
+ } catch (e) {
1654
+ return '"[unreadable]"';
1655
+ }
1656
+ }
1657
+ function frames(stack) {
1658
+ const out = [];
1659
+ if (typeof stack !== "string") return out;
1660
+ for (const l of stack.slice(0, 8e3).split("\n")) {
1661
+ const f = l.trim();
1662
+ if (f.indexOf("at ") !== 0 && !/@[^@]*:\d+(?::\d+)?$/.test(f)) continue;
1663
+ const s = scrub2(f.slice(0, 620).replace(/[?#][^\s:)]*/g, "").replace(URLS, (u) => cleanUrl(u, []) || u));
1664
+ out.push(s.length > 300 ? s.slice(0, 299) + "\u2026" : s);
1665
+ if (out.length >= 10) break;
1666
+ }
1667
+ return out;
1668
+ }
1669
+ function line(level, args, trace, lead) {
1670
+ const a = cur;
1671
+ if (!a || !a.console || busy) return;
1672
+ const first = args[0];
1673
+ if (typeof first === "string" && first.indexOf("[ionblink]") === 0) return;
1674
+ busy = true;
1675
+ try {
1676
+ if (!take(con, MAX_LINES, "console lines")) return;
1677
+ const out = lead ? [JSON.stringify(lead)] : [];
1678
+ let room = LINE - (lead ? lead.length + 2 : 0);
1679
+ let tr = trace ? trace() : [];
1680
+ for (let i = 0; i < args.length && room > 0; i++) {
1681
+ const v = args[i];
1682
+ if (v instanceof Error && !tr.length) tr = frames(v.stack);
1683
+ let s = text(v, room);
1684
+ if (s.length > room) s = s.slice(0, Math.max(0, room - 1)) + "\u2026";
1685
+ room -= s.length;
1686
+ out.push(s);
1687
+ }
1688
+ con.chars += LINE - room;
1689
+ a.push(plugin(CONSOLE_PLUGIN, { level, trace: tr, payload: out }));
1690
+ } catch (e) {
1691
+ a.report("inspect.console", e);
1692
+ } finally {
1693
+ busy = false;
1694
+ }
1695
+ }
1696
+ function wrapConsole() {
1697
+ const c = console;
1698
+ for (const l of LEVELS) {
1699
+ const orig = c[l];
1700
+ if (typeof orig !== "function") continue;
1701
+ c[l] = function(...a) {
1702
+ line(l, a);
1703
+ return orig.apply(this, a);
1704
+ };
1705
+ }
1706
+ addEventListener("error", (e) => {
1707
+ const err = e.error;
1708
+ if (err instanceof Error) line("error", [err.name + ": " + err.message], () => frames(err.stack), "Uncaught");
1709
+ else line("error", [e.message || "Script error"], () => e.filename ? frames("at " + e.filename + ":" + e.lineno + ":" + e.colno) : [], "Uncaught");
1710
+ });
1711
+ addEventListener("unhandledrejection", (e) => {
1712
+ const r = e.reason;
1713
+ if (r instanceof Error) line("error", [r.name + ": " + r.message], () => frames(r.stack), "Uncaught (in promise)");
1714
+ else line("error", [r], void 0, "Uncaught (in promise)");
1715
+ });
1716
+ }
1717
+ function cleanUrl(href, keep) {
1718
+ let u;
1719
+ try {
1720
+ u = new URL(href);
1721
+ } catch (e) {
1722
+ return "";
1723
+ }
1724
+ if (u.protocol !== "http:" && u.protocol !== "https:") return u.protocol;
1725
+ let q = "";
1726
+ if (keep.length)
1727
+ u.searchParams.forEach((v, k) => {
1728
+ if (keep.indexOf(k) >= 0) q += (q ? "&" : "?") + encodeURIComponent(k) + "=" + encodeURIComponent(scrub2(v.slice(0, 520)).slice(0, 200));
1729
+ });
1730
+ return (u.origin + seg2(u.pathname)).slice(0, 1e3) + q;
1731
+ }
1732
+ function fill(q, pe) {
1733
+ if (typeof pe.transferSize === "number") q.transferSize = pe.transferSize;
1734
+ if (typeof pe.encodedBodySize === "number") q.encodedBodySize = pe.encodedBodySize;
1735
+ if (!(pe.responseStart > 0)) return;
1736
+ const t = {};
1737
+ let any = false;
1738
+ const put = (k, v) => {
1739
+ if (ms(v) > 0) any = !!(t[k] = ms(v));
1740
+ };
1741
+ put("dns", pe.domainLookupEnd - pe.domainLookupStart);
1742
+ put("connect", pe.connectEnd - pe.connectStart);
1743
+ if (pe.secureConnectionStart > 0) put("tls", pe.connectEnd - pe.secureConnectionStart);
1744
+ put("wait", pe.responseStart - (pe.requestStart || pe.startTime));
1745
+ put("download", pe.responseEnd - pe.responseStart);
1746
+ if (any) q.timing = t;
1747
+ }
1748
+ function begin(u, m, type) {
1749
+ if (!cur || !cur.network) return null;
1750
+ const p = abs(u);
1751
+ if (!p || own(p)) return null;
1752
+ const r = { url: p.href, method: (typeof m === "string" && m ? m : "GET").toUpperCase().slice(0, 12), type, t0: performance.now() };
1753
+ open.push(r);
1754
+ if (open.length > 200) open.shift();
1755
+ return r;
1756
+ }
1757
+ function end(r, status, error) {
1758
+ r.t1 = performance.now();
1759
+ r.status = status;
1760
+ if (error) r.error = error;
1761
+ if (r.pe) send(r);
1762
+ else r.timer = setTimeout(() => send(r), WAIT_MS);
1763
+ }
1764
+ function entry(pe) {
1765
+ if (pe.initiatorType !== "fetch" && pe.initiatorType !== "xmlhttprequest") return;
1766
+ for (const r of open)
1767
+ if (!r.pe && r.url === pe.name && r.t0 <= pe.startTime + 20) {
1768
+ r.pe = pe;
1769
+ if (r.t1 !== void 0) {
1770
+ clearTimeout(r.timer);
1771
+ send(r);
1772
+ }
1773
+ return;
1774
+ }
1775
+ }
1776
+ function send(r) {
1777
+ const i = open.indexOf(r);
1778
+ if (i < 0) return;
1779
+ open.splice(i, 1);
1780
+ const a = cur;
1781
+ if (!a || !take(net, MAX_REQS, "requests")) return;
1782
+ const pe = r.pe;
1783
+ const o = origin();
1784
+ const q = {
1785
+ url: cleanUrl(r.url, a.keep),
1786
+ method: r.method,
1787
+ initiatorType: r.type,
1788
+ status: r.status,
1789
+ startTime: ms(o + (pe ? pe.startTime : r.t0)),
1790
+ endTime: ms(o + (pe && pe.responseEnd > 0 ? pe.responseEnd : r.t1))
1791
+ };
1792
+ if (r.error) q.error = r.error;
1793
+ if (pe) fill(q, pe);
1794
+ a.push(plugin(NETWORK_PLUGIN, { requests: [q] }));
1795
+ }
1796
+ function wrapNetwork() {
1797
+ const w = window;
1798
+ const F = w.fetch;
1799
+ if (typeof F === "function")
1800
+ w.fetch = function(input, init) {
1801
+ let r = null;
1802
+ safe("inspect.fetch", () => {
1803
+ const req = typeof Request !== "undefined" && input instanceof Request ? input : null;
1804
+ r = begin(req ? req.url : input, init && init.method || req && req.method, "fetch");
1805
+ })();
1806
+ const p = F.apply(this, arguments);
1807
+ const rr = r;
1808
+ if (!rr || !p || typeof p.then !== "function") return p;
1809
+ return p.then(
1810
+ (res) => {
1811
+ safe("inspect.fetch", end)(rr, res.status);
1812
+ return res;
1813
+ },
1814
+ (e) => {
1815
+ safe("inspect.fetch", end)(rr, 0, e instanceof Error && e.name === "AbortError" ? "aborted" : "failed");
1816
+ throw e;
1817
+ }
1818
+ );
1819
+ };
1820
+ const X = typeof XMLHttpRequest !== "undefined" ? XMLHttpRequest.prototype : null;
1821
+ if (X) {
1822
+ const meta = /* @__PURE__ */ new WeakMap();
1823
+ const live = /* @__PURE__ */ new WeakMap();
1824
+ const O = X.open;
1825
+ const S = X.send;
1826
+ X.open = function(m, u) {
1827
+ meta.set(this, [m, u]);
1828
+ return O.apply(this, arguments);
1829
+ };
1830
+ X.send = function() {
1831
+ safe("inspect.xhr", () => {
1832
+ const m = meta.get(this);
1833
+ const r = m && begin(m[1], m[0], "xmlhttprequest");
1834
+ if (!r) return;
1835
+ const x = this;
1836
+ const had = live.get(x);
1837
+ if (had) {
1838
+ had.r = r;
1839
+ had.err = void 0;
1840
+ return;
1841
+ }
1842
+ const l = { r };
1843
+ live.set(x, l);
1844
+ const on = (t, v) => x.addEventListener(t, () => l.err = v);
1845
+ on("abort", "aborted");
1846
+ on("error", "failed");
1847
+ on("timeout", "timeout");
1848
+ x.addEventListener(
1849
+ "loadend",
1850
+ safe("inspect.xhr", () => {
1851
+ const q = l.r;
1852
+ if (!q) return;
1853
+ l.r = null;
1854
+ end(q, x.status, x.status ? void 0 : l.err || "failed");
1855
+ })
1856
+ );
1857
+ })();
1858
+ return S.apply(this, arguments);
1859
+ };
1860
+ }
1861
+ if (typeof PerformanceObserver !== "undefined") {
1862
+ try {
1863
+ new PerformanceObserver(safe("inspect.timing", (l) => {
1864
+ for (const e of l.getEntries()) entry(e);
1865
+ })).observe({ type: "resource" });
1866
+ } catch (e) {
1867
+ if (cur) cur.report("inspect.timing", e);
1868
+ }
1869
+ }
1870
+ }
1871
+ function sweep(a) {
1872
+ if (swept || !a.fresh || typeof performance === "undefined" || !performance.getEntriesByType) return;
1873
+ swept = true;
1874
+ const nav = performance.getEntriesByType("navigation")[0];
1875
+ if (!nav || here(abs(nav.name)) !== here(abs(location.href))) return;
1876
+ const o = origin();
1877
+ const list = [];
1878
+ for (const e of performance.getEntriesByType("resource")) {
1879
+ const u = e.initiatorType === "fetch" || e.initiatorType === "xmlhttprequest" ? abs(e.name) : null;
1880
+ if (!u || own(u)) continue;
1881
+ const q = { url: cleanUrl(e.name, a.keep), initiatorType: e.initiatorType, startTime: ms(o + e.startTime), endTime: ms(o + e.responseEnd), isInitial: true };
1882
+ const st = e.responseStatus;
1883
+ if (typeof st === "number" && st > 0) q.status = st;
1884
+ fill(q, e);
1885
+ list.push(q);
1886
+ }
1887
+ const keep = list.slice(-50).filter(() => take(net, MAX_REQS, "requests"));
1888
+ if (keep.length) a.push(plugin(NETWORK_PLUGIN, { requests: keep }));
1889
+ }
1890
+ function start3(a) {
1891
+ cur = a;
1892
+ scrub2 = a.scrub;
1893
+ seg2 = a.seg;
1894
+ if (a.console && !(wrapped & 1)) {
1895
+ wrapped |= 1;
1896
+ wrapConsole();
1897
+ }
1898
+ if (a.network) {
1899
+ if (!(wrapped & 2)) {
1900
+ wrapped |= 2;
1901
+ wrapNetwork();
1902
+ }
1903
+ safe("inspect.sweep", sweep)(a);
1904
+ }
1905
+ return {
1906
+ stop: safe("inspect.stop", () => {
1907
+ if (cur !== a) return;
1908
+ for (const r of open.slice())
1909
+ if (r.t1 !== void 0) {
1910
+ clearTimeout(r.timer);
1911
+ send(r);
1912
+ }
1913
+ open = [];
1914
+ cur = null;
1915
+ })
1916
+ };
1917
+ }
1918
+ function resetForTests() {
1919
+ cur = null;
1920
+ open = [];
1921
+ swept = false;
1922
+ busy = false;
1923
+ Object.assign(con, bucket());
1924
+ Object.assign(net, bucket());
1925
+ }
1926
+ var LINE, MAX_LINES, MAX_CHARS, MAX_REQS, RATE, BURST, WAIT_MS, LEVELS, CONSOLE_PLUGIN, NETWORK_PLUGIN, SECRET, AUTHZ, URLS, cur, stars3, scrub2, seg2, wrapped, swept, busy, bucket, con, net, plugin, plain, kind, open, abs, own, ms, origin, safe, here;
1927
+ var init_inspect = __esm({
1928
+ "src/inspect.ts"() {
1929
+ "use strict";
1930
+ LINE = 2e3;
1931
+ MAX_LINES = 1e3;
1932
+ MAX_CHARS = 4e5;
1933
+ MAX_REQS = 1e3;
1934
+ RATE = 20;
1935
+ BURST = 100;
1936
+ WAIT_MS = 1500;
1937
+ LEVELS = ["log", "info", "warn", "error"];
1938
+ CONSOLE_PLUGIN = "rrweb/console@1";
1939
+ NETWORK_PLUGIN = "rrweb/network@1";
1940
+ SECRET = /pass|pwd|secret|token|auth(?!or(?!i))|bearer|cookie|session.?id|sessid|(?:^|[^a-z])sid(?:$|[^a-z])|csrf|xsrf|signature|credential|card|cc-?num|cvc|cvv|iban|ssn|otp|e-?mail|phone|api.?key|private.?key/i;
1941
+ AUTHZ = /\b(?:Bearer|Basic|Digest|Token)\s+[\w.~+/=-]{6,}/gi;
1942
+ URLS = /\bhttps?:\/\/[^\s"'<>()\\]+/gi;
1943
+ cur = null;
1944
+ stars3 = (s) => s.replace(/\S/g, "*");
1945
+ scrub2 = stars3;
1946
+ seg2 = () => "/:redacted";
1947
+ wrapped = 0;
1948
+ swept = false;
1949
+ busy = false;
1950
+ bucket = () => ({ n: BURST, at: 0, used: 0, chars: 0, skipped: 0, done: false });
1951
+ con = bucket();
1952
+ net = bucket();
1953
+ plugin = (name, payload) => ({ type: 6, data: { plugin: name, payload }, timestamp: Date.now() });
1954
+ plain = (o) => {
1955
+ const p = Object.getPrototypeOf(o);
1956
+ return p === Object.prototype || p === null;
1957
+ };
1958
+ kind = (o) => {
1959
+ const p = Object.getPrototypeOf(o);
1960
+ const c = p && p.constructor && p.constructor.name;
1961
+ return typeof c === "string" && c ? c.slice(0, 60) : "Object";
1962
+ };
1963
+ open = [];
1964
+ abs = (u) => {
1965
+ try {
1966
+ return new URL(String(u), location.href);
1967
+ } catch (e) {
1968
+ return null;
1969
+ }
1970
+ };
1971
+ own = (u) => /^(api|cdn)\.ionblink\.com$/.test(u.hostname) || /\/v1\/batch$/.test(u.pathname) && u.searchParams.has("k") && u.searchParams.has("lane") || /\/v1\/config\/ib_pk_[^/]*$/.test(u.pathname);
1972
+ ms = (n) => Math.max(0, Math.round(n));
1973
+ origin = () => performance.timeOrigin || Date.now() - performance.now();
1974
+ safe = (where, f) => (...a) => {
1975
+ try {
1976
+ f(...a);
1977
+ } catch (e) {
1978
+ if (cur) cur.report(where, e);
1979
+ }
1980
+ };
1981
+ here = (u) => u ? u.origin + u.pathname + u.hash : "";
1982
+ }
1983
+ });
1984
+
1985
+ // src/replay-npm.ts
1986
+ var replay_npm_exports = {};
1987
+ __export(replay_npm_exports, {
1988
+ start: () => start4
1989
+ });
1990
+ var start4;
1991
+ var init_replay_npm = __esm({
1992
+ "src/replay-npm.ts"() {
1993
+ "use strict";
1994
+ init_replay();
1995
+ start4 = (api) => start2(api, () => Promise.resolve().then(() => (init_inspect(), inspect_exports)).then((m) => m.start));
1996
+ }
1997
+ });
1998
+
1464
1999
  // src/index.ts
1465
2000
  var index_exports = {};
1466
2001
  __export(index_exports, {
@@ -1498,7 +2033,7 @@ var LIMITS = {
1498
2033
  init_scrub();
1499
2034
 
1500
2035
  // src/consent.ts
1501
- init_util();
2036
+ var clamp = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
1502
2037
  var MODES = ["off", "basic", "full", "replay"];
1503
2038
  var rank = (m) => MODES.indexOf(m);
1504
2039
  var minMode = (a, b) => rank(a) <= rank(b) ? a : b;
@@ -1549,7 +2084,10 @@ function parseConfig(j) {
1549
2084
  // missing = true (errs towards asking)
1550
2085
  replay: {
1551
2086
  sample: typeof r.sample === "number" && isFinite(r.sample) ? clamp(r.sample, 0, 1) : 0,
1552
- on: r.on !== false
2087
+ on: r.on !== false,
2088
+ // console and network capture: only an explicit true (the site's setting) turns either on
2089
+ console: r.console === true,
2090
+ network: r.network === true
1553
2091
  },
1554
2092
  kill: false
1555
2093
  };
@@ -1689,42 +2227,42 @@ function createSession(store, clock = now, onEnd) {
1689
2227
  let saved = 0;
1690
2228
  const fresh = (t, a = uuid4(), p) => p ? { a, s: uuid7(t), st: t, la: t, p } : { a, s: uuid7(t), st: t, la: t };
1691
2229
  const save = (t) => {
1692
- store.set(cur);
2230
+ store.set(cur2);
1693
2231
  saved = t;
1694
2232
  };
1695
2233
  const t0 = clock();
1696
2234
  const init = store.get();
1697
- let cur = valid(init) && !expired(init, t0) ? init : fresh(t0, valid(init) ? init.a : void 0, valid(init) ? init.p : void 0);
1698
- if (cur !== init) save(t0);
2235
+ let cur2 = valid(init) && !expired(init, t0) ? init : fresh(t0, valid(init) ? init.a : void 0, valid(init) ? init.p : void 0);
2236
+ if (cur2 !== init) save(t0);
1699
2237
  function check(t) {
1700
- if (!expired(cur, t)) return false;
2238
+ if (!expired(cur2, t)) return false;
1701
2239
  const other = store.get(true);
1702
- if (valid(other) && other.a === cur.a && !expired(other, t)) {
1703
- cur = other;
2240
+ if (valid(other) && other.a === cur2.a && !expired(other, t)) {
2241
+ cur2 = other;
1704
2242
  return false;
1705
2243
  }
1706
- onEnd && onEnd(cur);
1707
- cur = fresh(t, cur.a, cur.p);
2244
+ onEnd && onEnd(cur2);
2245
+ cur2 = fresh(t, cur2.a, cur2.p);
1708
2246
  save(t);
1709
2247
  return true;
1710
2248
  }
1711
2249
  return {
1712
- peek: () => cur,
2250
+ peek: () => cur2,
1713
2251
  touch(t = clock()) {
1714
2252
  const rotated = check(t);
1715
- if (t > cur.la) cur.la = t;
2253
+ if (t > cur2.la) cur2.la = t;
1716
2254
  if (rotated || t - saved > 5e3) save(t);
1717
2255
  return rotated;
1718
2256
  },
1719
2257
  reset(t = clock()) {
1720
- onEnd && onEnd(cur);
1721
- cur = fresh(t);
2258
+ onEnd && onEnd(cur2);
2259
+ cur2 = fresh(t);
1722
2260
  save(t);
1723
- return cur;
2261
+ return cur2;
1724
2262
  },
1725
2263
  setPerson(id) {
1726
- if (id) cur.p = id;
1727
- else delete cur.p;
2264
+ if (id) cur2.p = id;
2265
+ else delete cur2.p;
1728
2266
  save(clock());
1729
2267
  }
1730
2268
  };
@@ -1732,9 +2270,9 @@ function createSession(store, clock = now, onEnd) {
1732
2270
 
1733
2271
  // src/storage.ts
1734
2272
  init_util();
1735
- function area(kind) {
2273
+ function area(kind2) {
1736
2274
  try {
1737
- const s = kind === "session" ? window.sessionStorage : window.localStorage;
2275
+ const s = kind2 === "session" ? window.sessionStorage : window.localStorage;
1738
2276
  return s || null;
1739
2277
  } catch (e) {
1740
2278
  report("storage", e);
@@ -1745,11 +2283,11 @@ function readCookie(name) {
1745
2283
  const m = document.cookie.match(new RegExp("(?:^|; )" + name + "=([^;]*)"));
1746
2284
  return m ? decodeURIComponent(m[1]) : null;
1747
2285
  }
1748
- function kv(name, kind, cookieDomain, codec) {
2286
+ function kv(name, kind2, cookieDomain, codec) {
1749
2287
  let mem = null;
1750
2288
  let held = false;
1751
2289
  let loaded = false;
1752
- const st = kind === "memory" ? null : area(kind === "cookie" ? "local" : kind);
2290
+ const st = kind2 === "memory" ? null : area(kind2 === "cookie" ? "local" : kind2);
1753
2291
  function write(v) {
1754
2292
  const s = v === null ? null : JSON.stringify(v);
1755
2293
  try {
@@ -1824,7 +2362,7 @@ function createTransport(d) {
1824
2362
  let bytes = 0;
1825
2363
  let dropped = 0;
1826
2364
  let wake = null;
1827
- const busy = {};
2365
+ const busy2 = {};
1828
2366
  const rand = d.random || Math.random;
1829
2367
  const maxBody = d.maxBody || LIMITS.maxBody;
1830
2368
  const halve = (it) => {
@@ -1884,7 +2422,7 @@ function createTransport(d) {
1884
2422
  async function send1(it) {
1885
2423
  const lane = it.b.lane;
1886
2424
  it.flying = true;
1887
- busy[lane] = true;
2425
+ busy2[lane] = true;
1888
2426
  let size = 0;
1889
2427
  let res = { status: 0 };
1890
2428
  try {
@@ -1903,7 +2441,7 @@ function createTransport(d) {
1903
2441
  size = typeof body === "string" ? body.length : body.byteLength;
1904
2442
  if (q.indexOf(it) < 0 || size > maxBody && halve(it)) {
1905
2443
  it.flying = false;
1906
- busy[lane] = false;
2444
+ busy2[lane] = false;
1907
2445
  return;
1908
2446
  }
1909
2447
  it.sent = true;
@@ -1912,20 +2450,20 @@ function createTransport(d) {
1912
2450
  res = { status: 0 };
1913
2451
  }
1914
2452
  it.flying = it.sent = false;
1915
- busy[lane] = false;
2453
+ busy2[lane] = false;
1916
2454
  handle(it, res, size);
1917
2455
  }
1918
2456
  function arm() {
1919
2457
  let next = Infinity;
1920
2458
  for (const it of q) if (!it.flying && it.at < next) next = it.at;
1921
2459
  if (next === Infinity) return;
1922
- const ms = Math.max(0, next - d.now());
2460
+ const ms2 = Math.max(0, next - d.now());
1923
2461
  if (wake !== null && wake <= next) return;
1924
2462
  wake = next;
1925
2463
  d.schedule(() => {
1926
2464
  wake = null;
1927
2465
  void pump();
1928
- }, ms);
2466
+ }, ms2);
1929
2467
  }
1930
2468
  function pump() {
1931
2469
  if (held || stopped || typeof navigator !== "undefined" && navigator.onLine === false) return Promise.resolve();
@@ -1936,7 +2474,7 @@ function createTransport(d) {
1936
2474
  if (it.p) runs.push(it.p);
1937
2475
  continue;
1938
2476
  }
1939
- if (busy[it.b.lane] || it.at > t) continue;
2477
+ if (busy2[it.b.lane] || it.at > t) continue;
1940
2478
  runs.push(it.p = send1(it).then(() => pump()));
1941
2479
  }
1942
2480
  arm();
@@ -2063,6 +2601,7 @@ function createIonBlink(deps) {
2063
2601
  if (debug) console.log("[ionblink]", ...a);
2064
2602
  };
2065
2603
  const full = () => mode === "full" || mode === "replay";
2604
+ const hidden = () => document.visibilityState === "hidden";
2066
2605
  const ingest = (lane) => api + "/v1/batch?k=" + encodeURIComponent(key) + "&lane=" + lane;
2067
2606
  const beacon = (lane, b) => {
2068
2607
  try {
@@ -2146,6 +2685,7 @@ function createIonBlink(deps) {
2146
2685
  const s = st || session.peek();
2147
2686
  while (buf.length) {
2148
2687
  const b = { ...env(s, "events"), events: buf.splice(0, LIMITS.maxEvents) };
2688
+ if (hidden()) b.hidden = true;
2149
2689
  if (ctxDirty) {
2150
2690
  b.context = context();
2151
2691
  ctxDirty = false;
@@ -2176,7 +2716,11 @@ function createIonBlink(deps) {
2176
2716
  return [{ ...b, replay: b.replay.slice(0, mid) }, { ...b, batch: uuid7(), seq, replay: b.replay.slice(mid) }];
2177
2717
  }
2178
2718
  function armE() {
2179
- if (!timerE && buf.length) timerE = setTimeout(guard("flush", () => cutEvents()), flushMs);
2719
+ if (!timerE && buf.length)
2720
+ timerE = setTimeout(guard("flush", () => {
2721
+ cutEvents();
2722
+ hidden() && transport && transport.beaconAll();
2723
+ }), hidden() ? 0 : flushMs);
2180
2724
  }
2181
2725
  function capture(e, p, t = now(), active = true) {
2182
2726
  if (mode === "off") return;
@@ -2197,9 +2741,9 @@ function createIonBlink(deps) {
2197
2741
  if (replay.on) restartReplay();
2198
2742
  }
2199
2743
  function startFull() {
2200
- const kind = o.storage === "memory" ? "memory" : o.storage === "cookie" ? "cookie" : "local";
2201
- sessKV = kv("ib_" + sfx, kind, o.cookieDomain, kind === "cookie" ? sessionCookie : void 0);
2202
- winKV = kv("ib_w_" + sfx, kind === "memory" ? "memory" : "session");
2744
+ const kind2 = o.storage === "memory" ? "memory" : o.storage === "cookie" ? "cookie" : "local";
2745
+ sessKV = kv("ib_" + sfx, kind2, o.cookieDomain, kind2 === "cookie" ? sessionCookie : void 0);
2746
+ winKV = kv("ib_w_" + sfx, kind2 === "memory" ? "memory" : "session");
2203
2747
  if (provisional) {
2204
2748
  sessKV.hold(true);
2205
2749
  winKV.hold(true);
@@ -2234,7 +2778,7 @@ function createIonBlink(deps) {
2234
2778
  beacon: (url, body) => !!navigator.sendBeacon && navigator.sendBeacon(url, body),
2235
2779
  gzip: gz ? async (s) => new Uint8Array(await new Response(new Blob([s]).stream().pipeThrough(new CompressionStream("gzip"))).arrayBuffer()) : null,
2236
2780
  now,
2237
- schedule: (fn, ms) => setTimeout(guard("transport", fn), ms),
2781
+ schedule: (fn, ms2) => setTimeout(guard("transport", fn), ms2),
2238
2782
  split,
2239
2783
  onAnswer: (a) => {
2240
2784
  if (typeof a.flush_s === "number" && isFinite(a.flush_s)) {
@@ -2450,8 +2994,8 @@ function createIonBlink(deps) {
2450
2994
  if (x || xLoad || mode === "off") return;
2451
2995
  xLoad = true;
2452
2996
  Promise.resolve().then(() => deps.loadX()).then(
2453
- guard("x.start", (start3) => {
2454
- const h = start3({
2997
+ guard("x.start", (start5) => {
2998
+ const h = start5({
2455
2999
  level,
2456
3000
  capture,
2457
3001
  on: autoOn,
@@ -2527,9 +3071,9 @@ function createIonBlink(deps) {
2527
3071
  }, { passive: true });
2528
3072
  on(d, "visibilitychange", () => {
2529
3073
  const t = now();
2530
- const hidden = d.visibilityState === "hidden";
2531
- fwd("visibilitychange", null, hidden, t);
2532
- if (hidden) {
3074
+ const h = hidden();
3075
+ fwd("visibilitychange", null, h, t);
3076
+ if (h) {
2533
3077
  if (full()) {
2534
3078
  emitSignals(t, false);
2535
3079
  emitVitals();
@@ -2537,7 +3081,7 @@ function createIonBlink(deps) {
2537
3081
  cutReplay();
2538
3082
  transport && transport.beaconAll();
2539
3083
  if (hideTimer) clearTimeout(hideTimer);
2540
- hideTimer = setTimeout(guard("replay.hidden", () => d.visibilityState === "hidden" && stopReplay()), 6e4);
3084
+ hideTimer = setTimeout(guard("replay.hidden", () => hidden() && stopReplay()), 6e4);
2541
3085
  } else sendBasic();
2542
3086
  } else {
2543
3087
  if (hideTimer) clearTimeout(hideTimer);
@@ -2650,7 +3194,7 @@ function createIonBlink(deps) {
2650
3194
  max = isMode(o.mode) ? o.mode : "replay";
2651
3195
  if (o.mask && ORDER.indexOf(o.mask) >= 0) explicitMask = o.mask;
2652
3196
  setReporter(onSdkError);
2653
- hiddenAtStart = document.visibilityState === "hidden";
3197
+ hiddenAtStart = hidden();
2654
3198
  idle(guard("boot", boot), 1e3);
2655
3199
  addEventListener("pagehide", guard("boot.hide", () => {
2656
3200
  if (!waiting) return;
@@ -2687,18 +3231,20 @@ function createIonBlink(deps) {
2687
3231
  if (!person || typeof person !== "object") return;
2688
3232
  const traits = cleanProps(person, false) || {};
2689
3233
  const before = level();
3234
+ let renewed = false;
2690
3235
  if (session && typeof traits.id === "string" && traits.id) {
2691
- const cur = session.peek().p;
2692
- if (cur && cur !== traits.id) {
3236
+ const cur2 = session.peek().p;
3237
+ if (cur2 && cur2 !== traits.id) {
2693
3238
  cutEvents();
2694
3239
  session.reset();
2695
3240
  ctxDirty = true;
3241
+ renewed = true;
2696
3242
  } else cutEvents();
2697
3243
  session.setPerson(traits.id.slice(0, 200));
2698
3244
  ctxDirty = true;
2699
3245
  }
2700
3246
  capture("$set", traits);
2701
- if (level() !== before) restartReplay();
3247
+ if (level() !== before || renewed && replay.on) restartReplay();
2702
3248
  }),
2703
3249
  identify: (id, traits) => ib.set({ ...traits || {}, id }),
2704
3250
  page: guard("page", (path, props) => {
@@ -2784,6 +3330,6 @@ init_scrub();
2784
3330
  var ionblink = createIonBlink({
2785
3331
  dist: "npm",
2786
3332
  loadX: () => Promise.resolve().then(() => (init_x(), x_exports)).then((m) => m.start),
2787
- loadReplay: () => Promise.resolve().then(() => (init_replay(), replay_exports)).then((m) => m.start)
3333
+ loadReplay: () => Promise.resolve().then(() => (init_replay_npm(), replay_npm_exports)).then((m) => m.start)
2788
3334
  });
2789
3335
  var index_default = ionblink;