ionblink-js 0.1.2 → 0.1.6

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.
@@ -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.6" : "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,13 +311,17 @@ 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
  }
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
+ }
322
325
  function scrubUrl(href) {
323
326
  if (scrub(href) === href) return href;
324
327
  try {
@@ -327,20 +330,22 @@ function scrubUrl(href) {
327
330
  u.searchParams.forEach((v, k) => {
328
331
  q += (q ? "&" : "?") + encodeURIComponent(k) + "=" + encodeURIComponent(scrub(v));
329
332
  });
330
- return u.origin + seg(u.pathname) + q;
333
+ return u.origin + u.pathname.split("/").map(assetSeg).join("/") + q;
331
334
  } catch (e) {
332
335
  return scrub(href);
333
336
  }
334
337
  }
335
338
  function maskAttrsFn(level, extraMask) {
336
- const text = maskTextFn(level, extraMask);
339
+ const text2 = maskTextFn(level, extraMask);
337
340
  const masked = MASKED + extraMask;
338
341
  return (a, el, mut) => {
339
342
  for (const k in a) {
340
343
  const v = a[k];
341
344
  if (typeof v !== "string" || !v) continue;
342
345
  const n = k.toLowerCase();
343
- if (DROP_ATTR.test(n)) {
346
+ if (n === "_csstext") {
347
+ if (v.length > 1e6) a[k] = v.replace(BIG_DATA, "data:,");
348
+ } else if (DROP_ATTR.test(n)) {
344
349
  if (mut) a[k] = null;
345
350
  else delete a[k];
346
351
  } else if (n === "value" && field(el)) a[k] = maskInputFn(v, el);
@@ -350,14 +355,14 @@ function maskAttrsFn(level, extraMask) {
350
355
  const sc = scheme ? scheme[1].toLowerCase() : "";
351
356
  a[k] = sc === "javascript" ? "#" : sc && sc !== "http" && sc !== "https" ? sc + ":*" : maskUrl(v).url || "#";
352
357
  } 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);
358
+ else if (n.indexOf("data-") === 0) a[k] = level === "text" || deep(el, masked) ? stars2(v) : UI_WORD.test(v) ? v : text2(v, el);
359
+ else if (TEXT_ATTR.test(n)) a[k] = text2(v, el);
355
360
  }
356
361
  };
357
362
  }
358
- function maskInputFn(text, el) {
363
+ function maskInputFn(text2, el) {
359
364
  if (isSensitive(el)) return "********";
360
- return text ? "*".repeat(text.length) : text;
365
+ return text2 ? "*".repeat(text2.length) : text2;
361
366
  }
362
367
  function validSelectors(list, doc) {
363
368
  if (!Array.isArray(list)) return "";
@@ -416,7 +421,7 @@ function selector(el) {
416
421
  }
417
422
  return parts.join(">");
418
423
  }
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;
424
+ 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
425
  var init_mask = __esm({
421
426
  "src/mask.ts"() {
422
427
  "use strict";
@@ -426,16 +431,18 @@ var init_mask = __esm({
426
431
  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
432
  SENSITIVE_RE = /pass|pwd|card|cc-?num|cvc|cvv|iban|ssn|otp|secret|token|email|phone|^pin$/i;
428
433
  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:"]';
434
+ MASKED = "[data-ib-mask],.ib-mask,[data-ph-mask],.ph-mask,.ph-sensitive";
435
+ NO_CAPTURE = "[data-ib-no-capture],.ib-no-capture,[data-ib-block],.ib-block,.ph-no-capture";
436
+ 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
437
  BLOCKED_TEXT = ",img,picture,video,image";
433
438
  stars2 = (t) => t.replace(/\S/g, "*");
434
439
  typed = (el) => !!el && (!!deep(el, "[contenteditable]:not([contenteditable=false])") || el.ownerDocument.designMode === "on");
440
+ HASHED = /^((?:[a-z\d]{1,23}[-_.])+)[\da-f]{8,64}\.[a-z\d]{2,5}$/i;
435
441
  LINK_ATTR = /^(href|action|formaction|cite|ping|xlink:href|rr_src)$/;
436
442
  SRC_ATTR = /^(src|srcset|poster|background|data)$/;
437
443
  TEXT_ATTR = /^(title|alt|placeholder|label|value|summary|abbr|aria-label|aria-description|aria-valuetext|aria-placeholder|aria-roledescription|aria-braillelabel|aria-brailleroledescription)$/;
438
444
  DROP_ATTR = /^(on|nonce$|srcdoc$)/;
445
+ BIG_DATA = /data:[\w/+.-]+;base64,[\w+/=]{32768,}/g;
439
446
  UI_WORD = /^[a-z][a-z-]{0,15}$/;
440
447
  field = (el) => !el || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName) && !/^(submit|button|reset|image|checkbox|radio)$/i.test(el.getAttribute("type") || "");
441
448
  }
@@ -444,11 +451,11 @@ var init_mask = __esm({
444
451
  // src/rage.ts
445
452
  function createRage(o = {}) {
446
453
  const n = o.n || 3;
447
- const ms = o.ms || 1e3;
454
+ const ms2 = o.ms || 1e3;
448
455
  const px = o.px || 30;
449
456
  let lt = -1e12, lx = 0, ly = 0, count = 0;
450
457
  return (t, x, y) => {
451
- if (t - lt <= ms && Math.abs(x - lx) + Math.abs(y - ly) <= px) count++;
458
+ if (t - lt <= ms2 && Math.abs(x - lx) + Math.abs(y - ly) <= px) count++;
452
459
  else count = 1;
453
460
  lt = t;
454
461
  lx = x;
@@ -478,11 +485,11 @@ function errInfo(e) {
478
485
  }
479
486
  function targetOf(el, level, rect) {
480
487
  const t = { tag: el.tagName.toLowerCase(), sel: selector(el) };
481
- const text = textFor(el, level);
488
+ const text2 = textFor(el, level);
482
489
  const label = labelFor(el, level);
483
490
  const role = el.getAttribute("role");
484
491
  const name = el.getAttribute("data-ib-name");
485
- if (text) t.text = text;
492
+ if (text2) t.text = text2;
486
493
  if (label) t.label = label;
487
494
  if (role) t.role = role.slice(0, 20);
488
495
  if (name) t.name = name.slice(0, 64);
@@ -539,17 +546,17 @@ function createAuto(ctx) {
539
546
  });
540
547
  mo.observe(document.documentElement, { childList: true, subtree: true, attributes: true, characterData: true });
541
548
  }
542
- function err(kind, type, message, source, stack) {
549
+ function err(kind2, type, message, source, stack) {
543
550
  if (!ctx.on("errors") || errors >= 20) return;
544
551
  if (message === "Script error." || message === "Script error") {
545
552
  if (scriptErrors++ > 0) return;
546
553
  }
547
- const k = kind + type + message + (source || "");
554
+ const k = kind2 + type + message + (source || "");
548
555
  seen[k] = (seen[k] || 0) + 1;
549
556
  if (seen[k] > 5) return;
550
557
  errors++;
551
558
  const p = {
552
- kind,
559
+ kind: kind2,
553
560
  type: type.slice(0, 64),
554
561
  message: scrub(message).slice(0, 500)
555
562
  };
@@ -558,6 +565,19 @@ function createAuto(ctx) {
558
565
  if (seen[k] > 1) p.n = seen[k];
559
566
  ctx.capture("$error", p, now());
560
567
  }
568
+ function field2(target, action, t) {
569
+ const el = target;
570
+ if (!ctx.on("forms") || !el || !/^(INPUT|SELECT|TEXTAREA)$/.test(el.tagName) || closest(el, NO_CAPTURE)) return;
571
+ const type = el.tagName === "INPUT" ? (el.getAttribute("type") || "text").toLowerCase() : el.tagName.toLowerCase();
572
+ if (type === "hidden" || type === "submit" || type === "button") return;
573
+ const fd = { type };
574
+ const label = fieldLabel(el, ctx.level());
575
+ const name = el.getAttribute("name");
576
+ if (label) fd.label = label;
577
+ if (name) fd.name = scrub(name.slice(0, 40));
578
+ if (isSensitive(el)) fd.sensitive = true;
579
+ ctx.capture("$field", { action, field: fd }, t);
580
+ }
561
581
  return {
562
582
  click(e, t, box, late) {
563
583
  const el = actionable(e.target);
@@ -592,21 +612,10 @@ function createAuto(ctx) {
592
612
  selection(t) {
593
613
  lastSel = t;
594
614
  },
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
- },
615
+ field: field2,
608
616
  input(e, t) {
609
617
  const el = e.target;
618
+ if (el && /^(select|checkbox|radio)/.test(el.type)) field2(el, "change", t);
610
619
  const f = el && el.form;
611
620
  if (!ctx.on("forms") || !f || started.has(f) || closest(f, NO_CAPTURE)) return;
612
621
  started.add(f);
@@ -648,12 +657,18 @@ var init_auto = __esm({
648
657
  function createReplay(api) {
649
658
  let loading = false;
650
659
  let budget = false;
660
+ const waits = () => {
661
+ const s = api.rs();
662
+ return !!s.cfg && s.mode !== "replay";
663
+ };
664
+ let waited = waits();
651
665
  const blocked = (path) => {
652
666
  const g = api.rs().opts.blockPaths;
653
667
  return !!g && g.some((x) => typeof x === "string" && glob(x).test(path));
654
668
  };
655
669
  function gate() {
656
670
  const s = api.rs();
671
+ if (waits()) waited = true;
657
672
  if (s.mode !== "replay" || !s.sid) return "mode";
658
673
  if (s.killed === "replay" || s.killed === "all") return "killed";
659
674
  if (!s.cfg) return s.failed ? "no_config" : "wait";
@@ -674,7 +689,7 @@ function createReplay(api) {
674
689
  afterLoad(() => idle(
675
690
  guard("replay.idle", () => {
676
691
  Promise.resolve().then(() => api.loadReplay()).then(
677
- guard("replay.start", (start3) => {
692
+ guard("replay.start", (start5) => {
678
693
  loading = false;
679
694
  const g2 = gate();
680
695
  if (g2) {
@@ -686,7 +701,7 @@ function createReplay(api) {
686
701
  api.rset({ on: true });
687
702
  let handle;
688
703
  try {
689
- handle = start3({
704
+ handle = start5({
690
705
  level: api.level(),
691
706
  mask: arr(s.opts.maskSelectors).concat(arr(rc && rc.mask_selectors)),
692
707
  block: arr(s.opts.blockSelectors).concat(arr(rc && rc.block_selectors)),
@@ -696,7 +711,13 @@ function createReplay(api) {
696
711
  if (r === "budget") budget = true;
697
712
  stop(r);
698
713
  },
699
- report
714
+ report,
715
+ cfg: () => {
716
+ const c = api.rs().cfg;
717
+ return c ? c.replay : void 0;
718
+ },
719
+ opts: s.opts,
720
+ fresh: !waited
700
721
  });
701
722
  } catch (e) {
702
723
  off("unsupported");
@@ -721,16 +742,16 @@ function createReplay(api) {
721
742
  ));
722
743
  }
723
744
  function stop(reason) {
724
- const cur = api.rget();
745
+ const cur2 = api.rget();
725
746
  api.rset(reason ? { on: false, off: reason } : { on: false });
726
- if (cur.handle) {
747
+ if (cur2.handle) {
727
748
  try {
728
- cur.handle.stop();
749
+ cur2.handle.stop();
729
750
  } catch (e) {
730
751
  report("replay.stop", e);
731
752
  }
732
753
  }
733
- if (cur.on) api.capture("$replay", { state: "stopped", reason: reason || "paused" }, now(), false);
754
+ if (cur2.on) api.capture("$replay", { state: "stopped", reason: reason || "paused" }, now(), false);
734
755
  }
735
756
  return {
736
757
  maybe,
@@ -741,9 +762,9 @@ function createReplay(api) {
741
762
  maybe();
742
763
  },
743
764
  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();
765
+ const cur2 = api.rget();
766
+ if (cur2.on && blocked(path)) stop("blocked_path");
767
+ else if (!cur2.on && cur2.off === "blocked_path") maybe();
747
768
  }
748
769
  };
749
770
  }
@@ -926,8 +947,8 @@ function cv(a) {
926
947
  function push(a, v, cap = 200) {
927
948
  if (a.length < cap) a.push(v);
928
949
  }
929
- function createSignals(start3) {
930
- let s0 = start3;
950
+ function createSignals(start5) {
951
+ let s0 = start5;
931
952
  let ttfi;
932
953
  let ptype = "none";
933
954
  let moves = 0, steps = 0, flicks = 0, clicks = 0, noApproach = 0, offLt3 = 0, pressLt25 = 0;
@@ -1156,6 +1177,7 @@ var init_signals = __esm({
1156
1177
  // src/vitals.ts
1157
1178
  function watchVitals() {
1158
1179
  let lcp;
1180
+ let lcpEl;
1159
1181
  let cls = 0;
1160
1182
  let win = 0;
1161
1183
  let winStart = 0;
@@ -1178,6 +1200,7 @@ function watchVitals() {
1178
1200
  }
1179
1201
  observe("largest-contentful-paint", (e) => {
1180
1202
  lcp = e.startTime;
1203
+ lcpEl = e.element;
1181
1204
  });
1182
1205
  observe("layout-shift", (e) => {
1183
1206
  const s = e;
@@ -1201,6 +1224,7 @@ function watchVitals() {
1201
1224
  read() {
1202
1225
  const out = {};
1203
1226
  if (lcp !== void 0) out.lcp = Math.round(lcp);
1227
+ if (lcpEl) out.lcp_el = selector(lcpEl);
1204
1228
  if (types.indexOf("layout-shift") >= 0) out.cls = Math.round(cls * 1e3) / 1e3;
1205
1229
  const d = Object.keys(inter).map((k) => inter[+k]).sort((a, b) => b - a);
1206
1230
  if (d.length) out.inp = Math.round(d[Math.min(d.length - 1, Math.floor(d.length / 50))]);
@@ -1220,6 +1244,7 @@ function watchVitals() {
1220
1244
  var init_vitals = __esm({
1221
1245
  "src/vitals.ts"() {
1222
1246
  "use strict";
1247
+ init_mask();
1223
1248
  init_util();
1224
1249
  }
1225
1250
  });
@@ -1254,6 +1279,10 @@ function start(api, navStart) {
1254
1279
  if (lastA) eng += Math.min(Math.max(0, t - lastA), 5e3);
1255
1280
  lastA = t;
1256
1281
  };
1282
+ const page = () => ({
1283
+ engaged_ms: Math.round(eng),
1284
+ scroll_pct: Math.min(100, Math.round((maxY + window.innerHeight) / (document.documentElement.scrollHeight || 1) * 100))
1285
+ });
1257
1286
  const h = {
1258
1287
  pointermove: (e, t) => {
1259
1288
  act(t);
@@ -1298,13 +1327,14 @@ function start(api, navStart) {
1298
1327
  },
1299
1328
  copy: () => c() && sig.copy(),
1300
1329
  paste: () => c() && sig.paste(),
1301
- focusin: (e, t) => auto.field(e, true, t),
1302
- focusout: (e, t) => auto.field(e, false, t),
1330
+ focusin: (e, t) => auto.field(e.target, "focus", t),
1331
+ focusout: (e, t) => auto.field(e.target, "blur", t),
1303
1332
  submit: (e, t) => auto.submit(e, t),
1304
1333
  selectionchange: (_e, t) => auto.selection(t),
1305
1334
  error: (e) => e instanceof ErrorEvent && auto.error(e),
1306
1335
  unhandledrejection: (e) => auto.rejection(e),
1307
1336
  securitypolicyviolation: (e) => {
1337
+ if (e.disposition === "report") return;
1308
1338
  auto.csp(e);
1309
1339
  cspHint(e);
1310
1340
  },
@@ -1326,11 +1356,10 @@ function start(api, navStart) {
1326
1356
  if (f) f(e, t, extra, late);
1327
1357
  },
1328
1358
  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
- }),
1359
+ // a page hidden for good without a pagehide (in-app browsers, a killed tab) sends no $page_leave: its last
1360
+ // $signals carries the depth and engaged time instead
1361
+ summary: (t) => ({ ...sig.summary(t), ...page() }),
1362
+ page,
1334
1363
  vitals: () => vit ? vit.read() : {},
1335
1364
  automation: readAutomation,
1336
1365
  queue: (name) => openQueue(name),
@@ -1354,11 +1383,7 @@ var init_x = __esm({
1354
1383
  });
1355
1384
 
1356
1385
  // src/replay.ts
1357
- var replay_exports = {};
1358
- __export(replay_exports, {
1359
- start: () => start2
1360
- });
1361
- function start2(api) {
1386
+ function start2(api, loadInspect) {
1362
1387
  if (CRAWLER.test(navigator.userAgent)) return "crawler";
1363
1388
  if (document.getElementsByTagName("*").length > MAX_ELEMENTS) return "dom_too_large";
1364
1389
  const extraMask = validSelectors(api.mask);
@@ -1410,7 +1435,7 @@ function start2(api) {
1410
1435
  maskEvent(ev);
1411
1436
  buf.push(ev);
1412
1437
  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);
1438
+ 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
1439
  bytes += est;
1415
1440
  total += est;
1416
1441
  if (bytes >= CHUNK) flush();
@@ -1437,9 +1462,51 @@ function start2(api) {
1437
1462
  return true;
1438
1463
  }
1439
1464
  });
1465
+ let ins = null;
1466
+ const o = api.opts;
1467
+ const net2 = o.network;
1468
+ const allow = (k) => {
1469
+ const c = api.cfg();
1470
+ return !!c && c[k] === true && o[k] !== false;
1471
+ };
1472
+ if (loadInspect && (allow("console") || allow("network")))
1473
+ loadInspect().then(
1474
+ (start5) => {
1475
+ if (!live) return;
1476
+ try {
1477
+ ins = start5({
1478
+ get console() {
1479
+ return allow("console");
1480
+ },
1481
+ get network() {
1482
+ return allow("network");
1483
+ },
1484
+ star: api.level === "text",
1485
+ fresh: api.fresh,
1486
+ keep: net2 && typeof net2 === "object" && Array.isArray(net2.keepParams) ? net2.keepParams.filter((k) => typeof k === "string").slice(0, 20) : [],
1487
+ push: (e) => {
1488
+ try {
1489
+ emit(e);
1490
+ } catch (x) {
1491
+ api.report("inspect.emit", x);
1492
+ }
1493
+ },
1494
+ report: api.report,
1495
+ scrub,
1496
+ seg
1497
+ });
1498
+ } catch (e) {
1499
+ api.report("inspect.start", e);
1500
+ }
1501
+ },
1502
+ (e) => api.report("inspect.load", e)
1503
+ // blocked or offline: the recording goes on without them
1504
+ );
1440
1505
  return {
1441
1506
  flush,
1442
1507
  stop() {
1508
+ if (ins) ins.stop();
1509
+ ins = null;
1443
1510
  live = false;
1444
1511
  if (stop) stop();
1445
1512
  flush();
@@ -1461,6 +1528,459 @@ var init_replay = __esm({
1461
1528
  }
1462
1529
  });
1463
1530
 
1531
+ // src/inspect.ts
1532
+ var inspect_exports = {};
1533
+ __export(inspect_exports, {
1534
+ BURST: () => BURST,
1535
+ LINE: () => LINE,
1536
+ MAX_CHARS: () => MAX_CHARS,
1537
+ MAX_LINES: () => MAX_LINES,
1538
+ MAX_REQS: () => MAX_REQS,
1539
+ RATE: () => RATE,
1540
+ cleanUrl: () => cleanUrl,
1541
+ frames: () => frames,
1542
+ line: () => line,
1543
+ resetForTests: () => resetForTests,
1544
+ start: () => start3,
1545
+ str: () => str,
1546
+ text: () => text
1547
+ });
1548
+ function note(text2) {
1549
+ if (cur) cur.push(plugin(CONSOLE_PLUGIN, { level: "warn", trace: [], payload: [JSON.stringify("[ionblink] " + text2)] }));
1550
+ }
1551
+ function take(b, max, what) {
1552
+ if (b.done) return false;
1553
+ if (b.used >= max || b.chars > MAX_CHARS) {
1554
+ b.done = true;
1555
+ note(what + " capture stopped for this page after " + b.used);
1556
+ return false;
1557
+ }
1558
+ const t = Date.now();
1559
+ b.n = Math.min(BURST, b.n + (t - b.at) * RATE / 1e3);
1560
+ b.at = t;
1561
+ if (b.n < 1) {
1562
+ if (!b.skipped++)
1563
+ setTimeout(() => {
1564
+ if (b.skipped && !b.done) note(b.skipped + " " + what + " skipped: more than " + RATE + " a second");
1565
+ b.skipped = 0;
1566
+ }, 1e3);
1567
+ return false;
1568
+ }
1569
+ b.n--;
1570
+ b.used++;
1571
+ return true;
1572
+ }
1573
+ function str(s, max) {
1574
+ let t = s.slice(0, max + 320);
1575
+ t = cur && cur.star ? stars3(t) : scrub2(t.replace(AUTHZ, stars3).replace(URLS, (u) => cleanUrl(u, []) || u.split(/[?#]/)[0]));
1576
+ return t.length > max ? t.slice(0, max - 1) + "\u2026" : t;
1577
+ }
1578
+ function text(v, room) {
1579
+ if (typeof v === "string") return JSON.stringify(str(v, room));
1580
+ let n = 0;
1581
+ const seen = [];
1582
+ const walk = (x, d) => {
1583
+ if (++n > 100) return "\u2026";
1584
+ if (x === null || typeof x === "boolean") return x;
1585
+ switch (typeof x) {
1586
+ case "string":
1587
+ return str(x, 300);
1588
+ case "number":
1589
+ return isFinite(x) ? x : String(x);
1590
+ case "undefined":
1591
+ return "undefined";
1592
+ case "bigint":
1593
+ return x + "n";
1594
+ case "symbol":
1595
+ return String(x);
1596
+ case "function":
1597
+ return "\u0192 " + (x.name ? str(x.name, 60) : "anonymous");
1598
+ }
1599
+ const o = x;
1600
+ if (o instanceof Error) return str(o.name + ": " + o.message, 300);
1601
+ if (o instanceof Date) return isNaN(o.getTime()) ? "Invalid Date" : o.toISOString();
1602
+ if (o instanceof RegExp) return String(o);
1603
+ if (typeof Node !== "undefined" && o instanceof Node) return "<" + o.nodeName.toLowerCase() + ">";
1604
+ if (o === window) return "[Window]";
1605
+ if (seen.indexOf(o) >= 0) return "[Circular]";
1606
+ if (o instanceof Map || o instanceof Set) return (o instanceof Map ? "Map(" : "Set(") + o.size + ")";
1607
+ if (ArrayBuffer.isView(o)) return kind(o) + "(" + (o.length ?? o.byteLength) + ")";
1608
+ if (!Array.isArray(o) && !plain(o)) return "[" + kind(o) + "]";
1609
+ if (d > 2) return Array.isArray(o) ? "[Array(" + o.length + ")]" : "[Object]";
1610
+ seen.push(o);
1611
+ let r;
1612
+ if (Array.isArray(o)) {
1613
+ const a = o.slice(0, 20).map((y) => walk(y, d + 1));
1614
+ if (o.length > 20) a.push("\u2026 " + (o.length - 20) + " more");
1615
+ r = a;
1616
+ } else {
1617
+ const out = {};
1618
+ const ks = Object.keys(o);
1619
+ for (const k of ks.slice(0, 20)) {
1620
+ if (k === "__proto__") continue;
1621
+ let y;
1622
+ try {
1623
+ y = o[k];
1624
+ } catch (e) {
1625
+ y = "[unreadable]";
1626
+ }
1627
+ out[str(k, 100)] = SECRET.test(k) && y !== null && y !== void 0 && y !== "" ? "********" : walk(y, d + 1);
1628
+ }
1629
+ if (ks.length > 20) out["\u2026"] = ks.length - 20 + " more keys";
1630
+ r = out;
1631
+ }
1632
+ seen.pop();
1633
+ return r;
1634
+ };
1635
+ try {
1636
+ const j = JSON.stringify(walk(v, 0));
1637
+ return j === void 0 ? String(v) : j;
1638
+ } catch (e) {
1639
+ return '"[unreadable]"';
1640
+ }
1641
+ }
1642
+ function frames(stack) {
1643
+ const out = [];
1644
+ if (typeof stack !== "string") return out;
1645
+ for (const l of stack.slice(0, 8e3).split("\n")) {
1646
+ const f = l.trim();
1647
+ if (f.indexOf("at ") !== 0 && !/@[^@]*:\d+(?::\d+)?$/.test(f)) continue;
1648
+ const s = scrub2(f.slice(0, 620).replace(/[?#][^\s:)]*/g, "").replace(URLS, (u) => cleanUrl(u, []) || u));
1649
+ out.push(s.length > 300 ? s.slice(0, 299) + "\u2026" : s);
1650
+ if (out.length >= 10) break;
1651
+ }
1652
+ return out;
1653
+ }
1654
+ function line(level, args, trace, lead) {
1655
+ const a = cur;
1656
+ if (!a || !a.console || busy) return;
1657
+ const first = args[0];
1658
+ if (typeof first === "string" && first.indexOf("[ionblink]") === 0) return;
1659
+ busy = true;
1660
+ try {
1661
+ if (!take(con, MAX_LINES, "console lines")) return;
1662
+ const out = lead ? [JSON.stringify(lead)] : [];
1663
+ let room = LINE - (lead ? lead.length + 2 : 0);
1664
+ let tr = trace ? trace() : [];
1665
+ for (let i = 0; i < args.length && room > 0; i++) {
1666
+ const v = args[i];
1667
+ if (v instanceof Error && !tr.length) tr = frames(v.stack);
1668
+ let s = text(v, room);
1669
+ if (s.length > room) s = s.slice(0, Math.max(0, room - 1)) + "\u2026";
1670
+ room -= s.length;
1671
+ out.push(s);
1672
+ }
1673
+ con.chars += LINE - room;
1674
+ a.push(plugin(CONSOLE_PLUGIN, { level, trace: tr, payload: out }));
1675
+ } catch (e) {
1676
+ a.report("inspect.console", e);
1677
+ } finally {
1678
+ busy = false;
1679
+ }
1680
+ }
1681
+ function wrapConsole() {
1682
+ const c = console;
1683
+ for (const l of LEVELS) {
1684
+ const orig = c[l];
1685
+ if (typeof orig !== "function") continue;
1686
+ c[l] = function(...a) {
1687
+ line(l, a);
1688
+ return orig.apply(this, a);
1689
+ };
1690
+ }
1691
+ addEventListener("error", (e) => {
1692
+ const err = e.error;
1693
+ if (err instanceof Error) line("error", [err.name + ": " + err.message], () => frames(err.stack), "Uncaught");
1694
+ else line("error", [e.message || "Script error"], () => e.filename ? frames("at " + e.filename + ":" + e.lineno + ":" + e.colno) : [], "Uncaught");
1695
+ });
1696
+ addEventListener("unhandledrejection", (e) => {
1697
+ const r = e.reason;
1698
+ if (r instanceof Error) line("error", [r.name + ": " + r.message], () => frames(r.stack), "Uncaught (in promise)");
1699
+ else line("error", [r], void 0, "Uncaught (in promise)");
1700
+ });
1701
+ }
1702
+ function cleanUrl(href, keep) {
1703
+ let u;
1704
+ try {
1705
+ u = new URL(href);
1706
+ } catch (e) {
1707
+ return "";
1708
+ }
1709
+ if (u.protocol !== "http:" && u.protocol !== "https:") return u.protocol;
1710
+ let q = "";
1711
+ if (keep.length)
1712
+ u.searchParams.forEach((v, k) => {
1713
+ if (keep.indexOf(k) >= 0) q += (q ? "&" : "?") + encodeURIComponent(k) + "=" + encodeURIComponent(scrub2(v.slice(0, 520)).slice(0, 200));
1714
+ });
1715
+ return (u.origin + seg2(u.pathname)).slice(0, 1e3) + q;
1716
+ }
1717
+ function fill(q, pe) {
1718
+ if (typeof pe.transferSize === "number") q.transferSize = pe.transferSize;
1719
+ if (typeof pe.encodedBodySize === "number") q.encodedBodySize = pe.encodedBodySize;
1720
+ if (!(pe.responseStart > 0)) return;
1721
+ const t = {};
1722
+ let any = false;
1723
+ const put = (k, v) => {
1724
+ if (ms(v) > 0) any = !!(t[k] = ms(v));
1725
+ };
1726
+ put("dns", pe.domainLookupEnd - pe.domainLookupStart);
1727
+ put("connect", pe.connectEnd - pe.connectStart);
1728
+ if (pe.secureConnectionStart > 0) put("tls", pe.connectEnd - pe.secureConnectionStart);
1729
+ put("wait", pe.responseStart - (pe.requestStart || pe.startTime));
1730
+ put("download", pe.responseEnd - pe.responseStart);
1731
+ if (any) q.timing = t;
1732
+ }
1733
+ function begin(u, m, type) {
1734
+ if (!cur || !cur.network) return null;
1735
+ const p = abs(u);
1736
+ if (!p || own(p)) return null;
1737
+ const r = { url: p.href, method: (typeof m === "string" && m ? m : "GET").toUpperCase().slice(0, 12), type, t0: performance.now() };
1738
+ open.push(r);
1739
+ if (open.length > 200) open.shift();
1740
+ return r;
1741
+ }
1742
+ function end(r, status, error) {
1743
+ r.t1 = performance.now();
1744
+ r.status = status;
1745
+ if (error) r.error = error;
1746
+ if (r.pe) send(r);
1747
+ else r.timer = setTimeout(() => send(r), WAIT_MS);
1748
+ }
1749
+ function entry(pe) {
1750
+ if (pe.initiatorType !== "fetch" && pe.initiatorType !== "xmlhttprequest") return;
1751
+ for (const r of open)
1752
+ if (!r.pe && r.url === pe.name && r.t0 <= pe.startTime + 20) {
1753
+ r.pe = pe;
1754
+ if (r.t1 !== void 0) {
1755
+ clearTimeout(r.timer);
1756
+ send(r);
1757
+ }
1758
+ return;
1759
+ }
1760
+ }
1761
+ function send(r) {
1762
+ const i = open.indexOf(r);
1763
+ if (i < 0) return;
1764
+ open.splice(i, 1);
1765
+ const a = cur;
1766
+ if (!a || !take(net, MAX_REQS, "requests")) return;
1767
+ const pe = r.pe;
1768
+ const o = origin();
1769
+ const q = {
1770
+ url: cleanUrl(r.url, a.keep),
1771
+ method: r.method,
1772
+ initiatorType: r.type,
1773
+ status: r.status,
1774
+ startTime: ms(o + (pe ? pe.startTime : r.t0)),
1775
+ endTime: ms(o + (pe && pe.responseEnd > 0 ? pe.responseEnd : r.t1))
1776
+ };
1777
+ if (r.error) q.error = r.error;
1778
+ if (pe) fill(q, pe);
1779
+ a.push(plugin(NETWORK_PLUGIN, { requests: [q] }));
1780
+ }
1781
+ function wrapNetwork() {
1782
+ const w = window;
1783
+ const F = w.fetch;
1784
+ if (typeof F === "function")
1785
+ w.fetch = function(input, init) {
1786
+ let r = null;
1787
+ safe("inspect.fetch", () => {
1788
+ const req = typeof Request !== "undefined" && input instanceof Request ? input : null;
1789
+ r = begin(req ? req.url : input, init && init.method || req && req.method, "fetch");
1790
+ })();
1791
+ const p = F.apply(this, arguments);
1792
+ const rr = r;
1793
+ if (!rr || !p || typeof p.then !== "function") return p;
1794
+ return p.then(
1795
+ (res) => {
1796
+ safe("inspect.fetch", end)(rr, res.status);
1797
+ return res;
1798
+ },
1799
+ (e) => {
1800
+ safe("inspect.fetch", end)(rr, 0, e instanceof Error && e.name === "AbortError" ? "aborted" : "failed");
1801
+ throw e;
1802
+ }
1803
+ );
1804
+ };
1805
+ const X = typeof XMLHttpRequest !== "undefined" ? XMLHttpRequest.prototype : null;
1806
+ if (X) {
1807
+ const meta = /* @__PURE__ */ new WeakMap();
1808
+ const live = /* @__PURE__ */ new WeakMap();
1809
+ const O = X.open;
1810
+ const S = X.send;
1811
+ X.open = function(m, u) {
1812
+ meta.set(this, [m, u]);
1813
+ return O.apply(this, arguments);
1814
+ };
1815
+ X.send = function() {
1816
+ safe("inspect.xhr", () => {
1817
+ const m = meta.get(this);
1818
+ const r = m && begin(m[1], m[0], "xmlhttprequest");
1819
+ if (!r) return;
1820
+ const x = this;
1821
+ const had = live.get(x);
1822
+ if (had) {
1823
+ had.r = r;
1824
+ had.err = void 0;
1825
+ return;
1826
+ }
1827
+ const l = { r };
1828
+ live.set(x, l);
1829
+ const on = (t, v) => x.addEventListener(t, () => l.err = v);
1830
+ on("abort", "aborted");
1831
+ on("error", "failed");
1832
+ on("timeout", "timeout");
1833
+ x.addEventListener(
1834
+ "loadend",
1835
+ safe("inspect.xhr", () => {
1836
+ const q = l.r;
1837
+ if (!q) return;
1838
+ l.r = null;
1839
+ end(q, x.status, x.status ? void 0 : l.err || "failed");
1840
+ })
1841
+ );
1842
+ })();
1843
+ return S.apply(this, arguments);
1844
+ };
1845
+ }
1846
+ if (typeof PerformanceObserver !== "undefined") {
1847
+ try {
1848
+ new PerformanceObserver(safe("inspect.timing", (l) => {
1849
+ for (const e of l.getEntries()) entry(e);
1850
+ })).observe({ type: "resource" });
1851
+ } catch (e) {
1852
+ if (cur) cur.report("inspect.timing", e);
1853
+ }
1854
+ }
1855
+ }
1856
+ function sweep(a) {
1857
+ if (swept || !a.fresh || typeof performance === "undefined" || !performance.getEntriesByType) return;
1858
+ swept = true;
1859
+ const nav = performance.getEntriesByType("navigation")[0];
1860
+ if (!nav || here(abs(nav.name)) !== here(abs(location.href))) return;
1861
+ const o = origin();
1862
+ const list = [];
1863
+ for (const e of performance.getEntriesByType("resource")) {
1864
+ const u = e.initiatorType === "fetch" || e.initiatorType === "xmlhttprequest" ? abs(e.name) : null;
1865
+ if (!u || own(u)) continue;
1866
+ const q = { url: cleanUrl(e.name, a.keep), initiatorType: e.initiatorType, startTime: ms(o + e.startTime), endTime: ms(o + e.responseEnd), isInitial: true };
1867
+ const st = e.responseStatus;
1868
+ if (typeof st === "number" && st > 0) q.status = st;
1869
+ fill(q, e);
1870
+ list.push(q);
1871
+ }
1872
+ const keep = list.slice(-50).filter(() => take(net, MAX_REQS, "requests"));
1873
+ if (keep.length) a.push(plugin(NETWORK_PLUGIN, { requests: keep }));
1874
+ }
1875
+ function start3(a) {
1876
+ cur = a;
1877
+ scrub2 = a.scrub;
1878
+ seg2 = a.seg;
1879
+ if (a.console && !(wrapped & 1)) {
1880
+ wrapped |= 1;
1881
+ wrapConsole();
1882
+ }
1883
+ if (a.network) {
1884
+ if (!(wrapped & 2)) {
1885
+ wrapped |= 2;
1886
+ wrapNetwork();
1887
+ }
1888
+ safe("inspect.sweep", sweep)(a);
1889
+ }
1890
+ return {
1891
+ stop: safe("inspect.stop", () => {
1892
+ if (cur !== a) return;
1893
+ for (const r of open.slice())
1894
+ if (r.t1 !== void 0) {
1895
+ clearTimeout(r.timer);
1896
+ send(r);
1897
+ }
1898
+ open = [];
1899
+ cur = null;
1900
+ })
1901
+ };
1902
+ }
1903
+ function resetForTests() {
1904
+ cur = null;
1905
+ open = [];
1906
+ swept = false;
1907
+ busy = false;
1908
+ Object.assign(con, bucket());
1909
+ Object.assign(net, bucket());
1910
+ }
1911
+ 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;
1912
+ var init_inspect = __esm({
1913
+ "src/inspect.ts"() {
1914
+ "use strict";
1915
+ LINE = 2e3;
1916
+ MAX_LINES = 1e3;
1917
+ MAX_CHARS = 4e5;
1918
+ MAX_REQS = 1e3;
1919
+ RATE = 20;
1920
+ BURST = 100;
1921
+ WAIT_MS = 1500;
1922
+ LEVELS = ["log", "info", "warn", "error"];
1923
+ CONSOLE_PLUGIN = "rrweb/console@1";
1924
+ NETWORK_PLUGIN = "rrweb/network@1";
1925
+ 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;
1926
+ AUTHZ = /\b(?:Bearer|Basic|Digest|Token)\s+[\w.~+/=-]{6,}/gi;
1927
+ URLS = /\bhttps?:\/\/[^\s"'<>()\\]+/gi;
1928
+ cur = null;
1929
+ stars3 = (s) => s.replace(/\S/g, "*");
1930
+ scrub2 = stars3;
1931
+ seg2 = () => "/:redacted";
1932
+ wrapped = 0;
1933
+ swept = false;
1934
+ busy = false;
1935
+ bucket = () => ({ n: BURST, at: 0, used: 0, chars: 0, skipped: 0, done: false });
1936
+ con = bucket();
1937
+ net = bucket();
1938
+ plugin = (name, payload) => ({ type: 6, data: { plugin: name, payload }, timestamp: Date.now() });
1939
+ plain = (o) => {
1940
+ const p = Object.getPrototypeOf(o);
1941
+ return p === Object.prototype || p === null;
1942
+ };
1943
+ kind = (o) => {
1944
+ const p = Object.getPrototypeOf(o);
1945
+ const c = p && p.constructor && p.constructor.name;
1946
+ return typeof c === "string" && c ? c.slice(0, 60) : "Object";
1947
+ };
1948
+ open = [];
1949
+ abs = (u) => {
1950
+ try {
1951
+ return new URL(String(u), location.href);
1952
+ } catch (e) {
1953
+ return null;
1954
+ }
1955
+ };
1956
+ 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);
1957
+ ms = (n) => Math.max(0, Math.round(n));
1958
+ origin = () => performance.timeOrigin || Date.now() - performance.now();
1959
+ safe = (where, f) => (...a) => {
1960
+ try {
1961
+ f(...a);
1962
+ } catch (e) {
1963
+ if (cur) cur.report(where, e);
1964
+ }
1965
+ };
1966
+ here = (u) => u ? u.origin + u.pathname + u.hash : "";
1967
+ }
1968
+ });
1969
+
1970
+ // src/replay-npm.ts
1971
+ var replay_npm_exports = {};
1972
+ __export(replay_npm_exports, {
1973
+ start: () => start4
1974
+ });
1975
+ var start4;
1976
+ var init_replay_npm = __esm({
1977
+ "src/replay-npm.ts"() {
1978
+ "use strict";
1979
+ init_replay();
1980
+ start4 = (api) => start2(api, () => Promise.resolve().then(() => (init_inspect(), inspect_exports)).then((m) => m.start));
1981
+ }
1982
+ });
1983
+
1464
1984
  // src/index.ts
1465
1985
  var index_exports = {};
1466
1986
  __export(index_exports, {
@@ -1498,7 +2018,7 @@ var LIMITS = {
1498
2018
  init_scrub();
1499
2019
 
1500
2020
  // src/consent.ts
1501
- init_util();
2021
+ var clamp = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
1502
2022
  var MODES = ["off", "basic", "full", "replay"];
1503
2023
  var rank = (m) => MODES.indexOf(m);
1504
2024
  var minMode = (a, b) => rank(a) <= rank(b) ? a : b;
@@ -1549,7 +2069,10 @@ function parseConfig(j) {
1549
2069
  // missing = true (errs towards asking)
1550
2070
  replay: {
1551
2071
  sample: typeof r.sample === "number" && isFinite(r.sample) ? clamp(r.sample, 0, 1) : 0,
1552
- on: r.on !== false
2072
+ on: r.on !== false,
2073
+ // console and network capture: only an explicit true (the site's setting) turns either on
2074
+ console: r.console === true,
2075
+ network: r.network === true
1553
2076
  },
1554
2077
  kill: false
1555
2078
  };
@@ -1689,42 +2212,42 @@ function createSession(store, clock = now, onEnd) {
1689
2212
  let saved = 0;
1690
2213
  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
2214
  const save = (t) => {
1692
- store.set(cur);
2215
+ store.set(cur2);
1693
2216
  saved = t;
1694
2217
  };
1695
2218
  const t0 = clock();
1696
2219
  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);
2220
+ let cur2 = valid(init) && !expired(init, t0) ? init : fresh(t0, valid(init) ? init.a : void 0, valid(init) ? init.p : void 0);
2221
+ if (cur2 !== init) save(t0);
1699
2222
  function check(t) {
1700
- if (!expired(cur, t)) return false;
2223
+ if (!expired(cur2, t)) return false;
1701
2224
  const other = store.get(true);
1702
- if (valid(other) && other.a === cur.a && !expired(other, t)) {
1703
- cur = other;
2225
+ if (valid(other) && other.a === cur2.a && !expired(other, t)) {
2226
+ cur2 = other;
1704
2227
  return false;
1705
2228
  }
1706
- onEnd && onEnd(cur);
1707
- cur = fresh(t, cur.a, cur.p);
2229
+ onEnd && onEnd(cur2);
2230
+ cur2 = fresh(t, cur2.a, cur2.p);
1708
2231
  save(t);
1709
2232
  return true;
1710
2233
  }
1711
2234
  return {
1712
- peek: () => cur,
2235
+ peek: () => cur2,
1713
2236
  touch(t = clock()) {
1714
2237
  const rotated = check(t);
1715
- if (t > cur.la) cur.la = t;
2238
+ if (t > cur2.la) cur2.la = t;
1716
2239
  if (rotated || t - saved > 5e3) save(t);
1717
2240
  return rotated;
1718
2241
  },
1719
2242
  reset(t = clock()) {
1720
- onEnd && onEnd(cur);
1721
- cur = fresh(t);
2243
+ onEnd && onEnd(cur2);
2244
+ cur2 = fresh(t);
1722
2245
  save(t);
1723
- return cur;
2246
+ return cur2;
1724
2247
  },
1725
2248
  setPerson(id) {
1726
- if (id) cur.p = id;
1727
- else delete cur.p;
2249
+ if (id) cur2.p = id;
2250
+ else delete cur2.p;
1728
2251
  save(clock());
1729
2252
  }
1730
2253
  };
@@ -1732,9 +2255,9 @@ function createSession(store, clock = now, onEnd) {
1732
2255
 
1733
2256
  // src/storage.ts
1734
2257
  init_util();
1735
- function area(kind) {
2258
+ function area(kind2) {
1736
2259
  try {
1737
- const s = kind === "session" ? window.sessionStorage : window.localStorage;
2260
+ const s = kind2 === "session" ? window.sessionStorage : window.localStorage;
1738
2261
  return s || null;
1739
2262
  } catch (e) {
1740
2263
  report("storage", e);
@@ -1745,11 +2268,11 @@ function readCookie(name) {
1745
2268
  const m = document.cookie.match(new RegExp("(?:^|; )" + name + "=([^;]*)"));
1746
2269
  return m ? decodeURIComponent(m[1]) : null;
1747
2270
  }
1748
- function kv(name, kind, cookieDomain, codec) {
2271
+ function kv(name, kind2, cookieDomain, codec) {
1749
2272
  let mem = null;
1750
2273
  let held = false;
1751
2274
  let loaded = false;
1752
- const st = kind === "memory" ? null : area(kind === "cookie" ? "local" : kind);
2275
+ const st = kind2 === "memory" ? null : area(kind2 === "cookie" ? "local" : kind2);
1753
2276
  function write(v) {
1754
2277
  const s = v === null ? null : JSON.stringify(v);
1755
2278
  try {
@@ -1824,7 +2347,7 @@ function createTransport(d) {
1824
2347
  let bytes = 0;
1825
2348
  let dropped = 0;
1826
2349
  let wake = null;
1827
- const busy = {};
2350
+ const busy2 = {};
1828
2351
  const rand = d.random || Math.random;
1829
2352
  const maxBody = d.maxBody || LIMITS.maxBody;
1830
2353
  const halve = (it) => {
@@ -1884,7 +2407,7 @@ function createTransport(d) {
1884
2407
  async function send1(it) {
1885
2408
  const lane = it.b.lane;
1886
2409
  it.flying = true;
1887
- busy[lane] = true;
2410
+ busy2[lane] = true;
1888
2411
  let size = 0;
1889
2412
  let res = { status: 0 };
1890
2413
  try {
@@ -1903,7 +2426,7 @@ function createTransport(d) {
1903
2426
  size = typeof body === "string" ? body.length : body.byteLength;
1904
2427
  if (q.indexOf(it) < 0 || size > maxBody && halve(it)) {
1905
2428
  it.flying = false;
1906
- busy[lane] = false;
2429
+ busy2[lane] = false;
1907
2430
  return;
1908
2431
  }
1909
2432
  it.sent = true;
@@ -1912,20 +2435,20 @@ function createTransport(d) {
1912
2435
  res = { status: 0 };
1913
2436
  }
1914
2437
  it.flying = it.sent = false;
1915
- busy[lane] = false;
2438
+ busy2[lane] = false;
1916
2439
  handle(it, res, size);
1917
2440
  }
1918
2441
  function arm() {
1919
2442
  let next = Infinity;
1920
2443
  for (const it of q) if (!it.flying && it.at < next) next = it.at;
1921
2444
  if (next === Infinity) return;
1922
- const ms = Math.max(0, next - d.now());
2445
+ const ms2 = Math.max(0, next - d.now());
1923
2446
  if (wake !== null && wake <= next) return;
1924
2447
  wake = next;
1925
2448
  d.schedule(() => {
1926
2449
  wake = null;
1927
2450
  void pump();
1928
- }, ms);
2451
+ }, ms2);
1929
2452
  }
1930
2453
  function pump() {
1931
2454
  if (held || stopped || typeof navigator !== "undefined" && navigator.onLine === false) return Promise.resolve();
@@ -1936,7 +2459,7 @@ function createTransport(d) {
1936
2459
  if (it.p) runs.push(it.p);
1937
2460
  continue;
1938
2461
  }
1939
- if (busy[it.b.lane] || it.at > t) continue;
2462
+ if (busy2[it.b.lane] || it.at > t) continue;
1940
2463
  runs.push(it.p = send1(it).then(() => pump()));
1941
2464
  }
1942
2465
  arm();
@@ -2063,6 +2586,7 @@ function createIonBlink(deps) {
2063
2586
  if (debug) console.log("[ionblink]", ...a);
2064
2587
  };
2065
2588
  const full = () => mode === "full" || mode === "replay";
2589
+ const hidden = () => document.visibilityState === "hidden";
2066
2590
  const ingest = (lane) => api + "/v1/batch?k=" + encodeURIComponent(key) + "&lane=" + lane;
2067
2591
  const beacon = (lane, b) => {
2068
2592
  try {
@@ -2146,6 +2670,7 @@ function createIonBlink(deps) {
2146
2670
  const s = st || session.peek();
2147
2671
  while (buf.length) {
2148
2672
  const b = { ...env(s, "events"), events: buf.splice(0, LIMITS.maxEvents) };
2673
+ if (hidden()) b.hidden = true;
2149
2674
  if (ctxDirty) {
2150
2675
  b.context = context();
2151
2676
  ctxDirty = false;
@@ -2176,7 +2701,11 @@ function createIonBlink(deps) {
2176
2701
  return [{ ...b, replay: b.replay.slice(0, mid) }, { ...b, batch: uuid7(), seq, replay: b.replay.slice(mid) }];
2177
2702
  }
2178
2703
  function armE() {
2179
- if (!timerE && buf.length) timerE = setTimeout(guard("flush", () => cutEvents()), flushMs);
2704
+ if (!timerE && buf.length)
2705
+ timerE = setTimeout(guard("flush", () => {
2706
+ cutEvents();
2707
+ hidden() && transport && transport.beaconAll();
2708
+ }), hidden() ? 0 : flushMs);
2180
2709
  }
2181
2710
  function capture(e, p, t = now(), active = true) {
2182
2711
  if (mode === "off") return;
@@ -2197,9 +2726,9 @@ function createIonBlink(deps) {
2197
2726
  if (replay.on) restartReplay();
2198
2727
  }
2199
2728
  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");
2729
+ const kind2 = o.storage === "memory" ? "memory" : o.storage === "cookie" ? "cookie" : "local";
2730
+ sessKV = kv("ib_" + sfx, kind2, o.cookieDomain, kind2 === "cookie" ? sessionCookie : void 0);
2731
+ winKV = kv("ib_w_" + sfx, kind2 === "memory" ? "memory" : "session");
2203
2732
  if (provisional) {
2204
2733
  sessKV.hold(true);
2205
2734
  winKV.hold(true);
@@ -2234,7 +2763,7 @@ function createIonBlink(deps) {
2234
2763
  beacon: (url, body) => !!navigator.sendBeacon && navigator.sendBeacon(url, body),
2235
2764
  gzip: gz ? async (s) => new Uint8Array(await new Response(new Blob([s]).stream().pipeThrough(new CompressionStream("gzip"))).arrayBuffer()) : null,
2236
2765
  now,
2237
- schedule: (fn, ms) => setTimeout(guard("transport", fn), ms),
2766
+ schedule: (fn, ms2) => setTimeout(guard("transport", fn), ms2),
2238
2767
  split,
2239
2768
  onAnswer: (a) => {
2240
2769
  if (typeof a.flush_s === "number" && isFinite(a.flush_s)) {
@@ -2450,8 +2979,8 @@ function createIonBlink(deps) {
2450
2979
  if (x || xLoad || mode === "off") return;
2451
2980
  xLoad = true;
2452
2981
  Promise.resolve().then(() => deps.loadX()).then(
2453
- guard("x.start", (start3) => {
2454
- const h = start3({
2982
+ guard("x.start", (start5) => {
2983
+ const h = start5({
2455
2984
  level,
2456
2985
  capture,
2457
2986
  on: autoOn,
@@ -2527,9 +3056,9 @@ function createIonBlink(deps) {
2527
3056
  }, { passive: true });
2528
3057
  on(d, "visibilitychange", () => {
2529
3058
  const t = now();
2530
- const hidden = d.visibilityState === "hidden";
2531
- fwd("visibilitychange", null, hidden, t);
2532
- if (hidden) {
3059
+ const h = hidden();
3060
+ fwd("visibilitychange", null, h, t);
3061
+ if (h) {
2533
3062
  if (full()) {
2534
3063
  emitSignals(t, false);
2535
3064
  emitVitals();
@@ -2537,7 +3066,7 @@ function createIonBlink(deps) {
2537
3066
  cutReplay();
2538
3067
  transport && transport.beaconAll();
2539
3068
  if (hideTimer) clearTimeout(hideTimer);
2540
- hideTimer = setTimeout(guard("replay.hidden", () => d.visibilityState === "hidden" && stopReplay()), 6e4);
3069
+ hideTimer = setTimeout(guard("replay.hidden", () => hidden() && stopReplay()), 6e4);
2541
3070
  } else sendBasic();
2542
3071
  } else {
2543
3072
  if (hideTimer) clearTimeout(hideTimer);
@@ -2650,7 +3179,7 @@ function createIonBlink(deps) {
2650
3179
  max = isMode(o.mode) ? o.mode : "replay";
2651
3180
  if (o.mask && ORDER.indexOf(o.mask) >= 0) explicitMask = o.mask;
2652
3181
  setReporter(onSdkError);
2653
- hiddenAtStart = document.visibilityState === "hidden";
3182
+ hiddenAtStart = hidden();
2654
3183
  idle(guard("boot", boot), 1e3);
2655
3184
  addEventListener("pagehide", guard("boot.hide", () => {
2656
3185
  if (!waiting) return;
@@ -2688,8 +3217,8 @@ function createIonBlink(deps) {
2688
3217
  const traits = cleanProps(person, false) || {};
2689
3218
  const before = level();
2690
3219
  if (session && typeof traits.id === "string" && traits.id) {
2691
- const cur = session.peek().p;
2692
- if (cur && cur !== traits.id) {
3220
+ const cur2 = session.peek().p;
3221
+ if (cur2 && cur2 !== traits.id) {
2693
3222
  cutEvents();
2694
3223
  session.reset();
2695
3224
  ctxDirty = true;
@@ -2784,6 +3313,6 @@ init_scrub();
2784
3313
  var ionblink = createIonBlink({
2785
3314
  dist: "npm",
2786
3315
  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)
3316
+ loadReplay: () => Promise.resolve().then(() => (init_replay_npm(), replay_npm_exports)).then((m) => m.start)
2788
3317
  });
2789
3318
  var index_default = ionblink;