blocfeed 0.14.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/README.md +39 -0
- package/dist/chunk-CYITSKBK.js +2 -0
- package/dist/chunk-NLL5DECC.cjs +2 -0
- package/dist/{controller-JCtPYbzs.d.cts → controller-6fm9oK63.d.cts} +48 -1
- package/dist/{controller-JCtPYbzs.d.ts → controller-6fm9oK63.d.ts} +48 -1
- package/dist/engine.cjs +1 -1
- package/dist/engine.d.cts +2 -2
- package/dist/engine.d.ts +2 -2
- package/dist/engine.js +1 -1
- package/dist/main.cjs +3 -3
- package/dist/main.d.cts +30 -3
- package/dist/main.d.ts +30 -3
- package/dist/main.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-EZWTVVJ5.cjs +0 -2
- package/dist/chunk-PUVKSWVE.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.15.1 — 2026-04-23
|
|
4
|
+
|
|
5
|
+
### Bug fixes
|
|
6
|
+
|
|
7
|
+
- **Recursive self-reports** — the `httpFail` detector no longer reports failures of `/api/behavioral-events` or `/api/feedback` (the widget's own ingest endpoints). Previously, when an ingest call failed, the detector emitted *another* event describing that failure, which also failed, creating a feedback loop that flooded ingest. Default `httpFail.ignoreUrls` now excludes both endpoints.
|
|
8
|
+
- **`form_selector` fallback** — when a form has no `id`, the HTTP-fail detector now builds a CSS selector via `buildCssSelector()` instead of emitting the literal string `"form"`. Gives usable selectors like `body > main > form.checkout`.
|
|
9
|
+
|
|
10
|
+
### Improvements
|
|
11
|
+
|
|
12
|
+
- **Dev-mode console logging** — in non-production environments (`process.env.NODE_ENV !== "production"`), each behavioral event is logged via `console.debug` as it fires so developers can see detectors working without waiting for dashboard updates. Silent in production.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 0.15.0 — 2026-04-22
|
|
17
|
+
|
|
18
|
+
### New features
|
|
19
|
+
|
|
20
|
+
- **Passive pattern detection** — the widget now automatically detects and reports four common UX failures to the blocfeed dashboard, with no code changes required after upgrade:
|
|
21
|
+
- **Rage-clicks on disabled buttons** — flags `event_data.disabled = true` when the clicked element has `disabled`, `aria-disabled="true"`, or `pointer-events: none`.
|
|
22
|
+
- **Silent HTTP 4xx/5xx form failures** — patches `window.fetch` and `XMLHttpRequest.prototype.open/send` to detect error responses on configured status codes (default: `[400, 401, 403, 422, 500, 502, 503, 504]`). Associates submit-button clicks with failing requests within 1500ms for `form_selector`.
|
|
23
|
+
- **Redirect loops** — detects repeated same-URL navigations via `history.pushState` / `replaceState` / `popstate`. 30s suppression window per URL after firing.
|
|
24
|
+
- **Form data loss** — detects dirty forms restored from bfcache (`pageshow.persisted === true`) or abandoned via `beforeunload` after editing.
|
|
25
|
+
- **`config.behavioral`** — opt-out and tuning. Fields: `enabled`, `sampling` (0..1 per-session), `ignoreSelectors`, plus per-detector `enabled`/`threshold`/`windowMs` overrides and `httpFail.statusCodes` / `httpFail.ignoreUrls`.
|
|
26
|
+
- **`BehavioralTracker` class and types exported** from the package root for advanced integrations and headless usage. New types: `BehavioralEvent`, `BehavioralEventType`, `BehavioralConfig`, `ResolvedBehavioralConfig`.
|
|
27
|
+
|
|
28
|
+
### Privacy
|
|
29
|
+
|
|
30
|
+
- **No request or response bodies** are ever captured. HTTP-fail records URLs, status codes, and method only.
|
|
31
|
+
- **Original globals restored on unmount** — `window.fetch`, `XMLHttpRequest.prototype.open/send`, and `history.pushState` / `replaceState` are all restored to their originals when the tracker uninstalls.
|
|
32
|
+
- **No user identity attached** to behavioral events. Only session-scoped IDs stored in `sessionStorage`.
|
|
33
|
+
- Default `ignoreSelectors` excludes `[data-blocfeed-ui]` and `[data-blocfeed-ignore]` so the widget's own UI never triggers false positives.
|
|
34
|
+
|
|
35
|
+
### Platform changes (blocfeed-frontend)
|
|
36
|
+
|
|
37
|
+
- Widget POSTs batched events to the existing `/api/behavioral-events` endpoint (`{ events: [...] }` body, `x-blocfeed-id` header, or `?_bfid=` query fallback for `sendBeacon`). No schema migration required — events map to the existing `VALID_EVENT_TYPES` vocabulary.
|
|
38
|
+
- Events arrive into `public.behavioral_events`. The existing aggregation + issue-linking pipeline promotes them into `behavioral_signals` and attaches them to `issues`.
|
|
39
|
+
|
|
40
|
+
### Tests
|
|
41
|
+
|
|
42
|
+
- 36 new tests across `tests/behavioral/` (session, submit, four detectors, integration). Full suite now at 116/116 green.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
3
46
|
## 0.14.0 — 2026-04-22
|
|
4
47
|
|
|
5
48
|
### Bug fixes (QA pass)
|
package/README.md
CHANGED
|
@@ -999,6 +999,45 @@ import type {
|
|
|
999
999
|
} from "blocfeed";
|
|
1000
1000
|
```
|
|
1001
1001
|
|
|
1002
|
+
## Passive pattern detection (v0.15.0+)
|
|
1003
|
+
|
|
1004
|
+
The widget now automatically detects and reports four common UX failures —
|
|
1005
|
+
no code changes required after upgrading:
|
|
1006
|
+
|
|
1007
|
+
- **Rage-clicks on disabled buttons** — "I clicked Save five times and nothing happened"
|
|
1008
|
+
- **Silent HTTP form failures** — 4xx/5xx responses to form submits (checkout, upgrade flows)
|
|
1009
|
+
- **Redirect loops** — repeated navigation to the same URL in a short window
|
|
1010
|
+
- **Form data loss** — fields filled in, then lost to a browser back or bfcache restore
|
|
1011
|
+
|
|
1012
|
+
Events ship to the same `/api/behavioral-events` endpoint and surface in the
|
|
1013
|
+
blocfeed dashboard alongside user-reported feedback.
|
|
1014
|
+
|
|
1015
|
+
### Opt out or tune
|
|
1016
|
+
|
|
1017
|
+
```tsx
|
|
1018
|
+
<BlocFeedWidget
|
|
1019
|
+
blocfeed_id="bf_your_project"
|
|
1020
|
+
config={{
|
|
1021
|
+
behavioral: {
|
|
1022
|
+
enabled: true, // default true
|
|
1023
|
+
sampling: 1.0, // 0..1 per-session
|
|
1024
|
+
ignoreSelectors: ["[data-blocfeed-ignore]"],
|
|
1025
|
+
rageClick: { threshold: 3, windowMs: 1000 },
|
|
1026
|
+
httpFail: { statusCodes: [400, 422, 500], ignoreUrls: ["/health"] },
|
|
1027
|
+
redirectLoop:{ threshold: 3, windowMs: 2000 },
|
|
1028
|
+
formDataLoss:{ enabled: true },
|
|
1029
|
+
}
|
|
1030
|
+
}}
|
|
1031
|
+
/>
|
|
1032
|
+
```
|
|
1033
|
+
|
|
1034
|
+
### Privacy
|
|
1035
|
+
|
|
1036
|
+
- **No request or response bodies are captured.** URLs, status codes, and DOM selectors only.
|
|
1037
|
+
- URL is sent as-is — use `httpFail.ignoreUrls` to skip URLs that contain PII in query params.
|
|
1038
|
+
- No user identity is attached to behavioral events.
|
|
1039
|
+
- On widget unmount, `window.fetch`, `XMLHttpRequest`, and `history.pushState` are restored to their originals.
|
|
1040
|
+
|
|
1002
1041
|
## Local development
|
|
1003
1042
|
|
|
1004
1043
|
```bash
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function y(){return typeof window<"u"&&typeof document<"u"}function De(e){let t=globalThis.CSS;return typeof t?.escape=="function"?t.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,n=>{let o=n.codePointAt(0);return o===void 0?"":`\\${o.toString(16)} `})}function pe(e){return {x:e.x,y:e.y,width:e.width,height:e.height}}function Ft(e){return {x:e.x+window.scrollX,y:e.y+window.scrollY,width:e.width,height:e.height}}function Pt(e){return e.replace(/\s+/g," ").trim()}function me(e,t=140){let n=e.textContent;if(!n)return;let o=Pt(n);if(o)return o.length<=t?o:`${o.slice(0,t-1)}\u2026`}function Mt(e){let t=1;for(let n=e.previousElementSibling;n;n=n.previousElementSibling)n.tagName===e.tagName&&(t+=1);return t}var He=["data-testid","data-test-id","data-test","data-qa","data-cy"],Ne="data-blocfeed-component";function ge(e){let t=e.closest(`[${Ne}]`);if(!t)return;let o=t.getAttribute(Ne)?.trim();return o||void 0}function Lt(e){for(let t of He){let n=e.closest(`[${t}]`);if(!n)continue;let r=n.getAttribute(t)?.trim();if(r)return r}}function Oe(e){try{let t=e,n=Object.getOwnPropertyNames(t);for(let o of n)if(o.startsWith("__reactFiber$")||o.startsWith("__reactInternalInstance$")){let r=t[o];if(r&&typeof r=="object")return r}}catch{}return null}function q(e){if(e.length<=1||e.length===2&&e[0]===e[0].toLowerCase()||e.startsWith("__")&&e.endsWith("__"))return true;let t=e[0];return t>="a"&&t<="z"}function K(e){if(e){for(let t of e)if(typeof t.name=="string"&&t.name&&!q(t.name))return t.name}}function F(e){if(e&&typeof e!="string"){if(typeof e=="function"){let t=e;return typeof t.displayName=="string"&&t.displayName?t.displayName:typeof t.name=="string"&&t.name?t.name:void 0}if(typeof e=="object"){let t=e,n=t.displayName;if(typeof n=="string"&&n)return n;let o=t.render;if(typeof o=="function"){let i=o;if(typeof i.displayName=="string"&&i.displayName)return i.displayName;if(typeof i.name=="string"&&i.name)return i.name}let r=t.type;return F(r)}}}function he(e){let t=Oe(e);if(!t)return;let n=K(t._debugInfo);if(n)return n;let o=t._debugOwner!==void 0;if(o){let f=t._debugOwner;for(let s=0;f&&s<50;s+=1){let d=K(f._debugInfo);if(d)return d;let l=F(f.type)??F(f.elementType);if(l&&!q(l))return l;f=f._debugOwner;}}if(t._owner!==void 0&&t._owner!==t._debugOwner){let f=t._owner;for(let s=0;f&&s<50;s+=1){let d=K(f._debugInfo);if(d)return d;let l=F(f.type)??F(f.elementType);if(l&&!q(l))return l;f=f._owner;}}let i=t,c=o?80:25;for(let f=0;i&&f<c;f+=1){let s=K(i._debugInfo);if(s)return s;let d=F(i.type)??F(i.elementType);if(d&&!q(d))return d;i=i.return;}let a=e.parentElement;for(let f=0;a&&f<15;f+=1){let s=Oe(a);if(s){let d=K(s._debugInfo);if(d)return d;let l=F(s.type)??F(s.elementType);if(l&&!q(l))return l;if(s._debugOwner){let p=F(s._debugOwner.type)??F(s._debugOwner.elementType);if(p&&!q(p))return p}if(s._owner&&s._owner!==s._debugOwner){let p=F(s._owner.type)??F(s._owner.elementType);if(p&&!q(p))return p}}a=a.parentElement;}}function Bt(e){let t=e.tagName.toLowerCase(),n=e.getAttribute("id");if(n)return `#${De(n)}`;for(let o of He){let r=e.getAttribute(o);if(r)return `${t}[${o}="${De(r)}"]`}return `${t}:nth-of-type(${Mt(e)})`}function W(e,t=10){let n=[],o=e;for(;o&&n.length<t;){let r=Bt(o);if(n.unshift(r),r.startsWith("#"))break;o=o.parentElement;}return n.join(" > ")}function Ue(e,t){if(!t||t.length===0)return false;for(let n of t)if(e.closest(n))return true;return false}function be(e,t){if(!e||Ue(e,t.ignoreSelectors))return null;let n=e;for(;n;){if(Ue(n,t.ignoreSelectors))return null;if(t.isSelectable?t.isSelectable(n):It(n))return n;n=n.parentElement;}return null}function It(e){let t=e.tagName;return !(t==="HTML"||t==="BODY")}function Ve(e){let t=e.getBoundingClientRect(),n={selector:W(e),tagName:e.tagName.toLowerCase(),rect:pe(t),pageRect:Ft(t)},o=e.getAttribute("id");o&&(n.id=o);let r=e.className;typeof r=="string"&&r.trim()&&(n.className=r);let i=me(e);i&&(n.textSnippet=i);let c=ge(e)??he(e);c&&(n.componentName=c);let a=Lt(e);return a&&(n.testId=a),n}var we=null;async function qe(){return we||(we=import('html-to-image')),we}async function Dt(e){return await new Promise((t,n)=>{let o=new Image;o.onload=()=>t({width:o.naturalWidth,height:o.naturalHeight}),o.onerror=()=>n(new Error("Failed to load generated screenshot")),o.src=e;})}async function Xe(e,t){let{width:n,height:o}=await Dt(e);return {dataUrl:e,mime:t,width:n,height:o}}function $(e){if(e?.aborted)throw new Error("Aborted")}function $e(){return {async captureElement(e,t){if(!y())throw new Error("captureElement can only run in the browser");$(t.signal);let n=await qe();$(t.signal);let o=t.mime==="image/jpeg"?await n.toJpeg(e,{quality:t.quality??.92,pixelRatio:t.pixelRatio}):await n.toPng(e,{pixelRatio:t.pixelRatio});return $(t.signal),await Xe(o,t.mime)},async captureFullPage(e){if(!y())throw new Error("captureFullPage can only run in the browser");$(e.signal);let t=document.documentElement,n=Math.max(t.scrollWidth,t.clientWidth),o=Math.max(t.scrollHeight,t.clientHeight),r=Math.min(1,e.maxDimension/Math.max(n,o)),i=Math.max(1,Math.round(n*r)),c=Math.max(1,Math.round(o*r)),a=await qe();$(e.signal);let f=e.mime==="image/jpeg"?await a.toJpeg(t,{width:i,height:c,quality:e.quality??.92,pixelRatio:e.pixelRatio}):await a.toPng(t,{width:i,height:c,pixelRatio:e.pixelRatio});return $(e.signal),await Xe(f,e.mime)}}}function Nt(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return "Unknown error"}}function w(e,t,n){let o={kind:e,message:Nt(t)};return n&&(o.detail=n),o}var Ot=12e3,Ut=2048,Ht=.92;function ze(){return Date.now()}function Vt(e){return new Promise((t,n)=>{let o=()=>n(new Error("Aborted"));if(e.aborted){o();return}e.addEventListener("abort",o,{once:true});})}async function je(e,t,n){let o=new Promise((i,c)=>{let a=setTimeout(()=>c(new Error("Timeout")),t);typeof a.unref=="function"&&a.unref();}),r=[e,o];return n&&r.push(Vt(n)),await Promise.race(r)}function qt(e){if(!y())return 1;let t=window.devicePixelRatio||1,n=e?.pixelRatio??Math.min(t,2);return Math.max(.1,n)}function Xt(e){return !!(e?.element||e?.fullPage)}function Ke(e){let t={mime:e.mime,pixelRatio:e.pixelRatio,maxDimension:e.maxDimension};return e.includeQuality&&(t.quality=e.quality),e.signal&&(t.signal=e.signal),t}async function We(e){let{selectionElement:t,capture:n,signal:o}=e;if(!y()||!Xt(n))return;let r=ze(),i=[],c=n?.timeoutMs??Ot,a=n?.maxDimension??Ut,f=n?.mime??"image/png",s=n?.quality??Ht,d=n?.adapter??$e(),l={},p=qt(n);if(n?.element&&t)try{let g=t.getBoundingClientRect(),h=Math.min(1,a/Math.max(g.width,g.height)),k=Math.min(p,p*h),v=await je(Promise.resolve(d.captureElement(t,{...Ke({mime:f,quality:s,pixelRatio:k,maxDimension:a,includeQuality:f==="image/jpeg",...o?{signal:o}:{}})})),c,o);l.element=v;}catch(g){if(o?.aborted)throw g;i.push(w("capture_failed",g,{target:"element"}));}if(n?.fullPage)try{let g=await je(Promise.resolve(d.captureFullPage(Ke({mime:f,quality:s,pixelRatio:p,maxDimension:a,includeQuality:f==="image/jpeg",...o?{signal:o}:{}}))),c,o);l.fullPage=g;}catch(g){if(o?.aborted)throw g;i.push(w("capture_failed",g,{target:"fullPage"}));}let m=ze(),u={startedAt:r,finishedAt:m,durationMs:Math.max(0,m-r)};return i.length>0&&(u.errors=i),{...l,diagnostics:u}}function $t(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return}}function zt(){return y()?{url:window.location.href,title:document.title,referrer:document.referrer||void 0,userAgent:navigator.userAgent,language:navigator.language,platform:navigator.platform,viewport:{width:window.innerWidth,height:window.innerHeight},screen:{width:window.screen.width,height:window.screen.height},scroll:{x:window.scrollX,y:window.scrollY},devicePixelRatio:window.devicePixelRatio||1,timezone:$t()}:{}}function jt(e){if(!e)return {};let t={};return e.id&&(t.userId=e.id),e.email&&(t.userEmail=e.email),e.name&&(t.userName=e.name),t}async function Ze(e){let{config:t,context:n,user:o}=e;if(t?.enabled===false)return {};let r={...zt(),...jt(o)},i=t?.enrich;if(!i)return r;try{let c=await i(n);return {...r,...c}}catch(c){let a=w("unknown",c);return {...r,blocfeedMetadataError:a.message}}}var Z="blocfeed-queue",Kt=50;function ve(){if(!y())return [];try{let e=localStorage.getItem(Z);if(!e)return [];let t=JSON.parse(e);if(Array.isArray(t))return t;console.warn("[BlocFeed] offline queue was corrupt (non-array) \u2014 resetting");try{localStorage.removeItem(Z);}catch{}return []}catch(e){console.warn("[BlocFeed] offline queue could not be read \u2014 resetting",e);try{localStorage.removeItem(Z);}catch{}return []}}function ye(e){if(y())try{e.length===0?localStorage.removeItem(Z):localStorage.setItem(Z,JSON.stringify(e));}catch(t){let n=t instanceof DOMException?t.name:"";console.warn(`[BlocFeed] failed to persist offline queue${n?` (${n})`:""} \u2014 feedback may be lost if page is closed`);}}function Wt(e){let t={...e};if(t.screenshots){let n={...t.screenshots};n.element&&(n.element={...n.element,dataUrl:""}),n.fullPage&&(n.fullPage={...n.fullPage,dataUrl:""}),t.screenshots=n;}return delete t.video,t}function Ee(e){let t=ve(),n=Wt(e);for(n.metadata={...n.metadata,_queued:true},t.push({payload:n,timestamp:Date.now()});t.length>Kt;)t.shift();ye(t);}function Ge(){let e=ve();return e.length===0?[]:(ye([]),e.map(t=>t.payload))}function Jn(){ye([]);}function eo(){return ve().length}var Zt=200,G=[],Ye=0,te=false;function Qe(e){let t=e.target;if(!(t instanceof Element)||t.closest("[data-blocfeed-ui]"))return;let n={timestampMs:Date.now()-Ye,path:window.location.pathname,tagName:t.tagName.toLowerCase()},o=me(t,100);o&&(n.textSnippet=o);let r=ge(t)??he(t);r&&(n.componentName=r),G.length<Zt&&G.push(n);}var Je={capture:true,passive:true};function et(){te||!y()||(te=true,G=[],Ye=Date.now(),document.addEventListener("click",Qe,Je));}function tt(){te&&(te=false,document.removeEventListener("click",Qe,Je));}function Gt(){return [...G]}function Yt(){G=[];}var Qt=3e4,Jt=25e5,nt="video/webm",en=250,tn=1e3,nn=["video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm"];function ot(){if(typeof MediaRecorder>"u")return null;for(let e of nn)if(MediaRecorder.isTypeSupported(e))return e;return null}function on(){return !y()||typeof navigator?.mediaDevices?.getDisplayMedia!="function"?false:ot()!==null}async function _e(e){let{config:t,signal:n}=e;if(!y()||typeof navigator?.mediaDevices?.getDisplayMedia!="function")throw w("recording_failed",new Error("Screen recording is not supported in this browser"));let o=ot();if(!o)throw w("recording_failed",new Error("No supported video codec found (WebM required)"));if(n?.aborted)throw w("aborted",new Error("Recording aborted before start"));let r;try{r=await navigator.mediaDevices.getDisplayMedia({video:{displaySurface:"browser"},audio:!1});}catch(h){let k=h instanceof DOMException&&h.name==="NotAllowedError"?"Screen share permission denied":"Failed to start screen share";throw w("recording_failed",new Error(k))}if(n?.aborted)throw r.getTracks().forEach(h=>h.stop()),w("aborted",new Error("Recording aborted after permission"));let i=t?.maxDurationMs??Qt,c=t?.videoBitsPerSecond??Jt,a=new MediaRecorder(r,{mimeType:o,videoBitsPerSecond:c}),f=[],s=[],d=0,l=null,p=null,m=false,u=()=>{tt(),l!==null&&(clearInterval(l),l=null),p!==null&&(clearTimeout(p),p=null),r.getTracks().forEach(h=>h.stop());},g=new Promise((h,k)=>{a.ondataavailable=R=>{R.data.size>0&&f.push(R.data);},a.onstop=()=>{if(m)return;m=true,u();let R=Date.now()-d,P=new Blob(f,{type:nt}),_=URL.createObjectURL(P);h({mime:nt,blobUrl:_,blob:P,durationMs:R,sizeBytes:P.size});},a.onerror=()=>{m||(m=true,u(),k(w("recording_failed",new Error("MediaRecorder error"))));};let v=r.getVideoTracks()[0];if(v&&v.addEventListener("ended",()=>{a.state!=="inactive"&&a.stop();}),n){let R=()=>{m||(m=true,a.state!=="inactive"&&a.stop(),u(),k(w("aborted",new Error("Recording aborted"))));};n.addEventListener("abort",R,{once:true});}});return a.start(tn),et(),d=Date.now(),l=setInterval(()=>{let h=Date.now()-d;for(let k of s)k(h);},en),p=setTimeout(()=>{!m&&a.state!=="inactive"&&a.stop();},i),{result:g,stop(){!m&&a.state!=="inactive"&&a.stop();},onTick(h){s.push(h);},abort(){m||(m=true,a.state!=="inactive"&&a.stop(),u());}}}var rn=6e4,rt="audio/webm",sn=250,an=["audio/webm;codecs=opus","audio/webm","audio/ogg;codecs=opus"];function it(){if(typeof MediaRecorder>"u")return null;for(let e of an)if(MediaRecorder.isTypeSupported(e))return e;return null}function cn(){return !y()||typeof navigator?.mediaDevices?.getUserMedia!="function"?false:it()!==null}async function Se(e){let{config:t,signal:n}=e;if(!y()||typeof navigator?.mediaDevices?.getUserMedia!="function")throw w("recording_failed",new Error("Microphone recording is not supported in this browser"));let o=it();if(!o)throw w("recording_failed",new Error("No supported audio codec found"));if(n?.aborted)throw w("aborted",new Error("Voice recording aborted before start"));let r;try{r=await navigator.mediaDevices.getUserMedia({audio:!0});}catch(g){let h=g instanceof DOMException&&g.name==="NotAllowedError"?"Microphone permission denied":"Failed to access microphone";throw w("recording_failed",new Error(h))}if(n?.aborted)throw r.getTracks().forEach(g=>g.stop()),w("aborted",new Error("Voice recording aborted after permission"));let i=t?.maxDurationMs??rn,c=new MediaRecorder(r,{mimeType:o}),a=[],f=[],s=0,d=null,l=null,p=false,m=()=>{d!==null&&(clearInterval(d),d=null),l!==null&&(clearTimeout(l),l=null),r.getTracks().forEach(g=>g.stop());},u=new Promise((g,h)=>{if(c.ondataavailable=k=>{k.data.size>0&&a.push(k.data);},c.onstop=()=>{if(p)return;p=true,m();let k=Date.now()-s,v=new Blob(a,{type:rt});g({blob:v,mime:rt,durationMs:k});},c.onerror=()=>{p||(p=true,m(),h(w("recording_failed",new Error("MediaRecorder error"))));},n){let k=()=>{p||(p=true,c.state!=="inactive"&&c.stop(),m(),h(w("aborted",new Error("Voice recording aborted"))));};n.addEventListener("abort",k,{once:true});}});return c.start(1e3),s=Date.now(),d=setInterval(()=>{let g=Date.now()-s;for(let h of f)h(g);},sn),l=setTimeout(()=>{l=null,!p&&c.state!=="inactive"&&c.stop();},i),{result:u,stop(){!p&&c.state!=="inactive"&&c.stop();},onTick(g){f.push(g);},abort(){p||(p=true,c.state!=="inactive"&&c.stop(),m());}}}var ln=12e3,dn=2,un=500,fn=2e3,ke="https://blocfeed.com/api/feedback",pn="https://blocfeed.com/api/feedback/voice",st=0,lt="blocfeed-viewer-token",dt="blocfeed-my-feedback-url";function mn(){try{return localStorage.getItem(lt)}catch{return null}}function wo(){try{return localStorage.getItem(dt)}catch{return null}}function gn(e,t){try{localStorage.setItem(lt,e),t&&localStorage.setItem(dt,t);}catch{}}function at(e,t){return new Promise((n,o)=>{if(t?.aborted){o(new Error("Aborted"));return}let r=setTimeout(n,e),i=()=>{clearTimeout(r),o(new Error("Aborted"));};t?.addEventListener("abort",i,{once:true});})}function hn(e){return e>=500&&e<=599}function bn(e){let[t,n]=e.split(",",2);if(!t||!n)throw new Error("Invalid data URL");let r=/data:(.*?);base64/.exec(t)?.[1]||"application/octet-stream",i=atob(n),c=new Uint8Array(i.length);for(let a=0;a<i.length;a+=1)c[a]=i.charCodeAt(a);return new Blob([c],{type:r})}function wn(e){let t={},n={},o={...e};if(o.screenshots){let r={},i={...o.screenshots};i.element&&(t.element=i.element.dataUrl,r.element={mime:i.element.mime,width:i.element.width,height:i.element.height},i.element={...i.element,dataUrl:""}),i.fullPage&&(t.fullPage=i.fullPage.dataUrl,r.fullPage={mime:i.fullPage.mime,width:i.fullPage.width,height:i.fullPage.height},i.fullPage={...i.fullPage,dataUrl:""}),o.screenshots=i,(r.element||r.fullPage)&&(o.screenshot_intent=r);}return o.video&&(n.blob=o.video.blob,o.video_intent={mime:o.video.mime,durationMs:o.video.durationMs,sizeBytes:o.video.sizeBytes},delete o.video),{lean:o,extracted:t,extractedVideo:n}}async function ct(e,t,n){let o=bn(t);await fetch(e,{method:"PUT",body:o,headers:{"content-type":o.type},...n?{signal:n}:{}});}async function vn(e){let{feedbackId:t,extracted:n,screenshots:o,signal:r}=e,i={};n.element&&o?.element&&(i.element={dataUrl:n.element,mime:o.element.mime,width:o.element.width,height:o.element.height}),n.fullPage&&o?.fullPage&&(i.fullPage={dataUrl:n.fullPage,mime:o.fullPage.mime,width:o.fullPage.width,height:o.fullPage.height}),Object.keys(i).length!==0&&await fetch(`${ke}/${t}/screenshots`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(i),...r?{signal:r}:{}});}async function yn(e){await fetch(`${ke}/${e.feedbackId}/video`,{method:"POST",body:e.blob,headers:{"content-type":e.blob.type},...e.signal?{signal:e.signal}:{}});}async function ut(e){let{signal:t,transport:n}=e;if(Date.now()-st<fn)return {ok:false,error:w("configuration",new Error("Please wait before submitting again"))};let r=n?.timeoutMs??ln,i=n?.maxAttempts??dn,c=n?.backoffMs??un,a=!!(e.payload.screenshots?.element?.dataUrl||e.payload.screenshots?.fullPage?.dataUrl),f=!!e.payload.video?.blob,s=a||f,{lean:d,extracted:l,extractedVideo:p}=s?wn(e.payload):{lean:e.payload,extracted:{},extractedVideo:{}},m=mn();m&&(d.viewer_token=m);let u={...l,...e.screenshotDataUrls};for(let g=1;g<=i;g+=1){let h=new AbortController,k=setTimeout(()=>h.abort(),r),v=()=>h.abort();t&&t.addEventListener("abort",v,{once:true});try{let R=await fetch(ke,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(d),signal:h.signal});if(R.ok){st=Date.now();let _;try{_=await R.json();}catch{}if(_?.viewer_token&&gn(_.viewer_token,_.my_feedback_url),(u.element||u.fullPage)&&_){let M=_.upload_urls;if(M){let U=[];u.element&&M.element&&U.push(ct(M.element,u.element,t)),u.fullPage&&M.fullPage&&U.push(ct(M.fullPage,u.fullPage,t));try{await Promise.all(U);}catch{}}else if(_.feedback_id)try{await vn({feedbackId:_.feedback_id,extracted:u,screenshots:e.payload.screenshots,...t?{signal:t}:{}});}catch{}}if(p.blob&&_){let M=_.upload_urls;if(M?.video)try{await fetch(M.video,{method:"PUT",body:p.blob,headers:{"content-type":p.blob.type},...t?{signal:t}:{}});}catch{}else if(_.feedback_id)try{await yn({feedbackId:_.feedback_id,blob:p.blob,...t?{signal:t}:{}});}catch{}}let B={ok:!0,status:R.status};return _&&(B.apiResponse=_),B}if(g<i&&hn(R.status)){let _=.85+Math.random()*.3,ee=Math.round(c*2**(g-1)*_);await at(ee,t);continue}let P=`HTTP ${R.status}`;try{let _=await R.json();_?.error&&(P=_.error);}catch{}return {ok:!1,status:R.status,error:w("api_failed",new Error(P))}}catch(R){if(h.signal.aborted||t?.aborted)return {ok:false,error:w("aborted",R)};if(g<i){let P=.85+Math.random()*.3,_=Math.round(c*2**(g-1)*P);await at(_,t);continue}return {ok:false,error:w("api_failed",R)}}finally{clearTimeout(k),t&&t.removeEventListener("abort",v);}}return {ok:false,error:w("api_failed",new Error("Failed"))}}async function ft(e){let{blob:t,mime:n,blocfeedId:o,signal:r}=e,i=await fetch(pn,{method:"POST",headers:{"Content-Type":n,"X-Blocfeed-Id":o},body:t,...r?{signal:r}:{}});if(!i.ok){let a=await i.json().catch(()=>({error:"Unknown error"}));throw w("api_failed",new Error(a?.error??`Voice API returned ${i.status}`))}let c=await i.json();return {text:c.text??"",warning:c.warning}}var En={enabled:true,sampling:1,ignoreSelectors:["[data-blocfeed-ui]","[data-blocfeed-ignore]"],rageClick:{enabled:true,threshold:3,windowMs:1e3},httpFail:{enabled:true,statusCodes:[400,401,403,422,500,502,503,504],ignoreUrls:["/api/behavioral-events","/api/feedback"]},redirectLoop:{enabled:true,threshold:3,windowMs:2e3},formDataLoss:{enabled:true}};function pt(e){let t=En;return {enabled:e?.enabled??t.enabled,sampling:e?.sampling??t.sampling,ignoreSelectors:e?.ignoreSelectors??t.ignoreSelectors,rageClick:{...t.rageClick,...e?.rageClick??{}},httpFail:{...t.httpFail,...e?.httpFail??{}},redirectLoop:{...t.redirectLoop,...e?.redirectLoop??{}},formDataLoss:{...t.formDataLoss,...e?.formDataLoss??{}}}}function mt(e){let t=[];async function n(){if(t.length===0)return;let r=t.splice(0,50);try{await fetch(e.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-blocfeed-id":e.blocfeedId},body:JSON.stringify({events:r}),keepalive:!0});}catch{}}function o(){if(t.length===0)return;if(typeof navigator>"u"||typeof navigator.sendBeacon!="function"){n();return}let r=t.splice(0,50),i=new Blob([JSON.stringify({events:r})],{type:"application/json"}),c=`${e.endpoint}?_bfid=${encodeURIComponent(e.blocfeedId)}`;try{navigator.sendBeacon(c,i);}catch{}}return {enqueue(r){t.push(r);},flush:n,flushBeacon:o,size(){return t.length}}}var gt="bf_behavioral_session",ne=null;function O(){try{let e=sessionStorage.getItem(gt);if(e)return e;let t=ht();return sessionStorage.setItem(gt,t),t}catch{return ne||(ne=ht(),ne)}}function ht(){let e=Math.random().toString(36).slice(2,10).padEnd(8,"0");return `bf_${Date.now()}_${e}`}function bt(e,t){if(!e.rageClick.enabled)return ()=>{};let{threshold:n,windowMs:o}=e.rageClick,r=new Map;function i(c){try{let a=c.target;if(!a||!(a instanceof Element)||Sn(a,e.ignoreSelectors))return;let f=W(a,4);if(!f)return;let s=Date.now(),l=(r.get(f)??[]).filter(p=>s-p<=o);if(l.push(s),r.set(f,l),l.length>=n){let p=_n(a),m={session_id:O(),event_type:"rage_click",page_url:typeof window>"u"?"":window.location.href,selector:f,event_data:{click_count:l.length,window_ms:o,disabled:p||void 0},created_at:new Date().toISOString()};t(m),r.set(f,[]);}}catch{}}return document.addEventListener("click",i,{capture:true,passive:true}),()=>document.removeEventListener("click",i,{capture:true})}function _n(e){if(e.hasAttribute("disabled")||e.getAttribute("aria-disabled")==="true")return true;try{if(window.getComputedStyle(e).pointerEvents==="none")return !0}catch{}return false}function Sn(e,t){if(t.length===0)return false;for(let n of t)try{if(e.matches(n)||e.closest(n))return !0}catch{}return false}var vt=0,yt=null,kn=1500;function Tn(){function e(t){try{let n=t.target;if(!n)return;let o=n.closest('button[type="submit"], input[type="submit"], [data-blocfeed-submit]');if(!o)return;vt=Date.now();let r=o.closest("form");yt=(r?W(r,3):"")||null;}catch{}}return document.addEventListener("click",e,{capture:true,passive:true}),()=>document.removeEventListener("click",e,{capture:true})}function Et(e,t){if(!e.httpFail.enabled)return ()=>{};let{statusCodes:n,ignoreUrls:o}=e.httpFail,r=new Set(n),i=Tn(),c=globalThis.fetch,a=async(l,p)=>{let m=typeof l=="string"?l:l instanceof URL?l.toString():l.url,u=(p?.method??l.method??"GET").toUpperCase(),g=await c.call(globalThis,l,p);try{!wt(m,o)&&r.has(g.status)&&t(d(g.status,m,u));}catch{}return g};globalThis.fetch=a;let f=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;return XMLHttpRequest.prototype.open=function(l,p,...m){return this.__bf_url=p,this.__bf_method=l.toUpperCase(),f.call(this,l,p,...m)},XMLHttpRequest.prototype.send=function(l){let p=()=>{try{let m=this.__bf_url??"",u=this.__bf_method??"GET";!wt(m,o)&&r.has(this.status)&&t(d(this.status,m,u));}catch{}};return this.__bf_handler=p,this.addEventListener("loadend",p),s.call(this,l??null)},()=>{globalThis.fetch=c,XMLHttpRequest.prototype.open=f,XMLHttpRequest.prototype.send=s,i();};function d(l,p,m){let g=Date.now()-vt<kn;return {session_id:O(),event_type:"error",page_url:typeof window>"u"?"":window.location.href,selector:null,event_data:{http_status:l,request_url:p,method:m,form_selector:g?yt:null},created_at:new Date().toISOString()}}}function wt(e,t){if(t.length===0)return false;for(let n of t)if(e.includes(n))return true;return false}var Rn=3e4;function _t(e,t){if(!e.redirectLoop.enabled)return ()=>{};if(typeof window>"u")return ()=>{};let{threshold:n,windowMs:o}=e.redirectLoop,r=new Map,i=new Map,c=history.pushState,a=history.replaceState;function f(d){try{let l=Date.now(),p=i.get(d)??0;if(l<p)return;let u=(r.get(d)??[]).filter(g=>l-g<=o);if(u.push(l),r.set(d,u),u.length>=n){let g={session_id:O(),event_type:"thrashing",page_url:window.location.href,selector:null,event_data:{count:u.length,url:d,window_ms:o},created_at:new Date().toISOString()};t(g),i.set(d,l+Rn),r.set(d,[]);}}catch{}}function s(){let d=window.location.pathname+window.location.search;f(d);}return history.pushState=function(...d){let l=c.apply(this,d);return s(),l},history.replaceState=function(...d){let l=a.apply(this,d);return s(),l},window.addEventListener("popstate",s),()=>{history.pushState=c,history.replaceState=a,window.removeEventListener("popstate",s);}}function St(e,t){if(!e.formDataLoss.enabled)return ()=>{};if(typeof window>"u")return ()=>{};let n=new Set,o=0;function r(s){let d=s.closest("form");return d?d.id?`#${d.id}`:"form":null}function i(s){try{let d=s.target;if(!d||!(d instanceof HTMLInputElement||d instanceof HTMLTextAreaElement||d instanceof HTMLSelectElement))return;let l=r(d);if(!l)return;n.has(l)||n.add(l),o++;}catch{}}function c(s){if(n.size===0)return;let d=Array.from(n),l={session_id:O(),event_type:"form_abandonment",page_url:window.location.href,selector:d[0]??null,event_data:{cause:s,field_count:o,forms:d},created_at:new Date().toISOString()};t(l);}function a(s){s.persisted&&c("bfcache_restore");}function f(){c("beforeunload_after_edit");}return document.addEventListener("input",i,{capture:true,passive:true}),window.addEventListener("pageshow",a),window.addEventListener("beforeunload",f),()=>{document.removeEventListener("input",i,{capture:true}),window.removeEventListener("pageshow",a),window.removeEventListener("beforeunload",f);}}var Cn=5e3,oe=class{constructor(t){this.submitter=null;this.detectorUninstallers=[];this.flushTimer=null;this.pageHideHandler=null;this.installed=false;this.opts=t,this.resolved=pt(t.config);}install(){if(this.installed||!this.resolved.enabled||!(this.opts.passiveSampler??(()=>Math.random()<this.resolved.sampling))())return;let n=this.opts.endpoint??"https://blocfeed.com/api/behavioral-events";this.submitter=this.opts.submitter??mt({endpoint:n,blocfeedId:this.opts.blocfeedId});let o=r=>{this.submitter?.enqueue(r);};this.detectorUninstallers.push(bt(this.resolved,o)),this.detectorUninstallers.push(Et(this.resolved,o)),this.detectorUninstallers.push(_t(this.resolved,o)),this.detectorUninstallers.push(St(this.resolved,o)),this.flushTimer=setInterval(()=>{this.submitter?.flush();},Cn),this.pageHideHandler=()=>{this.submitter?.flushBeacon();},typeof window<"u"&&window.addEventListener("pagehide",this.pageHideHandler),this.installed=true;}uninstall(){if(this.installed){for(let t of this.detectorUninstallers)try{t();}catch{}this.detectorUninstallers=[],this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.pageHideHandler&&typeof window<"u"&&(window.removeEventListener("pagehide",this.pageHideHandler),this.pageHideHandler=null);try{this.submitter?.flush();}catch{}this.submitter=null,this.installed=false;}}};function Te(e){let t=null,n=null,o=(...r)=>{n=r,t===null&&(t=requestAnimationFrame(()=>{if(t=null,!n)return;let i=n;n=null,e(...i);}));};return o.cancel=()=>{t!==null&&cancelAnimationFrame(t),t=null,n=null;},o}function re(e){return e instanceof Element?!!e.closest("[data-blocfeed-ui]"):false}function ie(e){e.stopPropagation(),e.stopImmediatePropagation?.();}function kt(e,t){if(!y())throw new Error("BlocFeed picker can only run in a browser environment.");let n=e.ignoreSelectors,o=e.isSelectable,r={};n&&n.length>0&&(r.ignoreSelectors=n),o&&(r.isSelectable=o);let i=null,c=null,a=(u,g=false)=>{if(!u){i=null,c=null,t.onHover(null);return}let h=pe(u.getBoundingClientRect()),k=`${Math.round(h.x)}:${Math.round(h.y)}:${Math.round(h.width)}:${Math.round(h.height)}`;!g&&u===i&&k===c||(i=u,c=k,t.onHover({element:u,rect:h}));},f=Te(u=>{if(re(u.target))return;let g=document.elementFromPoint(u.clientX,u.clientY),h=be(g,r);a(h);}),s=Te(()=>{i&&a(i,true);}),d=u=>{re(u.target)||(ie(u),u.pointerType==="mouse"&&u.preventDefault());},l=u=>{re(u.target)||(ie(u),u.pointerType==="mouse"&&u.preventDefault());},p=u=>{if(re(u.target))return;ie(u),u.preventDefault();let g=document.elementFromPoint(u.clientX,u.clientY),h=be(g,r);h&&t.onSelect({element:h,descriptor:Ve(h)});},m=u=>{u.key==="Escape"&&(ie(u),u.preventDefault(),t.onCancel());};return window.addEventListener("pointermove",f,{capture:true,passive:true}),window.addEventListener("pointerdown",d,{capture:true}),window.addEventListener("pointerup",l,{capture:true}),window.addEventListener("click",p,{capture:true}),window.addEventListener("keydown",m,{capture:true}),window.addEventListener("scroll",s,{capture:true,passive:true}),window.addEventListener("resize",s,{passive:true}),{stop(){window.removeEventListener("pointermove",f,{capture:true}),window.removeEventListener("pointerdown",d,{capture:true}),window.removeEventListener("pointerup",l,{capture:true}),window.removeEventListener("click",p,{capture:true}),window.removeEventListener("keydown",m,{capture:true}),window.removeEventListener("scroll",s,{capture:true}),window.removeEventListener("resize",s),f.cancel(),s.cancel(),t.onHover(null);}}}async function Re(e){let{signal:t,transport:n}=e,o={ok:false};try{let r={payload:e.payload,...t?{signal:t}:{},...n?{transport:n}:{}};o.api=await ut(r),o.ok=!!o.api?.ok;}catch(r){o.api={ok:false,error:w("api_failed",r)},o.ok=false;}return {payload:e.payload,result:o}}var An=["[data-blocfeed-ui]","[data-blocfeed-ignore]"];function xn(e){let t=[...An,...e?.ignoreSelectors??[]],n=Array.from(new Set(t));return {...e,ignoreSelectors:n}}function Tt(){return {phase:"idle"}}function Fn(e){if(e.ok)return false;let t=e.api;return t?t.status&&t.status>=400&&t.status<500||t.error?.kind==="aborted"||t.error?.kind==="configuration"?false:!t.ok:true}function ir(e){let t=e,n=new oe({blocfeedId:t.blocfeed_id??"",...t.behavioral!==void 0?{config:t.behavioral}:{}});n.install();let o=Tt(),r=new Set,i=new Set,c=null,a=null,f=null,s=null,d=0,l=null,p=null,m=null,u=null,g=false,h=()=>{for(let b of r)b(o);},k=b=>{for(let E of i)E(b);},v=b=>{o=b,h();},R=()=>{d+=1,s?.abort(),s=null;},P=()=>{c?.stop(),c=null,k(null),f!==null&&y()&&(document.documentElement.style.cursor=f,f=null);},_=()=>{if(m){try{URL.revokeObjectURL(m.blobUrl);}catch{}m=null;}},ee=()=>{p&&(p.abort(),p=null),_();},B=null,M=()=>{u&&(u.abort(),u=null),B&&(B.abort(),B=null);},U=()=>{R(),P(),ee(),M(),a=null,v(Tt());},Le=()=>{if(!y())return;P(),a=null;let b=xn(t.picker);f=document.documentElement.style.cursor,document.documentElement.style.cursor="crosshair",v({phase:"picking"}),c=kt(b,{onHover:k,onSelect:({element:E,descriptor:x})=>{a=E,P(),v({phase:"review",selection:x});},onCancel:()=>{U();}});},Be=()=>{let b=Ge();if(b.length!==0)for(let E of b)Re({payload:E,...t.transport?{transport:t.transport}:{}}).catch(()=>{Ee(E);});};if(y()){setTimeout(Be,1e3);let b=()=>Be();window.addEventListener("online",b),l=()=>window.removeEventListener("online",b);}return {getState:()=>o,getConfig:()=>t,subscribe(b){return r.add(b),()=>r.delete(b)},subscribeHover(b){return i.add(b),()=>i.delete(b)},start(){o.phase==="capturing"||o.phase==="submitting"||o.phase==="recording"||o.phase!=="picking"&&Le();},stop(){U();},clearSelection(){o.phase==="capturing"||o.phase==="submitting"||o.phase==="recording"||Le();},setConfig(b){t=b;},async submit(b,E){if(!y()){let T=w("configuration",new Error("BlocFeed submit can only run in the browser"));return v({phase:"error",lastError:T}),{ok:false}}let x=t.blocfeed_id?.trim?.()??"";if(!x){let L={phase:"error",lastError:w("configuration",new Error("Missing blocfeed_id. Create a project in BlocFeed and pass its blocfeed_id."))};return o.selection&&(L.selection=o.selection),v(L),{ok:false}}if(g)return {ok:false};if(o.phase==="capturing"||o.phase==="submitting"||o.phase==="recording")return {ok:false};g=true;let A=d+1;d=A,s?.abort(),s=new AbortController;let C=s.signal,S=o.selection,I=E?.capture?{...t.capture,...E.capture}:t.capture,H=!!(I?.element||I?.fullPage),z={phase:H?"capturing":"submitting"};S&&(z.selection=S),v(z);try{let T=H?await We({selectionElement:a,capture:I,signal:C}):void 0;if(C.aborted||d!==A)return {ok:!1};let L={phase:"submitting"};S&&(L.selection=S),T&&(L.capture=T),v(L);let D={};S&&(D.selection=S),T&&(D.capture=T);let j=await Ze({config:t.metadata,context:D,...t.user?{user:t.user}:{}}),V={version:1,createdAt:new Date().toISOString(),blocfeed_id:x,message:b,metadata:j};E?.category&&(V.category=E.category),t.user&&(V.user=t.user),S&&(V.selection=S),T&&(V.screenshots=T),m&&(V.video=m);let{result:N}=await Re({payload:V,signal:C,...t.transport?{transport:t.transport}:{}});if(C.aborted||d!==A)return N;if(N.ok){_(),a=null;let fe={phase:"success",lastSubmit:N};return S&&(fe.selection=S),T&&(fe.capture=T),v(fe),N}Fn(N)&&Ee(V);let xt=N.api?.error??w("unknown",new Error("Submission failed")),ue={phase:"error",lastSubmit:N,lastError:xt};return S&&(ue.selection=S),T&&(ue.capture=T),v(ue),N}catch(T){if(C.aborted||d!==A)return {ok:false};let D={phase:"error",lastError:C.aborted?w("aborted",T):w("unknown",T)};return S&&(D.selection=S),v(D),{ok:false}}finally{g=false,d===A&&(s=null);}},async startRecording(){if(o.phase!=="review"||!t.recording?.enabled||u||p)return;let b=o.selection,E={phase:"recording",recordingElapsedMs:0};b&&(E.selection=b),v(E);try{let x={config:t.recording};s&&(x.signal=s.signal);let A=await _e(x);p=A,A.onTick(I=>{if(o.phase==="recording"){let H={phase:"recording",recordingElapsedMs:I};b&&(H.selection=b),v(H);}});let C=await A.result;p=null,m=C;let S={phase:"review",video:C};b&&(S.selection=b),v(S);}catch(x){p=null;let C={phase:"review",lastError:x?.kind?x:w("recording_failed",x)};b&&(C.selection=b),v(C);}},stopRecording(){o.phase!=="recording"||!p||p.stop();},removeVideo(){_();let b=o.selection,E={phase:"review"};b&&(E.selection=b),v(E);},async startVoice(){if(o.phase!=="review"){console.warn("[BlocFeed] startVoice: ignored \u2014 phase is",o.phase,'(expected "review")');return}let b=t.voice;if(!b?.enabled){console.warn("[BlocFeed] startVoice: ignored \u2014 voice is not enabled in config");return}if(p){console.warn("[BlocFeed] startVoice: ignored \u2014 a screen recording is already in progress");return}M();let E=o.selection,x={phase:"review",voiceRecording:true,voiceElapsedMs:0};E&&(x.selection=E),m&&(x.video=m),v(x);try{let A={config:b};s&&(A.signal=s.signal);let C=await Se(A);u=C,C.onTick(D=>{let j={phase:"review",voiceRecording:!0,voiceElapsedMs:D};E&&(j.selection=E),m&&(j.video=m),v(j);});let S=await C.result;u=null;let I={phase:"review",voiceRecording:!1,voiceTranscribing:!0};E&&(I.selection=E),m&&(I.video=m),v(I),B=new AbortController;let H={blob:S.blob,mime:S.mime,blocfeedId:t.blocfeed_id,signal:B.signal},{text:Ie,warning:z}=await ft(H);B=null;let T={phase:"review",voiceRecording:!1,voiceTranscribing:!1};E&&(T.selection=E),m&&(T.video=m),v(T);let L={text:Ie};return z&&(L.warning=z),L}catch(A){M();let C=A?.kind?A:w("recording_failed",A);console.warn("[BlocFeed] Voice error:",C.message);let S={phase:"review",voiceRecording:false,voiceTranscribing:false,lastError:C};E&&(S.selection=E),m&&(S.video=m),v(S);return}},stopVoice(){u&&u.stop();},__unsafeGetSelectedElement(){return a},destroy(){n.uninstall(),U(),r.clear(),i.clear(),l?.(),l=null;}}}var Y=[],Q=[],Rt=20,Ct=15,se=[],At=typeof console<"u"?{log:console.log?.bind(console),warn:console.warn?.bind(console),error:console.error?.bind(console),info:console.info?.bind(console),debug:console.debug?.bind(console)}:{},ae=typeof globalThis<"u"&&typeof globalThis.fetch=="function"?globalThis.fetch:void 0,ce=typeof XMLHttpRequest<"u"?XMLHttpRequest.prototype.open:void 0,le=typeof XMLHttpRequest<"u"?XMLHttpRequest.prototype.send:void 0,Ae=new Set,xe=false,Fe=false,de=false,Pn=["blocfeed.com","google-analytics.com","googletagmanager.com","analytics.google.com","googleads.g.doubleclick.net","googlesyndication.com","googleadservices.com","google.com/pagead","google.com/ads","facebook.net","facebook.com/tr","connect.facebook.net","graph.facebook.com","api.mixpanel.com","api-js.mixpanel.com","api.amplitude.com","api2.amplitude.com","api.segment.io","cdn.segment.com","vars.hotjar.com","in.hotjar.com","script.hotjar.com","heapanalytics.com","fullstory.com/s/fs.js","rs.fullstory.com","app.posthog.com","us.posthog.com","eu.posthog.com","api-iam.intercom.io","widget.intercom.io","sentry.io/api","browser.sentry-cdn.com","browser-intake-datadoghq.com","clarity.ms","js.hs-analytics.net","api.hubapi.com","forms.hubspot.com","plausible.io/api","client.crisp.chat","js.driftt.com","r.logrocket.com","app.pendo.io","events.launchdarkly.com","app.launchdarkly.com","grammarly.com","gnar.grammarly.com","capi.grammarly.com","api.languagetool.org","api.languagetoolplus.com","fonts.googleapis.com","fonts.gstatic.com","cdn.cookielaw.org","consent.cookiebot.com","js.stripe.com","api.stripe.com/v1/tokens","google.com/recaptcha","hcaptcha.com","bam.nr-data.net","rec.smartlook.com","o2.mouseflow.com","api.luckyorange.com","static.zdassets.com","ekr.zdassets.com"];function Mn(e){if(e instanceof Error)return e.name&&e.name!=="Error"?`${e.name}: ${e.message}`:e.message||String(e);if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}function Ln(e,t){let n=t.map(Mn).join(" "),o=t.find(i=>i instanceof Error),r={level:e,message:n.slice(0,2e3),timestamp:Date.now()};for(o?.stack&&(r.stack=o.stack.slice(0,2e3)),Y.push(r);Y.length>Rt;)Y.shift();}function Ce(e){let t=e.url.toLowerCase();for(let n of se)if(t.includes(n))return;for(Q.push(e);Q.length>Ct;)Q.shift();}function cr(e={}){if(de||!y())return;de=true,Rt=e.consoleLimit??20,Ct=e.networkLimit??15;let t=e.ignoreUrls;if(t!==void 0?se=t.map(n=>n.toLowerCase()):se=[...Pn],e.console!==false){let n=e.consoleLevels??["error","warn"];for(let o of n){let r=At[o];r&&(Ae.add(o),console[o]=(...i)=>{Ln(o,i),r.apply(console,i);});}}if(e.network!==false&&ae){let n=ae;xe=true,window.fetch=async function(r,i){let c=typeof r=="string"?r:r instanceof URL?r.toString():r.url,a=(i?.method??"GET").toUpperCase(),f=Date.now();try{let s=await n.call(window,r,i);return s.ok||Ce({url:c.slice(0,500),method:a,status:s.status,statusText:s.statusText,timestamp:f,durationMs:Date.now()-f}),s}catch(s){throw Ce({url:c.slice(0,500),method:a,status:0,statusText:s instanceof Error?s.message:"Network error",timestamp:f,durationMs:Date.now()-f}),s}};}if(e.network!==false&&ce&&le){let n=ce,o=le;Fe=true,XMLHttpRequest.prototype.open=function(r,i,...c){return this.__bf_method=r.toUpperCase(),this.__bf_url=String(i),n.apply(this,[r,i,...c])},XMLHttpRequest.prototype.send=function(...r){let i=this.__bf_method||"GET",c=this.__bf_url||"",a=Date.now();return this.addEventListener("loadend",function(){if(this.status>=400||this.status===0){let f={url:c.slice(0,500),method:i,status:this.status,timestamp:a,durationMs:Date.now()-a};this.statusText&&(f.statusText=this.statusText),Ce(f);}},{once:true}),o.apply(this,r)};}}function lr(){if(de){for(let e of Ae){let t=At[e];t&&(console[e]=t);}Ae.clear(),xe&&ae&&(window.fetch=ae,xe=false),Fe&&ce&&le&&(XMLHttpRequest.prototype.open=ce,XMLHttpRequest.prototype.send=le,Fe=false),se=[],de=false;}}function dr(){return {consoleLogs:[...Y],networkErrors:[...Q]}}function ur(){Y=[],Q=[];}var Bn=[{name:"supabase_service_role_key",pattern:/SUPABASE_SERVICE_ROLE_KEY["'=:\s]{1,8}[A-Za-z0-9_.=-]{30,400}/},{name:"supabase_db_password",pattern:/SUPABASE_DB_PASSWORD["'=:\s]{1,8}[^\s"']{6,200}/},{name:"postgres_password",pattern:/POSTGRES_PASSWORD["'=:\s]{1,8}[^\s"']{6,200}/},{name:"database_url_with_creds",pattern:/(?:postgres|postgresql|mysql|mongodb|redis|amqp):\/\/[^:\s"']{1,100}:[^@\s"']{1,200}@/},{name:"aws_access_key",pattern:/AKIA[0-9A-Z]{16}/},{name:"aws_secret_key",pattern:/AWS_SECRET_ACCESS_KEY["'=:\s]{1,8}[A-Za-z0-9/+=]{30,200}/},{name:"aws_session_token",pattern:/AWS_SESSION_TOKEN["'=:\s]{1,8}[A-Za-z0-9/+=]{30,600}/},{name:"stripe_secret_key",pattern:/sk_live_[a-zA-Z0-9]{10,200}/},{name:"stripe_secret_key_test",pattern:/sk_test_[a-zA-Z0-9]{10,200}/},{name:"stripe_restricted_key",pattern:/rk_(?:live|test)_[a-zA-Z0-9]{10,200}/},{name:"github_pat",pattern:/ghp_[A-Za-z0-9_]{36,100}/},{name:"github_oauth",pattern:/gho_[A-Za-z0-9_]{36,100}/},{name:"github_user_token",pattern:/ghu_[A-Za-z0-9_]{36,100}/},{name:"github_server_token",pattern:/ghs_[A-Za-z0-9_]{36,100}/},{name:"github_fine_grained",pattern:/github_pat_[A-Za-z0-9_]{22,200}/},{name:"openai_api_key",pattern:/sk-[a-zA-Z0-9]{20,200}(?![a-zA-Z0-9_])/},{name:"anthropic_api_key",pattern:/sk-ant-[a-zA-Z0-9\-_]{20,200}/},{name:"private_key",pattern:/-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY-----/},{name:"sendgrid_api_key",pattern:/SG\.[a-zA-Z0-9_-]{22,100}\.[a-zA-Z0-9_-]{22,100}/},{name:"twilio_auth_token",pattern:/TWILIO_AUTH_TOKEN["'=:\s]{1,8}[a-f0-9]{32}/},{name:"generic_secret_key",pattern:/[A-Z_]{2,60}_SECRET_KEY["'=:\s]{1,8}[^\s"']{8,200}/},{name:"generic_secret",pattern:/[A-Z_]{2,60}_SECRET["'=:\s]{1,8}[^\s"']{8,200}/},{name:"generic_password",pattern:/[A-Z_]{2,60}_PASSWORD["'=:\s]{1,8}[^\s"']{6,200}/},{name:"generic_private_key_var",pattern:/[A-Z_]{2,60}_PRIVATE_KEY["'=:\s]{1,8}[^\s"']{8,400}/}],X=[],Me=0,Pe=false;function In(e){let t=e.slice(0,80);return t.length<=6?"***":t.slice(0,6)+"***"}function Dn(e,t,n,o){if(X.some(c=>c.rule===e&&c.source===t))return;let i={rule:e,source:t,hint:In(n),timestamp:Date.now()};o&&(i.location=o),X.push(i);}function J(e,t,n,o){for(let{name:r,pattern:i}of n){let c=i.exec(e);c&&Dn(r,t,c[0],o);}}function Nn(e){try{let t=window;if(t.__NEXT_DATA__){let n=JSON.stringify(t.__NEXT_DATA__);J(n,"hydration",e,"__NEXT_DATA__");}if(t.__NUXT__){let n=JSON.stringify(t.__NUXT__);J(n,"hydration",e,"__NUXT__");}}catch{}}function On(e){try{document.querySelectorAll("script:not([src])").forEach((n,o)=>{let r=n.textContent;r&&r.length>0&&J(r,"scripts",e,`inline-script[${o}]`);});}catch{}}function Un(e){try{document.querySelectorAll("meta[content]").forEach(n=>{let o=n.getAttribute("content"),r=n.getAttribute("name")||n.getAttribute("property")||"";o&&o.length>10&&J(o,"meta",e,r?`meta[${r}]`:void 0);});}catch{}}function Hn(e){try{document.querySelectorAll("[data-api-key], [data-secret], [data-token], [data-password]").forEach(n=>{let o=n.attributes;for(let r=0;r<o.length;r++){let i=o[r];i.name.startsWith("data-")&&i.value.length>10&&J(i.value,"dom",e,`${n.tagName.toLowerCase()}[${i.name}]`);}});}catch{}}function mr(e={}){if(Pe||!y()||(Pe=true,e.secretScan===false))return;let t=[...Bn,...e.customPatterns??[]],n=e.scanTargets??["hydration","scripts","meta","dom"];setTimeout(()=>{Me=Date.now(),n.includes("hydration")&&Nn(t),n.includes("scripts")&&On(t),n.includes("meta")&&Un(t),n.includes("dom")&&Hn(t);let o=e.notify??"both";X.length>0&&(o==="console"||o==="both")&&console.warn(`[BlocFeed Security] Found ${X.length} potential secret(s) exposed in client code:`,X.map(r=>`${r.rule} (${r.source}${r.location?`: ${r.location}`:""})`));},100);}function gr(){return {findings:[...X],scannedAt:Me}}function hr(){X=[],Me=0,Pe=false;}
|
|
2
|
+
export{hr as A,y as a,pe as b,$e as c,We as d,Ze as e,Ee as f,Ge as g,Jn as h,eo as i,Gt as j,Yt as k,on as l,_e as m,cn as n,Se as o,mn as p,wo as q,ft as r,oe as s,ir as t,cr as u,lr as v,dr as w,ur as x,mr as y,gr as z};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';function y(){return typeof window<"u"&&typeof document<"u"}function De(e){let t=globalThis.CSS;return typeof t?.escape=="function"?t.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,n=>{let o=n.codePointAt(0);return o===void 0?"":`\\${o.toString(16)} `})}function pe(e){return {x:e.x,y:e.y,width:e.width,height:e.height}}function Ft(e){return {x:e.x+window.scrollX,y:e.y+window.scrollY,width:e.width,height:e.height}}function Pt(e){return e.replace(/\s+/g," ").trim()}function me(e,t=140){let n=e.textContent;if(!n)return;let o=Pt(n);if(o)return o.length<=t?o:`${o.slice(0,t-1)}\u2026`}function Mt(e){let t=1;for(let n=e.previousElementSibling;n;n=n.previousElementSibling)n.tagName===e.tagName&&(t+=1);return t}var He=["data-testid","data-test-id","data-test","data-qa","data-cy"],Ne="data-blocfeed-component";function ge(e){let t=e.closest(`[${Ne}]`);if(!t)return;let o=t.getAttribute(Ne)?.trim();return o||void 0}function Lt(e){for(let t of He){let n=e.closest(`[${t}]`);if(!n)continue;let r=n.getAttribute(t)?.trim();if(r)return r}}function Oe(e){try{let t=e,n=Object.getOwnPropertyNames(t);for(let o of n)if(o.startsWith("__reactFiber$")||o.startsWith("__reactInternalInstance$")){let r=t[o];if(r&&typeof r=="object")return r}}catch{}return null}function q(e){if(e.length<=1||e.length===2&&e[0]===e[0].toLowerCase()||e.startsWith("__")&&e.endsWith("__"))return true;let t=e[0];return t>="a"&&t<="z"}function K(e){if(e){for(let t of e)if(typeof t.name=="string"&&t.name&&!q(t.name))return t.name}}function F(e){if(e&&typeof e!="string"){if(typeof e=="function"){let t=e;return typeof t.displayName=="string"&&t.displayName?t.displayName:typeof t.name=="string"&&t.name?t.name:void 0}if(typeof e=="object"){let t=e,n=t.displayName;if(typeof n=="string"&&n)return n;let o=t.render;if(typeof o=="function"){let i=o;if(typeof i.displayName=="string"&&i.displayName)return i.displayName;if(typeof i.name=="string"&&i.name)return i.name}let r=t.type;return F(r)}}}function he(e){let t=Oe(e);if(!t)return;let n=K(t._debugInfo);if(n)return n;let o=t._debugOwner!==void 0;if(o){let f=t._debugOwner;for(let s=0;f&&s<50;s+=1){let d=K(f._debugInfo);if(d)return d;let l=F(f.type)??F(f.elementType);if(l&&!q(l))return l;f=f._debugOwner;}}if(t._owner!==void 0&&t._owner!==t._debugOwner){let f=t._owner;for(let s=0;f&&s<50;s+=1){let d=K(f._debugInfo);if(d)return d;let l=F(f.type)??F(f.elementType);if(l&&!q(l))return l;f=f._owner;}}let i=t,c=o?80:25;for(let f=0;i&&f<c;f+=1){let s=K(i._debugInfo);if(s)return s;let d=F(i.type)??F(i.elementType);if(d&&!q(d))return d;i=i.return;}let a=e.parentElement;for(let f=0;a&&f<15;f+=1){let s=Oe(a);if(s){let d=K(s._debugInfo);if(d)return d;let l=F(s.type)??F(s.elementType);if(l&&!q(l))return l;if(s._debugOwner){let p=F(s._debugOwner.type)??F(s._debugOwner.elementType);if(p&&!q(p))return p}if(s._owner&&s._owner!==s._debugOwner){let p=F(s._owner.type)??F(s._owner.elementType);if(p&&!q(p))return p}}a=a.parentElement;}}function Bt(e){let t=e.tagName.toLowerCase(),n=e.getAttribute("id");if(n)return `#${De(n)}`;for(let o of He){let r=e.getAttribute(o);if(r)return `${t}[${o}="${De(r)}"]`}return `${t}:nth-of-type(${Mt(e)})`}function W(e,t=10){let n=[],o=e;for(;o&&n.length<t;){let r=Bt(o);if(n.unshift(r),r.startsWith("#"))break;o=o.parentElement;}return n.join(" > ")}function Ue(e,t){if(!t||t.length===0)return false;for(let n of t)if(e.closest(n))return true;return false}function be(e,t){if(!e||Ue(e,t.ignoreSelectors))return null;let n=e;for(;n;){if(Ue(n,t.ignoreSelectors))return null;if(t.isSelectable?t.isSelectable(n):It(n))return n;n=n.parentElement;}return null}function It(e){let t=e.tagName;return !(t==="HTML"||t==="BODY")}function Ve(e){let t=e.getBoundingClientRect(),n={selector:W(e),tagName:e.tagName.toLowerCase(),rect:pe(t),pageRect:Ft(t)},o=e.getAttribute("id");o&&(n.id=o);let r=e.className;typeof r=="string"&&r.trim()&&(n.className=r);let i=me(e);i&&(n.textSnippet=i);let c=ge(e)??he(e);c&&(n.componentName=c);let a=Lt(e);return a&&(n.testId=a),n}var we=null;async function qe(){return we||(we=import('html-to-image')),we}async function Dt(e){return await new Promise((t,n)=>{let o=new Image;o.onload=()=>t({width:o.naturalWidth,height:o.naturalHeight}),o.onerror=()=>n(new Error("Failed to load generated screenshot")),o.src=e;})}async function Xe(e,t){let{width:n,height:o}=await Dt(e);return {dataUrl:e,mime:t,width:n,height:o}}function $(e){if(e?.aborted)throw new Error("Aborted")}function $e(){return {async captureElement(e,t){if(!y())throw new Error("captureElement can only run in the browser");$(t.signal);let n=await qe();$(t.signal);let o=t.mime==="image/jpeg"?await n.toJpeg(e,{quality:t.quality??.92,pixelRatio:t.pixelRatio}):await n.toPng(e,{pixelRatio:t.pixelRatio});return $(t.signal),await Xe(o,t.mime)},async captureFullPage(e){if(!y())throw new Error("captureFullPage can only run in the browser");$(e.signal);let t=document.documentElement,n=Math.max(t.scrollWidth,t.clientWidth),o=Math.max(t.scrollHeight,t.clientHeight),r=Math.min(1,e.maxDimension/Math.max(n,o)),i=Math.max(1,Math.round(n*r)),c=Math.max(1,Math.round(o*r)),a=await qe();$(e.signal);let f=e.mime==="image/jpeg"?await a.toJpeg(t,{width:i,height:c,quality:e.quality??.92,pixelRatio:e.pixelRatio}):await a.toPng(t,{width:i,height:c,pixelRatio:e.pixelRatio});return $(e.signal),await Xe(f,e.mime)}}}function Nt(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return "Unknown error"}}function w(e,t,n){let o={kind:e,message:Nt(t)};return n&&(o.detail=n),o}var Ot=12e3,Ut=2048,Ht=.92;function ze(){return Date.now()}function Vt(e){return new Promise((t,n)=>{let o=()=>n(new Error("Aborted"));if(e.aborted){o();return}e.addEventListener("abort",o,{once:true});})}async function je(e,t,n){let o=new Promise((i,c)=>{let a=setTimeout(()=>c(new Error("Timeout")),t);typeof a.unref=="function"&&a.unref();}),r=[e,o];return n&&r.push(Vt(n)),await Promise.race(r)}function qt(e){if(!y())return 1;let t=window.devicePixelRatio||1,n=e?.pixelRatio??Math.min(t,2);return Math.max(.1,n)}function Xt(e){return !!(e?.element||e?.fullPage)}function Ke(e){let t={mime:e.mime,pixelRatio:e.pixelRatio,maxDimension:e.maxDimension};return e.includeQuality&&(t.quality=e.quality),e.signal&&(t.signal=e.signal),t}async function We(e){let{selectionElement:t,capture:n,signal:o}=e;if(!y()||!Xt(n))return;let r=ze(),i=[],c=n?.timeoutMs??Ot,a=n?.maxDimension??Ut,f=n?.mime??"image/png",s=n?.quality??Ht,d=n?.adapter??$e(),l={},p=qt(n);if(n?.element&&t)try{let g=t.getBoundingClientRect(),h=Math.min(1,a/Math.max(g.width,g.height)),k=Math.min(p,p*h),v=await je(Promise.resolve(d.captureElement(t,{...Ke({mime:f,quality:s,pixelRatio:k,maxDimension:a,includeQuality:f==="image/jpeg",...o?{signal:o}:{}})})),c,o);l.element=v;}catch(g){if(o?.aborted)throw g;i.push(w("capture_failed",g,{target:"element"}));}if(n?.fullPage)try{let g=await je(Promise.resolve(d.captureFullPage(Ke({mime:f,quality:s,pixelRatio:p,maxDimension:a,includeQuality:f==="image/jpeg",...o?{signal:o}:{}}))),c,o);l.fullPage=g;}catch(g){if(o?.aborted)throw g;i.push(w("capture_failed",g,{target:"fullPage"}));}let m=ze(),u={startedAt:r,finishedAt:m,durationMs:Math.max(0,m-r)};return i.length>0&&(u.errors=i),{...l,diagnostics:u}}function $t(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return}}function zt(){return y()?{url:window.location.href,title:document.title,referrer:document.referrer||void 0,userAgent:navigator.userAgent,language:navigator.language,platform:navigator.platform,viewport:{width:window.innerWidth,height:window.innerHeight},screen:{width:window.screen.width,height:window.screen.height},scroll:{x:window.scrollX,y:window.scrollY},devicePixelRatio:window.devicePixelRatio||1,timezone:$t()}:{}}function jt(e){if(!e)return {};let t={};return e.id&&(t.userId=e.id),e.email&&(t.userEmail=e.email),e.name&&(t.userName=e.name),t}async function Ze(e){let{config:t,context:n,user:o}=e;if(t?.enabled===false)return {};let r={...zt(),...jt(o)},i=t?.enrich;if(!i)return r;try{let c=await i(n);return {...r,...c}}catch(c){let a=w("unknown",c);return {...r,blocfeedMetadataError:a.message}}}var Z="blocfeed-queue",Kt=50;function ve(){if(!y())return [];try{let e=localStorage.getItem(Z);if(!e)return [];let t=JSON.parse(e);if(Array.isArray(t))return t;console.warn("[BlocFeed] offline queue was corrupt (non-array) \u2014 resetting");try{localStorage.removeItem(Z);}catch{}return []}catch(e){console.warn("[BlocFeed] offline queue could not be read \u2014 resetting",e);try{localStorage.removeItem(Z);}catch{}return []}}function ye(e){if(y())try{e.length===0?localStorage.removeItem(Z):localStorage.setItem(Z,JSON.stringify(e));}catch(t){let n=t instanceof DOMException?t.name:"";console.warn(`[BlocFeed] failed to persist offline queue${n?` (${n})`:""} \u2014 feedback may be lost if page is closed`);}}function Wt(e){let t={...e};if(t.screenshots){let n={...t.screenshots};n.element&&(n.element={...n.element,dataUrl:""}),n.fullPage&&(n.fullPage={...n.fullPage,dataUrl:""}),t.screenshots=n;}return delete t.video,t}function Ee(e){let t=ve(),n=Wt(e);for(n.metadata={...n.metadata,_queued:true},t.push({payload:n,timestamp:Date.now()});t.length>Kt;)t.shift();ye(t);}function Ge(){let e=ve();return e.length===0?[]:(ye([]),e.map(t=>t.payload))}function Jn(){ye([]);}function eo(){return ve().length}var Zt=200,G=[],Ye=0,te=false;function Qe(e){let t=e.target;if(!(t instanceof Element)||t.closest("[data-blocfeed-ui]"))return;let n={timestampMs:Date.now()-Ye,path:window.location.pathname,tagName:t.tagName.toLowerCase()},o=me(t,100);o&&(n.textSnippet=o);let r=ge(t)??he(t);r&&(n.componentName=r),G.length<Zt&&G.push(n);}var Je={capture:true,passive:true};function et(){te||!y()||(te=true,G=[],Ye=Date.now(),document.addEventListener("click",Qe,Je));}function tt(){te&&(te=false,document.removeEventListener("click",Qe,Je));}function Gt(){return [...G]}function Yt(){G=[];}var Qt=3e4,Jt=25e5,nt="video/webm",en=250,tn=1e3,nn=["video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm"];function ot(){if(typeof MediaRecorder>"u")return null;for(let e of nn)if(MediaRecorder.isTypeSupported(e))return e;return null}function on(){return !y()||typeof navigator?.mediaDevices?.getDisplayMedia!="function"?false:ot()!==null}async function _e(e){let{config:t,signal:n}=e;if(!y()||typeof navigator?.mediaDevices?.getDisplayMedia!="function")throw w("recording_failed",new Error("Screen recording is not supported in this browser"));let o=ot();if(!o)throw w("recording_failed",new Error("No supported video codec found (WebM required)"));if(n?.aborted)throw w("aborted",new Error("Recording aborted before start"));let r;try{r=await navigator.mediaDevices.getDisplayMedia({video:{displaySurface:"browser"},audio:!1});}catch(h){let k=h instanceof DOMException&&h.name==="NotAllowedError"?"Screen share permission denied":"Failed to start screen share";throw w("recording_failed",new Error(k))}if(n?.aborted)throw r.getTracks().forEach(h=>h.stop()),w("aborted",new Error("Recording aborted after permission"));let i=t?.maxDurationMs??Qt,c=t?.videoBitsPerSecond??Jt,a=new MediaRecorder(r,{mimeType:o,videoBitsPerSecond:c}),f=[],s=[],d=0,l=null,p=null,m=false,u=()=>{tt(),l!==null&&(clearInterval(l),l=null),p!==null&&(clearTimeout(p),p=null),r.getTracks().forEach(h=>h.stop());},g=new Promise((h,k)=>{a.ondataavailable=R=>{R.data.size>0&&f.push(R.data);},a.onstop=()=>{if(m)return;m=true,u();let R=Date.now()-d,P=new Blob(f,{type:nt}),_=URL.createObjectURL(P);h({mime:nt,blobUrl:_,blob:P,durationMs:R,sizeBytes:P.size});},a.onerror=()=>{m||(m=true,u(),k(w("recording_failed",new Error("MediaRecorder error"))));};let v=r.getVideoTracks()[0];if(v&&v.addEventListener("ended",()=>{a.state!=="inactive"&&a.stop();}),n){let R=()=>{m||(m=true,a.state!=="inactive"&&a.stop(),u(),k(w("aborted",new Error("Recording aborted"))));};n.addEventListener("abort",R,{once:true});}});return a.start(tn),et(),d=Date.now(),l=setInterval(()=>{let h=Date.now()-d;for(let k of s)k(h);},en),p=setTimeout(()=>{!m&&a.state!=="inactive"&&a.stop();},i),{result:g,stop(){!m&&a.state!=="inactive"&&a.stop();},onTick(h){s.push(h);},abort(){m||(m=true,a.state!=="inactive"&&a.stop(),u());}}}var rn=6e4,rt="audio/webm",sn=250,an=["audio/webm;codecs=opus","audio/webm","audio/ogg;codecs=opus"];function it(){if(typeof MediaRecorder>"u")return null;for(let e of an)if(MediaRecorder.isTypeSupported(e))return e;return null}function cn(){return !y()||typeof navigator?.mediaDevices?.getUserMedia!="function"?false:it()!==null}async function Se(e){let{config:t,signal:n}=e;if(!y()||typeof navigator?.mediaDevices?.getUserMedia!="function")throw w("recording_failed",new Error("Microphone recording is not supported in this browser"));let o=it();if(!o)throw w("recording_failed",new Error("No supported audio codec found"));if(n?.aborted)throw w("aborted",new Error("Voice recording aborted before start"));let r;try{r=await navigator.mediaDevices.getUserMedia({audio:!0});}catch(g){let h=g instanceof DOMException&&g.name==="NotAllowedError"?"Microphone permission denied":"Failed to access microphone";throw w("recording_failed",new Error(h))}if(n?.aborted)throw r.getTracks().forEach(g=>g.stop()),w("aborted",new Error("Voice recording aborted after permission"));let i=t?.maxDurationMs??rn,c=new MediaRecorder(r,{mimeType:o}),a=[],f=[],s=0,d=null,l=null,p=false,m=()=>{d!==null&&(clearInterval(d),d=null),l!==null&&(clearTimeout(l),l=null),r.getTracks().forEach(g=>g.stop());},u=new Promise((g,h)=>{if(c.ondataavailable=k=>{k.data.size>0&&a.push(k.data);},c.onstop=()=>{if(p)return;p=true,m();let k=Date.now()-s,v=new Blob(a,{type:rt});g({blob:v,mime:rt,durationMs:k});},c.onerror=()=>{p||(p=true,m(),h(w("recording_failed",new Error("MediaRecorder error"))));},n){let k=()=>{p||(p=true,c.state!=="inactive"&&c.stop(),m(),h(w("aborted",new Error("Voice recording aborted"))));};n.addEventListener("abort",k,{once:true});}});return c.start(1e3),s=Date.now(),d=setInterval(()=>{let g=Date.now()-s;for(let h of f)h(g);},sn),l=setTimeout(()=>{l=null,!p&&c.state!=="inactive"&&c.stop();},i),{result:u,stop(){!p&&c.state!=="inactive"&&c.stop();},onTick(g){f.push(g);},abort(){p||(p=true,c.state!=="inactive"&&c.stop(),m());}}}var ln=12e3,dn=2,un=500,fn=2e3,ke="https://blocfeed.com/api/feedback",pn="https://blocfeed.com/api/feedback/voice",st=0,lt="blocfeed-viewer-token",dt="blocfeed-my-feedback-url";function mn(){try{return localStorage.getItem(lt)}catch{return null}}function wo(){try{return localStorage.getItem(dt)}catch{return null}}function gn(e,t){try{localStorage.setItem(lt,e),t&&localStorage.setItem(dt,t);}catch{}}function at(e,t){return new Promise((n,o)=>{if(t?.aborted){o(new Error("Aborted"));return}let r=setTimeout(n,e),i=()=>{clearTimeout(r),o(new Error("Aborted"));};t?.addEventListener("abort",i,{once:true});})}function hn(e){return e>=500&&e<=599}function bn(e){let[t,n]=e.split(",",2);if(!t||!n)throw new Error("Invalid data URL");let r=/data:(.*?);base64/.exec(t)?.[1]||"application/octet-stream",i=atob(n),c=new Uint8Array(i.length);for(let a=0;a<i.length;a+=1)c[a]=i.charCodeAt(a);return new Blob([c],{type:r})}function wn(e){let t={},n={},o={...e};if(o.screenshots){let r={},i={...o.screenshots};i.element&&(t.element=i.element.dataUrl,r.element={mime:i.element.mime,width:i.element.width,height:i.element.height},i.element={...i.element,dataUrl:""}),i.fullPage&&(t.fullPage=i.fullPage.dataUrl,r.fullPage={mime:i.fullPage.mime,width:i.fullPage.width,height:i.fullPage.height},i.fullPage={...i.fullPage,dataUrl:""}),o.screenshots=i,(r.element||r.fullPage)&&(o.screenshot_intent=r);}return o.video&&(n.blob=o.video.blob,o.video_intent={mime:o.video.mime,durationMs:o.video.durationMs,sizeBytes:o.video.sizeBytes},delete o.video),{lean:o,extracted:t,extractedVideo:n}}async function ct(e,t,n){let o=bn(t);await fetch(e,{method:"PUT",body:o,headers:{"content-type":o.type},...n?{signal:n}:{}});}async function vn(e){let{feedbackId:t,extracted:n,screenshots:o,signal:r}=e,i={};n.element&&o?.element&&(i.element={dataUrl:n.element,mime:o.element.mime,width:o.element.width,height:o.element.height}),n.fullPage&&o?.fullPage&&(i.fullPage={dataUrl:n.fullPage,mime:o.fullPage.mime,width:o.fullPage.width,height:o.fullPage.height}),Object.keys(i).length!==0&&await fetch(`${ke}/${t}/screenshots`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(i),...r?{signal:r}:{}});}async function yn(e){await fetch(`${ke}/${e.feedbackId}/video`,{method:"POST",body:e.blob,headers:{"content-type":e.blob.type},...e.signal?{signal:e.signal}:{}});}async function ut(e){let{signal:t,transport:n}=e;if(Date.now()-st<fn)return {ok:false,error:w("configuration",new Error("Please wait before submitting again"))};let r=n?.timeoutMs??ln,i=n?.maxAttempts??dn,c=n?.backoffMs??un,a=!!(e.payload.screenshots?.element?.dataUrl||e.payload.screenshots?.fullPage?.dataUrl),f=!!e.payload.video?.blob,s=a||f,{lean:d,extracted:l,extractedVideo:p}=s?wn(e.payload):{lean:e.payload,extracted:{},extractedVideo:{}},m=mn();m&&(d.viewer_token=m);let u={...l,...e.screenshotDataUrls};for(let g=1;g<=i;g+=1){let h=new AbortController,k=setTimeout(()=>h.abort(),r),v=()=>h.abort();t&&t.addEventListener("abort",v,{once:true});try{let R=await fetch(ke,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(d),signal:h.signal});if(R.ok){st=Date.now();let _;try{_=await R.json();}catch{}if(_?.viewer_token&&gn(_.viewer_token,_.my_feedback_url),(u.element||u.fullPage)&&_){let M=_.upload_urls;if(M){let U=[];u.element&&M.element&&U.push(ct(M.element,u.element,t)),u.fullPage&&M.fullPage&&U.push(ct(M.fullPage,u.fullPage,t));try{await Promise.all(U);}catch{}}else if(_.feedback_id)try{await vn({feedbackId:_.feedback_id,extracted:u,screenshots:e.payload.screenshots,...t?{signal:t}:{}});}catch{}}if(p.blob&&_){let M=_.upload_urls;if(M?.video)try{await fetch(M.video,{method:"PUT",body:p.blob,headers:{"content-type":p.blob.type},...t?{signal:t}:{}});}catch{}else if(_.feedback_id)try{await yn({feedbackId:_.feedback_id,blob:p.blob,...t?{signal:t}:{}});}catch{}}let B={ok:!0,status:R.status};return _&&(B.apiResponse=_),B}if(g<i&&hn(R.status)){let _=.85+Math.random()*.3,ee=Math.round(c*2**(g-1)*_);await at(ee,t);continue}let P=`HTTP ${R.status}`;try{let _=await R.json();_?.error&&(P=_.error);}catch{}return {ok:!1,status:R.status,error:w("api_failed",new Error(P))}}catch(R){if(h.signal.aborted||t?.aborted)return {ok:false,error:w("aborted",R)};if(g<i){let P=.85+Math.random()*.3,_=Math.round(c*2**(g-1)*P);await at(_,t);continue}return {ok:false,error:w("api_failed",R)}}finally{clearTimeout(k),t&&t.removeEventListener("abort",v);}}return {ok:false,error:w("api_failed",new Error("Failed"))}}async function ft(e){let{blob:t,mime:n,blocfeedId:o,signal:r}=e,i=await fetch(pn,{method:"POST",headers:{"Content-Type":n,"X-Blocfeed-Id":o},body:t,...r?{signal:r}:{}});if(!i.ok){let a=await i.json().catch(()=>({error:"Unknown error"}));throw w("api_failed",new Error(a?.error??`Voice API returned ${i.status}`))}let c=await i.json();return {text:c.text??"",warning:c.warning}}var En={enabled:true,sampling:1,ignoreSelectors:["[data-blocfeed-ui]","[data-blocfeed-ignore]"],rageClick:{enabled:true,threshold:3,windowMs:1e3},httpFail:{enabled:true,statusCodes:[400,401,403,422,500,502,503,504],ignoreUrls:["/api/behavioral-events","/api/feedback"]},redirectLoop:{enabled:true,threshold:3,windowMs:2e3},formDataLoss:{enabled:true}};function pt(e){let t=En;return {enabled:e?.enabled??t.enabled,sampling:e?.sampling??t.sampling,ignoreSelectors:e?.ignoreSelectors??t.ignoreSelectors,rageClick:{...t.rageClick,...e?.rageClick??{}},httpFail:{...t.httpFail,...e?.httpFail??{}},redirectLoop:{...t.redirectLoop,...e?.redirectLoop??{}},formDataLoss:{...t.formDataLoss,...e?.formDataLoss??{}}}}function mt(e){let t=[];async function n(){if(t.length===0)return;let r=t.splice(0,50);try{await fetch(e.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-blocfeed-id":e.blocfeedId},body:JSON.stringify({events:r}),keepalive:!0});}catch{}}function o(){if(t.length===0)return;if(typeof navigator>"u"||typeof navigator.sendBeacon!="function"){n();return}let r=t.splice(0,50),i=new Blob([JSON.stringify({events:r})],{type:"application/json"}),c=`${e.endpoint}?_bfid=${encodeURIComponent(e.blocfeedId)}`;try{navigator.sendBeacon(c,i);}catch{}}return {enqueue(r){t.push(r);},flush:n,flushBeacon:o,size(){return t.length}}}var gt="bf_behavioral_session",ne=null;function O(){try{let e=sessionStorage.getItem(gt);if(e)return e;let t=ht();return sessionStorage.setItem(gt,t),t}catch{return ne||(ne=ht(),ne)}}function ht(){let e=Math.random().toString(36).slice(2,10).padEnd(8,"0");return `bf_${Date.now()}_${e}`}function bt(e,t){if(!e.rageClick.enabled)return ()=>{};let{threshold:n,windowMs:o}=e.rageClick,r=new Map;function i(c){try{let a=c.target;if(!a||!(a instanceof Element)||Sn(a,e.ignoreSelectors))return;let f=W(a,4);if(!f)return;let s=Date.now(),l=(r.get(f)??[]).filter(p=>s-p<=o);if(l.push(s),r.set(f,l),l.length>=n){let p=_n(a),m={session_id:O(),event_type:"rage_click",page_url:typeof window>"u"?"":window.location.href,selector:f,event_data:{click_count:l.length,window_ms:o,disabled:p||void 0},created_at:new Date().toISOString()};t(m),r.set(f,[]);}}catch{}}return document.addEventListener("click",i,{capture:true,passive:true}),()=>document.removeEventListener("click",i,{capture:true})}function _n(e){if(e.hasAttribute("disabled")||e.getAttribute("aria-disabled")==="true")return true;try{if(window.getComputedStyle(e).pointerEvents==="none")return !0}catch{}return false}function Sn(e,t){if(t.length===0)return false;for(let n of t)try{if(e.matches(n)||e.closest(n))return !0}catch{}return false}var vt=0,yt=null,kn=1500;function Tn(){function e(t){try{let n=t.target;if(!n)return;let o=n.closest('button[type="submit"], input[type="submit"], [data-blocfeed-submit]');if(!o)return;vt=Date.now();let r=o.closest("form");yt=(r?W(r,3):"")||null;}catch{}}return document.addEventListener("click",e,{capture:true,passive:true}),()=>document.removeEventListener("click",e,{capture:true})}function Et(e,t){if(!e.httpFail.enabled)return ()=>{};let{statusCodes:n,ignoreUrls:o}=e.httpFail,r=new Set(n),i=Tn(),c=globalThis.fetch,a=async(l,p)=>{let m=typeof l=="string"?l:l instanceof URL?l.toString():l.url,u=(p?.method??l.method??"GET").toUpperCase(),g=await c.call(globalThis,l,p);try{!wt(m,o)&&r.has(g.status)&&t(d(g.status,m,u));}catch{}return g};globalThis.fetch=a;let f=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;return XMLHttpRequest.prototype.open=function(l,p,...m){return this.__bf_url=p,this.__bf_method=l.toUpperCase(),f.call(this,l,p,...m)},XMLHttpRequest.prototype.send=function(l){let p=()=>{try{let m=this.__bf_url??"",u=this.__bf_method??"GET";!wt(m,o)&&r.has(this.status)&&t(d(this.status,m,u));}catch{}};return this.__bf_handler=p,this.addEventListener("loadend",p),s.call(this,l??null)},()=>{globalThis.fetch=c,XMLHttpRequest.prototype.open=f,XMLHttpRequest.prototype.send=s,i();};function d(l,p,m){let g=Date.now()-vt<kn;return {session_id:O(),event_type:"error",page_url:typeof window>"u"?"":window.location.href,selector:null,event_data:{http_status:l,request_url:p,method:m,form_selector:g?yt:null},created_at:new Date().toISOString()}}}function wt(e,t){if(t.length===0)return false;for(let n of t)if(e.includes(n))return true;return false}var Rn=3e4;function _t(e,t){if(!e.redirectLoop.enabled)return ()=>{};if(typeof window>"u")return ()=>{};let{threshold:n,windowMs:o}=e.redirectLoop,r=new Map,i=new Map,c=history.pushState,a=history.replaceState;function f(d){try{let l=Date.now(),p=i.get(d)??0;if(l<p)return;let u=(r.get(d)??[]).filter(g=>l-g<=o);if(u.push(l),r.set(d,u),u.length>=n){let g={session_id:O(),event_type:"thrashing",page_url:window.location.href,selector:null,event_data:{count:u.length,url:d,window_ms:o},created_at:new Date().toISOString()};t(g),i.set(d,l+Rn),r.set(d,[]);}}catch{}}function s(){let d=window.location.pathname+window.location.search;f(d);}return history.pushState=function(...d){let l=c.apply(this,d);return s(),l},history.replaceState=function(...d){let l=a.apply(this,d);return s(),l},window.addEventListener("popstate",s),()=>{history.pushState=c,history.replaceState=a,window.removeEventListener("popstate",s);}}function St(e,t){if(!e.formDataLoss.enabled)return ()=>{};if(typeof window>"u")return ()=>{};let n=new Set,o=0;function r(s){let d=s.closest("form");return d?d.id?`#${d.id}`:"form":null}function i(s){try{let d=s.target;if(!d||!(d instanceof HTMLInputElement||d instanceof HTMLTextAreaElement||d instanceof HTMLSelectElement))return;let l=r(d);if(!l)return;n.has(l)||n.add(l),o++;}catch{}}function c(s){if(n.size===0)return;let d=Array.from(n),l={session_id:O(),event_type:"form_abandonment",page_url:window.location.href,selector:d[0]??null,event_data:{cause:s,field_count:o,forms:d},created_at:new Date().toISOString()};t(l);}function a(s){s.persisted&&c("bfcache_restore");}function f(){c("beforeunload_after_edit");}return document.addEventListener("input",i,{capture:true,passive:true}),window.addEventListener("pageshow",a),window.addEventListener("beforeunload",f),()=>{document.removeEventListener("input",i,{capture:true}),window.removeEventListener("pageshow",a),window.removeEventListener("beforeunload",f);}}var Cn=5e3,oe=class{constructor(t){this.submitter=null;this.detectorUninstallers=[];this.flushTimer=null;this.pageHideHandler=null;this.installed=false;this.opts=t,this.resolved=pt(t.config);}install(){if(this.installed||!this.resolved.enabled||!(this.opts.passiveSampler??(()=>Math.random()<this.resolved.sampling))())return;let n=this.opts.endpoint??"https://blocfeed.com/api/behavioral-events";this.submitter=this.opts.submitter??mt({endpoint:n,blocfeedId:this.opts.blocfeedId});let o=r=>{this.submitter?.enqueue(r);};this.detectorUninstallers.push(bt(this.resolved,o)),this.detectorUninstallers.push(Et(this.resolved,o)),this.detectorUninstallers.push(_t(this.resolved,o)),this.detectorUninstallers.push(St(this.resolved,o)),this.flushTimer=setInterval(()=>{this.submitter?.flush();},Cn),this.pageHideHandler=()=>{this.submitter?.flushBeacon();},typeof window<"u"&&window.addEventListener("pagehide",this.pageHideHandler),this.installed=true;}uninstall(){if(this.installed){for(let t of this.detectorUninstallers)try{t();}catch{}this.detectorUninstallers=[],this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.pageHideHandler&&typeof window<"u"&&(window.removeEventListener("pagehide",this.pageHideHandler),this.pageHideHandler=null);try{this.submitter?.flush();}catch{}this.submitter=null,this.installed=false;}}};function Te(e){let t=null,n=null,o=(...r)=>{n=r,t===null&&(t=requestAnimationFrame(()=>{if(t=null,!n)return;let i=n;n=null,e(...i);}));};return o.cancel=()=>{t!==null&&cancelAnimationFrame(t),t=null,n=null;},o}function re(e){return e instanceof Element?!!e.closest("[data-blocfeed-ui]"):false}function ie(e){e.stopPropagation(),e.stopImmediatePropagation?.();}function kt(e,t){if(!y())throw new Error("BlocFeed picker can only run in a browser environment.");let n=e.ignoreSelectors,o=e.isSelectable,r={};n&&n.length>0&&(r.ignoreSelectors=n),o&&(r.isSelectable=o);let i=null,c=null,a=(u,g=false)=>{if(!u){i=null,c=null,t.onHover(null);return}let h=pe(u.getBoundingClientRect()),k=`${Math.round(h.x)}:${Math.round(h.y)}:${Math.round(h.width)}:${Math.round(h.height)}`;!g&&u===i&&k===c||(i=u,c=k,t.onHover({element:u,rect:h}));},f=Te(u=>{if(re(u.target))return;let g=document.elementFromPoint(u.clientX,u.clientY),h=be(g,r);a(h);}),s=Te(()=>{i&&a(i,true);}),d=u=>{re(u.target)||(ie(u),u.pointerType==="mouse"&&u.preventDefault());},l=u=>{re(u.target)||(ie(u),u.pointerType==="mouse"&&u.preventDefault());},p=u=>{if(re(u.target))return;ie(u),u.preventDefault();let g=document.elementFromPoint(u.clientX,u.clientY),h=be(g,r);h&&t.onSelect({element:h,descriptor:Ve(h)});},m=u=>{u.key==="Escape"&&(ie(u),u.preventDefault(),t.onCancel());};return window.addEventListener("pointermove",f,{capture:true,passive:true}),window.addEventListener("pointerdown",d,{capture:true}),window.addEventListener("pointerup",l,{capture:true}),window.addEventListener("click",p,{capture:true}),window.addEventListener("keydown",m,{capture:true}),window.addEventListener("scroll",s,{capture:true,passive:true}),window.addEventListener("resize",s,{passive:true}),{stop(){window.removeEventListener("pointermove",f,{capture:true}),window.removeEventListener("pointerdown",d,{capture:true}),window.removeEventListener("pointerup",l,{capture:true}),window.removeEventListener("click",p,{capture:true}),window.removeEventListener("keydown",m,{capture:true}),window.removeEventListener("scroll",s,{capture:true}),window.removeEventListener("resize",s),f.cancel(),s.cancel(),t.onHover(null);}}}async function Re(e){let{signal:t,transport:n}=e,o={ok:false};try{let r={payload:e.payload,...t?{signal:t}:{},...n?{transport:n}:{}};o.api=await ut(r),o.ok=!!o.api?.ok;}catch(r){o.api={ok:false,error:w("api_failed",r)},o.ok=false;}return {payload:e.payload,result:o}}var An=["[data-blocfeed-ui]","[data-blocfeed-ignore]"];function xn(e){let t=[...An,...e?.ignoreSelectors??[]],n=Array.from(new Set(t));return {...e,ignoreSelectors:n}}function Tt(){return {phase:"idle"}}function Fn(e){if(e.ok)return false;let t=e.api;return t?t.status&&t.status>=400&&t.status<500||t.error?.kind==="aborted"||t.error?.kind==="configuration"?false:!t.ok:true}function ir(e){let t=e,n=new oe({blocfeedId:t.blocfeed_id??"",...t.behavioral!==void 0?{config:t.behavioral}:{}});n.install();let o=Tt(),r=new Set,i=new Set,c=null,a=null,f=null,s=null,d=0,l=null,p=null,m=null,u=null,g=false,h=()=>{for(let b of r)b(o);},k=b=>{for(let E of i)E(b);},v=b=>{o=b,h();},R=()=>{d+=1,s?.abort(),s=null;},P=()=>{c?.stop(),c=null,k(null),f!==null&&y()&&(document.documentElement.style.cursor=f,f=null);},_=()=>{if(m){try{URL.revokeObjectURL(m.blobUrl);}catch{}m=null;}},ee=()=>{p&&(p.abort(),p=null),_();},B=null,M=()=>{u&&(u.abort(),u=null),B&&(B.abort(),B=null);},U=()=>{R(),P(),ee(),M(),a=null,v(Tt());},Le=()=>{if(!y())return;P(),a=null;let b=xn(t.picker);f=document.documentElement.style.cursor,document.documentElement.style.cursor="crosshair",v({phase:"picking"}),c=kt(b,{onHover:k,onSelect:({element:E,descriptor:x})=>{a=E,P(),v({phase:"review",selection:x});},onCancel:()=>{U();}});},Be=()=>{let b=Ge();if(b.length!==0)for(let E of b)Re({payload:E,...t.transport?{transport:t.transport}:{}}).catch(()=>{Ee(E);});};if(y()){setTimeout(Be,1e3);let b=()=>Be();window.addEventListener("online",b),l=()=>window.removeEventListener("online",b);}return {getState:()=>o,getConfig:()=>t,subscribe(b){return r.add(b),()=>r.delete(b)},subscribeHover(b){return i.add(b),()=>i.delete(b)},start(){o.phase==="capturing"||o.phase==="submitting"||o.phase==="recording"||o.phase!=="picking"&&Le();},stop(){U();},clearSelection(){o.phase==="capturing"||o.phase==="submitting"||o.phase==="recording"||Le();},setConfig(b){t=b;},async submit(b,E){if(!y()){let T=w("configuration",new Error("BlocFeed submit can only run in the browser"));return v({phase:"error",lastError:T}),{ok:false}}let x=t.blocfeed_id?.trim?.()??"";if(!x){let L={phase:"error",lastError:w("configuration",new Error("Missing blocfeed_id. Create a project in BlocFeed and pass its blocfeed_id."))};return o.selection&&(L.selection=o.selection),v(L),{ok:false}}if(g)return {ok:false};if(o.phase==="capturing"||o.phase==="submitting"||o.phase==="recording")return {ok:false};g=true;let A=d+1;d=A,s?.abort(),s=new AbortController;let C=s.signal,S=o.selection,I=E?.capture?{...t.capture,...E.capture}:t.capture,H=!!(I?.element||I?.fullPage),z={phase:H?"capturing":"submitting"};S&&(z.selection=S),v(z);try{let T=H?await We({selectionElement:a,capture:I,signal:C}):void 0;if(C.aborted||d!==A)return {ok:!1};let L={phase:"submitting"};S&&(L.selection=S),T&&(L.capture=T),v(L);let D={};S&&(D.selection=S),T&&(D.capture=T);let j=await Ze({config:t.metadata,context:D,...t.user?{user:t.user}:{}}),V={version:1,createdAt:new Date().toISOString(),blocfeed_id:x,message:b,metadata:j};E?.category&&(V.category=E.category),t.user&&(V.user=t.user),S&&(V.selection=S),T&&(V.screenshots=T),m&&(V.video=m);let{result:N}=await Re({payload:V,signal:C,...t.transport?{transport:t.transport}:{}});if(C.aborted||d!==A)return N;if(N.ok){_(),a=null;let fe={phase:"success",lastSubmit:N};return S&&(fe.selection=S),T&&(fe.capture=T),v(fe),N}Fn(N)&&Ee(V);let xt=N.api?.error??w("unknown",new Error("Submission failed")),ue={phase:"error",lastSubmit:N,lastError:xt};return S&&(ue.selection=S),T&&(ue.capture=T),v(ue),N}catch(T){if(C.aborted||d!==A)return {ok:false};let D={phase:"error",lastError:C.aborted?w("aborted",T):w("unknown",T)};return S&&(D.selection=S),v(D),{ok:false}}finally{g=false,d===A&&(s=null);}},async startRecording(){if(o.phase!=="review"||!t.recording?.enabled||u||p)return;let b=o.selection,E={phase:"recording",recordingElapsedMs:0};b&&(E.selection=b),v(E);try{let x={config:t.recording};s&&(x.signal=s.signal);let A=await _e(x);p=A,A.onTick(I=>{if(o.phase==="recording"){let H={phase:"recording",recordingElapsedMs:I};b&&(H.selection=b),v(H);}});let C=await A.result;p=null,m=C;let S={phase:"review",video:C};b&&(S.selection=b),v(S);}catch(x){p=null;let C={phase:"review",lastError:x?.kind?x:w("recording_failed",x)};b&&(C.selection=b),v(C);}},stopRecording(){o.phase!=="recording"||!p||p.stop();},removeVideo(){_();let b=o.selection,E={phase:"review"};b&&(E.selection=b),v(E);},async startVoice(){if(o.phase!=="review"){console.warn("[BlocFeed] startVoice: ignored \u2014 phase is",o.phase,'(expected "review")');return}let b=t.voice;if(!b?.enabled){console.warn("[BlocFeed] startVoice: ignored \u2014 voice is not enabled in config");return}if(p){console.warn("[BlocFeed] startVoice: ignored \u2014 a screen recording is already in progress");return}M();let E=o.selection,x={phase:"review",voiceRecording:true,voiceElapsedMs:0};E&&(x.selection=E),m&&(x.video=m),v(x);try{let A={config:b};s&&(A.signal=s.signal);let C=await Se(A);u=C,C.onTick(D=>{let j={phase:"review",voiceRecording:!0,voiceElapsedMs:D};E&&(j.selection=E),m&&(j.video=m),v(j);});let S=await C.result;u=null;let I={phase:"review",voiceRecording:!1,voiceTranscribing:!0};E&&(I.selection=E),m&&(I.video=m),v(I),B=new AbortController;let H={blob:S.blob,mime:S.mime,blocfeedId:t.blocfeed_id,signal:B.signal},{text:Ie,warning:z}=await ft(H);B=null;let T={phase:"review",voiceRecording:!1,voiceTranscribing:!1};E&&(T.selection=E),m&&(T.video=m),v(T);let L={text:Ie};return z&&(L.warning=z),L}catch(A){M();let C=A?.kind?A:w("recording_failed",A);console.warn("[BlocFeed] Voice error:",C.message);let S={phase:"review",voiceRecording:false,voiceTranscribing:false,lastError:C};E&&(S.selection=E),m&&(S.video=m),v(S);return}},stopVoice(){u&&u.stop();},__unsafeGetSelectedElement(){return a},destroy(){n.uninstall(),U(),r.clear(),i.clear(),l?.(),l=null;}}}var Y=[],Q=[],Rt=20,Ct=15,se=[],At=typeof console<"u"?{log:console.log?.bind(console),warn:console.warn?.bind(console),error:console.error?.bind(console),info:console.info?.bind(console),debug:console.debug?.bind(console)}:{},ae=typeof globalThis<"u"&&typeof globalThis.fetch=="function"?globalThis.fetch:void 0,ce=typeof XMLHttpRequest<"u"?XMLHttpRequest.prototype.open:void 0,le=typeof XMLHttpRequest<"u"?XMLHttpRequest.prototype.send:void 0,Ae=new Set,xe=false,Fe=false,de=false,Pn=["blocfeed.com","google-analytics.com","googletagmanager.com","analytics.google.com","googleads.g.doubleclick.net","googlesyndication.com","googleadservices.com","google.com/pagead","google.com/ads","facebook.net","facebook.com/tr","connect.facebook.net","graph.facebook.com","api.mixpanel.com","api-js.mixpanel.com","api.amplitude.com","api2.amplitude.com","api.segment.io","cdn.segment.com","vars.hotjar.com","in.hotjar.com","script.hotjar.com","heapanalytics.com","fullstory.com/s/fs.js","rs.fullstory.com","app.posthog.com","us.posthog.com","eu.posthog.com","api-iam.intercom.io","widget.intercom.io","sentry.io/api","browser.sentry-cdn.com","browser-intake-datadoghq.com","clarity.ms","js.hs-analytics.net","api.hubapi.com","forms.hubspot.com","plausible.io/api","client.crisp.chat","js.driftt.com","r.logrocket.com","app.pendo.io","events.launchdarkly.com","app.launchdarkly.com","grammarly.com","gnar.grammarly.com","capi.grammarly.com","api.languagetool.org","api.languagetoolplus.com","fonts.googleapis.com","fonts.gstatic.com","cdn.cookielaw.org","consent.cookiebot.com","js.stripe.com","api.stripe.com/v1/tokens","google.com/recaptcha","hcaptcha.com","bam.nr-data.net","rec.smartlook.com","o2.mouseflow.com","api.luckyorange.com","static.zdassets.com","ekr.zdassets.com"];function Mn(e){if(e instanceof Error)return e.name&&e.name!=="Error"?`${e.name}: ${e.message}`:e.message||String(e);if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}function Ln(e,t){let n=t.map(Mn).join(" "),o=t.find(i=>i instanceof Error),r={level:e,message:n.slice(0,2e3),timestamp:Date.now()};for(o?.stack&&(r.stack=o.stack.slice(0,2e3)),Y.push(r);Y.length>Rt;)Y.shift();}function Ce(e){let t=e.url.toLowerCase();for(let n of se)if(t.includes(n))return;for(Q.push(e);Q.length>Ct;)Q.shift();}function cr(e={}){if(de||!y())return;de=true,Rt=e.consoleLimit??20,Ct=e.networkLimit??15;let t=e.ignoreUrls;if(t!==void 0?se=t.map(n=>n.toLowerCase()):se=[...Pn],e.console!==false){let n=e.consoleLevels??["error","warn"];for(let o of n){let r=At[o];r&&(Ae.add(o),console[o]=(...i)=>{Ln(o,i),r.apply(console,i);});}}if(e.network!==false&&ae){let n=ae;xe=true,window.fetch=async function(r,i){let c=typeof r=="string"?r:r instanceof URL?r.toString():r.url,a=(i?.method??"GET").toUpperCase(),f=Date.now();try{let s=await n.call(window,r,i);return s.ok||Ce({url:c.slice(0,500),method:a,status:s.status,statusText:s.statusText,timestamp:f,durationMs:Date.now()-f}),s}catch(s){throw Ce({url:c.slice(0,500),method:a,status:0,statusText:s instanceof Error?s.message:"Network error",timestamp:f,durationMs:Date.now()-f}),s}};}if(e.network!==false&&ce&&le){let n=ce,o=le;Fe=true,XMLHttpRequest.prototype.open=function(r,i,...c){return this.__bf_method=r.toUpperCase(),this.__bf_url=String(i),n.apply(this,[r,i,...c])},XMLHttpRequest.prototype.send=function(...r){let i=this.__bf_method||"GET",c=this.__bf_url||"",a=Date.now();return this.addEventListener("loadend",function(){if(this.status>=400||this.status===0){let f={url:c.slice(0,500),method:i,status:this.status,timestamp:a,durationMs:Date.now()-a};this.statusText&&(f.statusText=this.statusText),Ce(f);}},{once:true}),o.apply(this,r)};}}function lr(){if(de){for(let e of Ae){let t=At[e];t&&(console[e]=t);}Ae.clear(),xe&&ae&&(window.fetch=ae,xe=false),Fe&&ce&&le&&(XMLHttpRequest.prototype.open=ce,XMLHttpRequest.prototype.send=le,Fe=false),se=[],de=false;}}function dr(){return {consoleLogs:[...Y],networkErrors:[...Q]}}function ur(){Y=[],Q=[];}var Bn=[{name:"supabase_service_role_key",pattern:/SUPABASE_SERVICE_ROLE_KEY["'=:\s]{1,8}[A-Za-z0-9_.=-]{30,400}/},{name:"supabase_db_password",pattern:/SUPABASE_DB_PASSWORD["'=:\s]{1,8}[^\s"']{6,200}/},{name:"postgres_password",pattern:/POSTGRES_PASSWORD["'=:\s]{1,8}[^\s"']{6,200}/},{name:"database_url_with_creds",pattern:/(?:postgres|postgresql|mysql|mongodb|redis|amqp):\/\/[^:\s"']{1,100}:[^@\s"']{1,200}@/},{name:"aws_access_key",pattern:/AKIA[0-9A-Z]{16}/},{name:"aws_secret_key",pattern:/AWS_SECRET_ACCESS_KEY["'=:\s]{1,8}[A-Za-z0-9/+=]{30,200}/},{name:"aws_session_token",pattern:/AWS_SESSION_TOKEN["'=:\s]{1,8}[A-Za-z0-9/+=]{30,600}/},{name:"stripe_secret_key",pattern:/sk_live_[a-zA-Z0-9]{10,200}/},{name:"stripe_secret_key_test",pattern:/sk_test_[a-zA-Z0-9]{10,200}/},{name:"stripe_restricted_key",pattern:/rk_(?:live|test)_[a-zA-Z0-9]{10,200}/},{name:"github_pat",pattern:/ghp_[A-Za-z0-9_]{36,100}/},{name:"github_oauth",pattern:/gho_[A-Za-z0-9_]{36,100}/},{name:"github_user_token",pattern:/ghu_[A-Za-z0-9_]{36,100}/},{name:"github_server_token",pattern:/ghs_[A-Za-z0-9_]{36,100}/},{name:"github_fine_grained",pattern:/github_pat_[A-Za-z0-9_]{22,200}/},{name:"openai_api_key",pattern:/sk-[a-zA-Z0-9]{20,200}(?![a-zA-Z0-9_])/},{name:"anthropic_api_key",pattern:/sk-ant-[a-zA-Z0-9\-_]{20,200}/},{name:"private_key",pattern:/-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY-----/},{name:"sendgrid_api_key",pattern:/SG\.[a-zA-Z0-9_-]{22,100}\.[a-zA-Z0-9_-]{22,100}/},{name:"twilio_auth_token",pattern:/TWILIO_AUTH_TOKEN["'=:\s]{1,8}[a-f0-9]{32}/},{name:"generic_secret_key",pattern:/[A-Z_]{2,60}_SECRET_KEY["'=:\s]{1,8}[^\s"']{8,200}/},{name:"generic_secret",pattern:/[A-Z_]{2,60}_SECRET["'=:\s]{1,8}[^\s"']{8,200}/},{name:"generic_password",pattern:/[A-Z_]{2,60}_PASSWORD["'=:\s]{1,8}[^\s"']{6,200}/},{name:"generic_private_key_var",pattern:/[A-Z_]{2,60}_PRIVATE_KEY["'=:\s]{1,8}[^\s"']{8,400}/}],X=[],Me=0,Pe=false;function In(e){let t=e.slice(0,80);return t.length<=6?"***":t.slice(0,6)+"***"}function Dn(e,t,n,o){if(X.some(c=>c.rule===e&&c.source===t))return;let i={rule:e,source:t,hint:In(n),timestamp:Date.now()};o&&(i.location=o),X.push(i);}function J(e,t,n,o){for(let{name:r,pattern:i}of n){let c=i.exec(e);c&&Dn(r,t,c[0],o);}}function Nn(e){try{let t=window;if(t.__NEXT_DATA__){let n=JSON.stringify(t.__NEXT_DATA__);J(n,"hydration",e,"__NEXT_DATA__");}if(t.__NUXT__){let n=JSON.stringify(t.__NUXT__);J(n,"hydration",e,"__NUXT__");}}catch{}}function On(e){try{document.querySelectorAll("script:not([src])").forEach((n,o)=>{let r=n.textContent;r&&r.length>0&&J(r,"scripts",e,`inline-script[${o}]`);});}catch{}}function Un(e){try{document.querySelectorAll("meta[content]").forEach(n=>{let o=n.getAttribute("content"),r=n.getAttribute("name")||n.getAttribute("property")||"";o&&o.length>10&&J(o,"meta",e,r?`meta[${r}]`:void 0);});}catch{}}function Hn(e){try{document.querySelectorAll("[data-api-key], [data-secret], [data-token], [data-password]").forEach(n=>{let o=n.attributes;for(let r=0;r<o.length;r++){let i=o[r];i.name.startsWith("data-")&&i.value.length>10&&J(i.value,"dom",e,`${n.tagName.toLowerCase()}[${i.name}]`);}});}catch{}}function mr(e={}){if(Pe||!y()||(Pe=true,e.secretScan===false))return;let t=[...Bn,...e.customPatterns??[]],n=e.scanTargets??["hydration","scripts","meta","dom"];setTimeout(()=>{Me=Date.now(),n.includes("hydration")&&Nn(t),n.includes("scripts")&&On(t),n.includes("meta")&&Un(t),n.includes("dom")&&Hn(t);let o=e.notify??"both";X.length>0&&(o==="console"||o==="both")&&console.warn(`[BlocFeed Security] Found ${X.length} potential secret(s) exposed in client code:`,X.map(r=>`${r.rule} (${r.source}${r.location?`: ${r.location}`:""})`));},100);}function gr(){return {findings:[...X],scannedAt:Me}}function hr(){X=[],Me=0,Pe=false;}
|
|
2
|
+
exports.A=hr;exports.a=y;exports.b=pe;exports.c=$e;exports.d=We;exports.e=Ze;exports.f=Ee;exports.g=Ge;exports.h=Jn;exports.i=eo;exports.j=Gt;exports.k=Yt;exports.l=on;exports.m=_e;exports.n=cn;exports.o=Se;exports.p=mn;exports.q=wo;exports.r=ft;exports.s=oe;exports.t=ir;exports.u=cr;exports.v=lr;exports.w=dr;exports.x=ur;exports.y=mr;exports.z=gr;
|
|
@@ -1,3 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Behavioral tracking types. Keep this file free of runtime imports —
|
|
3
|
+
* pure type declarations only.
|
|
4
|
+
*/
|
|
5
|
+
type BehavioralEventType = "rage_click" | "error" | "thrashing" | "form_abandonment";
|
|
6
|
+
interface BehavioralEvent {
|
|
7
|
+
session_id: string;
|
|
8
|
+
event_type: BehavioralEventType;
|
|
9
|
+
page_url: string;
|
|
10
|
+
selector: string | null;
|
|
11
|
+
event_data: Record<string, unknown> | null;
|
|
12
|
+
created_at: string;
|
|
13
|
+
}
|
|
14
|
+
interface RageClickConfig {
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
threshold?: number;
|
|
17
|
+
windowMs?: number;
|
|
18
|
+
}
|
|
19
|
+
interface HttpFailConfig {
|
|
20
|
+
enabled?: boolean;
|
|
21
|
+
statusCodes?: number[];
|
|
22
|
+
ignoreUrls?: string[];
|
|
23
|
+
}
|
|
24
|
+
interface RedirectLoopConfig {
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
threshold?: number;
|
|
27
|
+
windowMs?: number;
|
|
28
|
+
}
|
|
29
|
+
interface FormDataLossConfig {
|
|
30
|
+
enabled?: boolean;
|
|
31
|
+
}
|
|
32
|
+
interface BehavioralConfig {
|
|
33
|
+
enabled?: boolean;
|
|
34
|
+
sampling?: number;
|
|
35
|
+
ignoreSelectors?: string[];
|
|
36
|
+
rageClick?: RageClickConfig;
|
|
37
|
+
httpFail?: HttpFailConfig;
|
|
38
|
+
redirectLoop?: RedirectLoopConfig;
|
|
39
|
+
formDataLoss?: FormDataLossConfig;
|
|
40
|
+
}
|
|
41
|
+
|
|
1
42
|
type MaybePromise<T> = T | Promise<T>;
|
|
2
43
|
type ScreenshotMime = "image/png" | "image/jpeg";
|
|
3
44
|
interface ImageAsset {
|
|
@@ -326,6 +367,12 @@ interface BlocFeedConfig {
|
|
|
326
367
|
/** Which feedback categories to show as pills. Default: all four. */
|
|
327
368
|
categories?: FeedbackCategory[];
|
|
328
369
|
};
|
|
370
|
+
/**
|
|
371
|
+
* Passive behavioral pattern detection (rage clicks, HTTP failures,
|
|
372
|
+
* redirect loops, form data loss). Defaults to enabled. See
|
|
373
|
+
* docs/design-docs/2026-04-22-widget-pattern-detectors-design.md.
|
|
374
|
+
*/
|
|
375
|
+
behavioral?: BehavioralConfig;
|
|
329
376
|
}
|
|
330
377
|
interface ScreenshotIntent {
|
|
331
378
|
element?: {
|
|
@@ -432,4 +479,4 @@ interface BlocFeedController {
|
|
|
432
479
|
}
|
|
433
480
|
declare function createBlocFeedController(config: BlocFeedConfig): BlocFeedController;
|
|
434
481
|
|
|
435
|
-
export { type
|
|
482
|
+
export { type TransportResult as A, type BlocFeedConfig as B, type CaptureConfig as C, type DiagnosticsConfig as D, type ElementDescriptor as E, type FeedbackCategory as F, type TriggerStyle as G, type VideoIntent as H, type ImageAsset as I, type VideoMime as J, type VoiceConfig as K, type ClickEvent as L, type MaybePromise as M, type NetworkEntry as N, type HoverListener as O, type PickerConfig as P, type StateListener as Q, type RecordingConfig as R, type SubmitResult as S, type ThemeConfig as T, createBlocFeedController as U, type VideoAsset as V, type WidgetPosition as W, type BlocFeedHandle as a, type BlocFeedState as b, type BlocFeedController as c, type BehavioralEvent as d, type BehavioralConfig as e, type BehavioralEventType as f, type BlocFeedError as g, type BlocFeedStrings as h, type BlocFeedUser as i, type CaptureDiagnostics as j, type CaptureResult as k, type ConsoleEntry as l, type FeedbackApiResponse as m, type FeedbackPayload as n, type MetadataConfig as o, type MetadataContext as p, type Rect as q, type ScreenshotAdapter as r, type ScreenshotAdapterOptions as s, type ScreenshotIntent as t, type ScreenshotMime as u, type SecurityConfig as v, type SecurityFinding as w, type SecuritySnapshot as x, type SessionPhase as y, type TransportConfig as z };
|
|
@@ -1,3 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Behavioral tracking types. Keep this file free of runtime imports —
|
|
3
|
+
* pure type declarations only.
|
|
4
|
+
*/
|
|
5
|
+
type BehavioralEventType = "rage_click" | "error" | "thrashing" | "form_abandonment";
|
|
6
|
+
interface BehavioralEvent {
|
|
7
|
+
session_id: string;
|
|
8
|
+
event_type: BehavioralEventType;
|
|
9
|
+
page_url: string;
|
|
10
|
+
selector: string | null;
|
|
11
|
+
event_data: Record<string, unknown> | null;
|
|
12
|
+
created_at: string;
|
|
13
|
+
}
|
|
14
|
+
interface RageClickConfig {
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
threshold?: number;
|
|
17
|
+
windowMs?: number;
|
|
18
|
+
}
|
|
19
|
+
interface HttpFailConfig {
|
|
20
|
+
enabled?: boolean;
|
|
21
|
+
statusCodes?: number[];
|
|
22
|
+
ignoreUrls?: string[];
|
|
23
|
+
}
|
|
24
|
+
interface RedirectLoopConfig {
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
threshold?: number;
|
|
27
|
+
windowMs?: number;
|
|
28
|
+
}
|
|
29
|
+
interface FormDataLossConfig {
|
|
30
|
+
enabled?: boolean;
|
|
31
|
+
}
|
|
32
|
+
interface BehavioralConfig {
|
|
33
|
+
enabled?: boolean;
|
|
34
|
+
sampling?: number;
|
|
35
|
+
ignoreSelectors?: string[];
|
|
36
|
+
rageClick?: RageClickConfig;
|
|
37
|
+
httpFail?: HttpFailConfig;
|
|
38
|
+
redirectLoop?: RedirectLoopConfig;
|
|
39
|
+
formDataLoss?: FormDataLossConfig;
|
|
40
|
+
}
|
|
41
|
+
|
|
1
42
|
type MaybePromise<T> = T | Promise<T>;
|
|
2
43
|
type ScreenshotMime = "image/png" | "image/jpeg";
|
|
3
44
|
interface ImageAsset {
|
|
@@ -326,6 +367,12 @@ interface BlocFeedConfig {
|
|
|
326
367
|
/** Which feedback categories to show as pills. Default: all four. */
|
|
327
368
|
categories?: FeedbackCategory[];
|
|
328
369
|
};
|
|
370
|
+
/**
|
|
371
|
+
* Passive behavioral pattern detection (rage clicks, HTTP failures,
|
|
372
|
+
* redirect loops, form data loss). Defaults to enabled. See
|
|
373
|
+
* docs/design-docs/2026-04-22-widget-pattern-detectors-design.md.
|
|
374
|
+
*/
|
|
375
|
+
behavioral?: BehavioralConfig;
|
|
329
376
|
}
|
|
330
377
|
interface ScreenshotIntent {
|
|
331
378
|
element?: {
|
|
@@ -432,4 +479,4 @@ interface BlocFeedController {
|
|
|
432
479
|
}
|
|
433
480
|
declare function createBlocFeedController(config: BlocFeedConfig): BlocFeedController;
|
|
434
481
|
|
|
435
|
-
export { type
|
|
482
|
+
export { type TransportResult as A, type BlocFeedConfig as B, type CaptureConfig as C, type DiagnosticsConfig as D, type ElementDescriptor as E, type FeedbackCategory as F, type TriggerStyle as G, type VideoIntent as H, type ImageAsset as I, type VideoMime as J, type VoiceConfig as K, type ClickEvent as L, type MaybePromise as M, type NetworkEntry as N, type HoverListener as O, type PickerConfig as P, type StateListener as Q, type RecordingConfig as R, type SubmitResult as S, type ThemeConfig as T, createBlocFeedController as U, type VideoAsset as V, type WidgetPosition as W, type BlocFeedHandle as a, type BlocFeedState as b, type BlocFeedController as c, type BehavioralEvent as d, type BehavioralConfig as e, type BehavioralEventType as f, type BlocFeedError as g, type BlocFeedStrings as h, type BlocFeedUser as i, type CaptureDiagnostics as j, type CaptureResult as k, type ConsoleEntry as l, type FeedbackApiResponse as m, type FeedbackPayload as n, type MetadataConfig as o, type MetadataContext as p, type Rect as q, type ScreenshotAdapter as r, type ScreenshotAdapterOptions as s, type ScreenshotIntent as t, type ScreenshotMime as u, type SecurityConfig as v, type SecurityFinding as w, type SecuritySnapshot as x, type SessionPhase as y, type TransportConfig as z };
|
package/dist/engine.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkNLL5DECC_cjs=require('./chunk-NLL5DECC.cjs');function s(o){if(o?.aborted)throw new Error("Aborted")}async function v(o){return await new Promise((t,e)=>{let r=new Image;r.onload=()=>t({width:r.naturalWidth,height:r.naturalHeight}),r.onerror=()=>e(new Error("Failed to load generated screenshot")),r.src=o;})}async function l(o,t){let{width:e,height:r}=await v(o);return {dataUrl:o,mime:t,width:e,height:r}}function U(o){return {async captureElement(t,e){if(!chunkNLL5DECC_cjs.a())throw new Error("captureElement can only run in the browser");s(e.signal);let r={scale:e.pixelRatio},n=e.mime==="image/jpeg"?await o.domToJpeg(t,{...r,quality:e.quality??.92}):await o.domToPng(t,r);return s(e.signal),await l(n,e.mime)},async captureFullPage(t){if(!chunkNLL5DECC_cjs.a())throw new Error("captureFullPage can only run in the browser");s(t.signal);let e=document.documentElement,r=Math.max(e.scrollWidth,e.clientWidth),n=Math.max(e.scrollHeight,e.clientHeight),i=Math.min(1,t.maxDimension/Math.max(r,n)),c={width:Math.max(1,Math.round(r*i)),height:Math.max(1,Math.round(n*i)),scale:t.pixelRatio},a=t.mime==="image/jpeg"?await o.domToJpeg(e,{...c,quality:t.quality??.92}):await o.domToPng(e,c);return s(t.signal),await l(a,t.mime)}}}function O(o){let[t,e]=o.split(",",2);if(!t||!e)throw new Error("Invalid data URL");let n=/data:(.*?);base64/.exec(t)?.[1]||"application/octet-stream",i=atob(e),c=new Uint8Array(i.length);for(let a=0;a<i.length;a+=1)c[a]=i.charCodeAt(a);return new Blob([c],{type:n})}Object.defineProperty(exports,"clearClickEvents",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.k}});Object.defineProperty(exports,"clearDiagnostics",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.x}});Object.defineProperty(exports,"clearQueue",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.h}});Object.defineProperty(exports,"clearSecurityFindings",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.A}});Object.defineProperty(exports,"collectMetadata",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.e}});Object.defineProperty(exports,"createBlocFeedController",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.t}});Object.defineProperty(exports,"createHtmlToImageAdapter",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.c}});Object.defineProperty(exports,"dequeueAll",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.g}});Object.defineProperty(exports,"drainClickEvents",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.j}});Object.defineProperty(exports,"drainDiagnostics",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.w}});Object.defineProperty(exports,"enqueue",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.f}});Object.defineProperty(exports,"getMyFeedbackUrl",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.q}});Object.defineProperty(exports,"getQueueSize",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.i}});Object.defineProperty(exports,"getSecurityFindings",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.z}});Object.defineProperty(exports,"getViewerToken",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.p}});Object.defineProperty(exports,"installDiagnostics",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.u}});Object.defineProperty(exports,"isRecordingSupported",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.l}});Object.defineProperty(exports,"isVoiceSupported",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.n}});Object.defineProperty(exports,"runCapture",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.d}});Object.defineProperty(exports,"runSecretScan",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.y}});Object.defineProperty(exports,"startRecording",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.m}});Object.defineProperty(exports,"startVoiceRecording",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.o}});Object.defineProperty(exports,"transcribeAudio",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.r}});Object.defineProperty(exports,"uninstallDiagnostics",{enumerable:true,get:function(){return chunkNLL5DECC_cjs.v}});exports.createModernScreenshotAdapter=U;exports.dataUrlToBlob=O;
|
package/dist/engine.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { B as BlocFeedConfig, c as BlocFeedController,
|
|
1
|
+
import { r as ScreenshotAdapter, C as CaptureConfig, k as CaptureResult, V as VideoAsset, R as RecordingConfig, L as ClickEvent, K as VoiceConfig, o as MetadataConfig, p as MetadataContext, i as BlocFeedUser, n as FeedbackPayload, x as SecuritySnapshot, v as SecurityConfig } from './controller-6fm9oK63.cjs';
|
|
2
|
+
export { B as BlocFeedConfig, c as BlocFeedController, g as BlocFeedError, a as BlocFeedHandle, b as BlocFeedState, h as BlocFeedStrings, l as ConsoleEntry, D as DiagnosticsConfig, E as ElementDescriptor, m as FeedbackApiResponse, F as FeedbackCategory, O as HoverListener, I as ImageAsset, N as NetworkEntry, q as Rect, s as ScreenshotAdapterOptions, t as ScreenshotIntent, u as ScreenshotMime, w as SecurityFinding, y as SessionPhase, Q as StateListener, S as SubmitResult, T as ThemeConfig, z as TransportConfig, G as TriggerStyle, H as VideoIntent, J as VideoMime, W as WidgetPosition, U as createBlocFeedController } from './controller-6fm9oK63.cjs';
|
|
3
3
|
|
|
4
4
|
declare function createHtmlToImageAdapter(): ScreenshotAdapter;
|
|
5
5
|
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { B as BlocFeedConfig, c as BlocFeedController,
|
|
1
|
+
import { r as ScreenshotAdapter, C as CaptureConfig, k as CaptureResult, V as VideoAsset, R as RecordingConfig, L as ClickEvent, K as VoiceConfig, o as MetadataConfig, p as MetadataContext, i as BlocFeedUser, n as FeedbackPayload, x as SecuritySnapshot, v as SecurityConfig } from './controller-6fm9oK63.js';
|
|
2
|
+
export { B as BlocFeedConfig, c as BlocFeedController, g as BlocFeedError, a as BlocFeedHandle, b as BlocFeedState, h as BlocFeedStrings, l as ConsoleEntry, D as DiagnosticsConfig, E as ElementDescriptor, m as FeedbackApiResponse, F as FeedbackCategory, O as HoverListener, I as ImageAsset, N as NetworkEntry, q as Rect, s as ScreenshotAdapterOptions, t as ScreenshotIntent, u as ScreenshotMime, w as SecurityFinding, y as SessionPhase, Q as StateListener, S as SubmitResult, T as ThemeConfig, z as TransportConfig, G as TriggerStyle, H as VideoIntent, J as VideoMime, W as WidgetPosition, U as createBlocFeedController } from './controller-6fm9oK63.js';
|
|
3
3
|
|
|
4
4
|
declare function createHtmlToImageAdapter(): ScreenshotAdapter;
|
|
5
5
|
|
package/dist/engine.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a}from'./chunk-
|
|
1
|
+
import {a}from'./chunk-CYITSKBK.js';export{k as clearClickEvents,x as clearDiagnostics,h as clearQueue,A as clearSecurityFindings,e as collectMetadata,t as createBlocFeedController,c as createHtmlToImageAdapter,g as dequeueAll,j as drainClickEvents,w as drainDiagnostics,f as enqueue,q as getMyFeedbackUrl,i as getQueueSize,z as getSecurityFindings,p as getViewerToken,u as installDiagnostics,l as isRecordingSupported,n as isVoiceSupported,d as runCapture,y as runSecretScan,m as startRecording,o as startVoiceRecording,r as transcribeAudio,v as uninstallDiagnostics}from'./chunk-CYITSKBK.js';function s(o){if(o?.aborted)throw new Error("Aborted")}async function v(o){return await new Promise((t,e)=>{let r=new Image;r.onload=()=>t({width:r.naturalWidth,height:r.naturalHeight}),r.onerror=()=>e(new Error("Failed to load generated screenshot")),r.src=o;})}async function l(o,t){let{width:e,height:r}=await v(o);return {dataUrl:o,mime:t,width:e,height:r}}function U(o){return {async captureElement(t,e){if(!a())throw new Error("captureElement can only run in the browser");s(e.signal);let r={scale:e.pixelRatio},n=e.mime==="image/jpeg"?await o.domToJpeg(t,{...r,quality:e.quality??.92}):await o.domToPng(t,r);return s(e.signal),await l(n,e.mime)},async captureFullPage(t){if(!a())throw new Error("captureFullPage can only run in the browser");s(t.signal);let e=document.documentElement,r=Math.max(e.scrollWidth,e.clientWidth),n=Math.max(e.scrollHeight,e.clientHeight),i=Math.min(1,t.maxDimension/Math.max(r,n)),c={width:Math.max(1,Math.round(r*i)),height:Math.max(1,Math.round(n*i)),scale:t.pixelRatio},a$1=t.mime==="image/jpeg"?await o.domToJpeg(e,{...c,quality:t.quality??.92}):await o.domToPng(e,c);return s(t.signal),await l(a$1,t.mime)}}}function O(o){let[t,e]=o.split(",",2);if(!t||!e)throw new Error("Invalid data URL");let n=/data:(.*?);base64/.exec(t)?.[1]||"application/octet-stream",i=atob(e),c=new Uint8Array(i.length);for(let a=0;a<i.length;a+=1)c[a]=i.charCodeAt(a);return new Blob([c],{type:n})}export{U as createModernScreenshotAdapter,O as dataUrlToBlob};
|