@daybook/feedback 1.2.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/feedback.js +13 -12
- package/dist/index.js +45 -3
- package/dist/snapshot.d.ts +58 -0
- package/dist/snapshot.js +238 -0
- package/dist/types.d.ts +11 -0
- package/dist/widget.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -225,6 +225,22 @@ three days later when the reporter has moved on.
|
|
|
225
225
|
- **Page and device** — route, title, referrer, locale, timezone, viewport with DPR, and a readable
|
|
226
226
|
browser and OS rather than a raw user-agent string.
|
|
227
227
|
- **Breadcrumbs** — the last 40 navigations, clicks, console errors and failed or slow requests.
|
|
228
|
+
- **The page itself**, as `page-snapshot.json`: the markup with its classes and attributes, the
|
|
229
|
+
computed style of the pinned element and its ancestors, everything floating over the page at that
|
|
230
|
+
moment, what had focus, where the page was scrolled to, and which stylesheets were readable.
|
|
231
|
+
|
|
232
|
+
This is the half of a report a screenshot cannot give you, and it needs no permission — it is the
|
|
233
|
+
page's own state, read by script that is already running on it. A picture is for a person; most
|
|
234
|
+
feedback now passes an assistant first, and to an assistant a PNG is nearly opaque where a DOM is
|
|
235
|
+
the whole answer.
|
|
236
|
+
|
|
237
|
+
It obeys `redact` exactly as everything else does: field values are described rather than
|
|
238
|
+
reproduced, and `data-daybook-private` subtrees are replaced by a marker. Script bodies are
|
|
239
|
+
dropped, attributes and text are capped, and the whole thing truncates rather than growing.
|
|
240
|
+
|
|
241
|
+
**What it does carry is the page's visible text**, because that is what the page is. On screens
|
|
242
|
+
showing personal data, decide whether that belongs in a report — `dom: false` turns it off, and
|
|
243
|
+
`data-daybook-private` withholds a subtree without turning the whole thing off.
|
|
228
244
|
- **A screenshot**, if the reporter ticks "Capture the screen" and consents to the browser's share
|
|
229
245
|
prompt. The widget hides itself for the frame, so the picture is of the page underneath rather
|
|
230
246
|
than of the form that was just filled in — and if the reporter pinned an element, that element is
|
package/dist/feedback.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
"use strict";var DaybookFeedback=(()=>{var I=Object.defineProperty;var Ee=Object.getOwnPropertyDescriptor;var Te=Object.getOwnPropertyNames;var Se=Object.prototype.hasOwnProperty;var Le=(n,e)=>{for(var t in e)I(n,t,{get:e[t],enumerable:!0})},_e=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Te(e))!Se.call(n,r)&&r!==t&&I(n,r,{get:()=>e[r],enumerable:!(o=Ee(e,r))||o.enumerable});return n};var $e=n=>_e(I({},"__esModule",{value:!0}),n);var Je={};Le(Je,{DEFAULT_API_URL:()=>ke,DaybookFeedback:()=>H,captureAnchor:()=>_,init:()=>Ye,previewLauncher:()=>ye,resolveAnchor:()=>le});function v(n){var e;try{let t=new URL(n,location.href);return t.origin===location.origin?t.pathname:`${t.origin}${t.pathname}`}catch{return(e=n.split("?")[0])!=null?e:n}}function P(n){var o,r,i,s,a,c;let e=n.tagName.toLowerCase();if(!n.getAttribute("aria-label")&&!n.getAttribute("data-testid")&&!((o=n.textContent)!=null?o:"").trim()){let l=n.closest("button, a, [role=button], [data-testid], label");if(l&&l!==n)return P(l)}if(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement||n instanceof HTMLSelectElement){let l=(i=(r=n.getAttribute("name"))!=null?r:n.id)!=null?i:"",h=n instanceof HTMLInputElement?n.type:e;return`${e}[${h}]${l?` name=${l}`:""}`}let t=(c=(s=n.getAttribute("aria-label"))!=null?s:n.getAttribute("data-testid"))!=null?c:((a=n.textContent)!=null?a:"").replace(/\s+/g," ").trim().slice(0,40);return t?`${e} "${t}"`:e}function G(n){return n.replace(/[\w.+-]+@[\w-]+\.[\w.]+/g,"[email]").replace(/\b[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g,"[jwt]").replace(/\bBearer\s+[\w.-]+/gi,"Bearer [redacted]").replace(/\b\d{12,19}\b/g,"[number]").slice(0,500)}var Z="data-daybook-private";var k=class{constructor(e=40,t=!0){this.limit=e;this.redact=t;this.entries=[];this.detach=[]}list(){return[...this.entries]}add(e,t){for(this.entries.push({at:new Date().toISOString(),type:e,message:this.redact?G(t):t.slice(0,500)});this.entries.length>this.limit;)this.entries.shift()}start(){let e=a=>{let c=a.target;c instanceof Element&&(c.closest("[data-daybook-feedback]")||this.add("click",P(c)))};document.addEventListener("click",e,{capture:!0,passive:!0}),this.detach.push(()=>document.removeEventListener("click",e,{capture:!0}));let t=history.pushState,o=history.replaceState,r=()=>this.add("nav",v(location.href));history.pushState=(...a)=>{t.apply(history,a),r()},history.replaceState=(...a)=>{o.apply(history,a),r()},window.addEventListener("popstate",r),this.detach.push(()=>{history.pushState=t,history.replaceState=o,window.removeEventListener("popstate",r)});for(let a of["error","warn"]){let c=console[a];console[a]=(...l)=>{this.add("console",`${a}: ${l.map(B).join(" ")}`),c.apply(console,l)},this.detach.push(()=>{console[a]=c})}let i=a=>this.add("console",`uncaught: ${a.message}`),s=a=>this.add("console",`unhandled rejection: ${B(a.reason)}`);window.addEventListener("error",i),window.addEventListener("unhandledrejection",s),this.detach.push(()=>{window.removeEventListener("error",i),window.removeEventListener("unhandledrejection",s)}),this.watchFetch()}stop(){for(let e of this.detach.splice(0))e()}watchFetch(){if(typeof window.fetch!="function")return;let e=window.fetch;window.fetch=async(...t)=>{let o=performance.now();try{let r=await e.apply(window,t),i=Math.round(performance.now()-o);return(!r.ok||i>3e3)&&this.add("network",`${r.status} ${v(ee(t[0]))} ${i}ms`),r}catch(r){throw this.add("network",`failed ${v(ee(t[0]))}: ${B(r)}`),r}},this.detach.push(()=>{window.fetch=e})}};function ee(n){return typeof n=="string"?n:n instanceof URL?n.href:n.url}function B(n){var e,t;if(typeof n=="string")return n;if(n instanceof Error)return`${n.name}: ${n.message}`;try{return(t=(e=JSON.stringify(n))==null?void 0:e.slice(0,200))!=null?t:String(n)}catch{return String(n)}}var j="pm.feedback.queue";var T=class{constructor(e,t){this.apiUrl=e;this.ingestKey=t;this.session=null;this.identityToken=null}setSession(e){this.session=e}async send(e,t=[],o){var c,l,h;let r={idempotencyKey:(c=e.idempotencyKey)!=null?c:te(),...e,attachments:[...(l=e.attachments)!=null?l:[],...t.map(p=>({filename:p.filename,contentType:p.contentType,size:p.blob.size}))]},i=await this.post("/ingest/v1",r);if(!i.ok)throw await E(i);let s=await i.json(),a=((h=e.attachments)!=null?h:[]).length;return await Promise.all(t.map(async(p,g)=>{let b=Me(s,a+g);if(!b){o==null||o(p,new Error("The server would not accept that file."));return}try{await this.upload(b,p)}catch(w){o==null||o(p,w)}})),s}async flush(){let e=oe();if(e.length!==0){re([]);for(let t of e)try{let o=await this.post("/ingest/v1",t);!o.ok&&(o.status===429||o.status>=500)&&O(t)}catch{O(t)}}}queue(e){var t;O({...e,idempotencyKey:(t=e.idempotencyKey)!=null?t:te(),attachments:void 0})}async signIn(){let e=ne(64),t=await Ae(e),o=ne(16),r=`${this.base()}/ingest/v1/authorize?key=${encodeURIComponent(this.ingestKey)}&origin=${encodeURIComponent(location.origin)}&code_challenge=${encodeURIComponent(t)}&state=${encodeURIComponent(o)}`,i=window.open(r,"daybook-feedback","width=460,height=640");if(!i)throw Object.assign(new Error("Popup blocked"),{code:"popup_blocked"});let s=await new Promise((l,h)=>{let p=setInterval(()=>{i.closed&&(b(),h(Object.assign(new Error("Sign-in cancelled"),{code:"cancelled"})))},400),g=w=>{if(w.origin!==new URL(this.base()).origin)return;let f=w.data;if((f==null?void 0:f.source)==="daybook-feedback"&&f.state===o){if(b(),f.error||!f.code){h(Object.assign(new Error("Sign-in was refused"),{code:f.error||"refused"}));return}l(f.code)}},b=()=>{clearInterval(p),window.removeEventListener("message",g)};window.addEventListener("message",g)}),a=await this.post("/ingest/v1/token",{code:s,codeVerifier:e});if(!a.ok)throw await E(a);let{identityToken:c}=await a.json();return this.identityToken=c,c}base(){return this.apiUrl.replace(/\/$/,"")}resolve(e){try{let t=new URL(this.base()),o=new URL(e,t);return o.hostname===t.hostname?new URL(o.pathname+o.search,t).toString():o.toString()}catch{return e}}async handshake(e){var r,i;let t=await this.post("/ingest/v1/session",{...e,identityToken:(r=this.identityToken)!=null?r:void 0});if(!t.ok)throw await E(t);let o=await t.json();return this.session=(i=o.sessionToken)!=null?i:null,o}post(e,t){let o={"Content-Type":"application/json","X-Ingest-Key":this.ingestKey};return this.session&&(o["X-Feedback-Session"]=this.session),fetch(`${this.base()}${e}`,{method:"POST",headers:o,body:JSON.stringify(t),credentials:"omit"})}async upload(e,t){let o=await fetch(this.resolve(e.uploadUrl),{method:e.method,headers:{"Content-Type":e.contentType,"X-Ingest-Key":this.ingestKey},body:t.blob,credentials:"omit"});if(!o.ok)throw await E(o);await this.post(`/ingest/v1/attachments/${e.id}/confirm`,{})}};function Me(n,e){let t=n.attachments.find(o=>o.index===e);return t!=null?t:n.attachments.some(o=>typeof o.index=="number")?void 0:n.attachments[e]}function O(n){let e=oe();e.push(n),re(e.slice(-20))}function oe(){try{let n=localStorage.getItem(j);return n?JSON.parse(n):[]}catch{return[]}}function re(n){try{n.length===0?localStorage.removeItem(j):localStorage.setItem(j,JSON.stringify(n))}catch{}}async function E(n){let e=`http_${n.status}`;try{let t=await n.json();if(t.code&&(e=t.code),t.message)return Object.assign(new Error(t.message),{code:e})}catch{}return Object.assign(new Error(`Ingest failed (${n.status})`),{code:e})}function te(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function ne(n){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",t=new Uint8Array(n);return crypto.getRandomValues(t),Array.from(t,o=>e[o%e.length]).join("")}async function Ae(n){let e=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(n));return btoa(String.fromCharCode(...new Uint8Array(e))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function q(n){var t;let e={platform:"web",route:location.pathname,title:document.title.slice(0,200),locale:navigator.language,timezone:He(),viewport:{width:window.innerWidth,height:window.innerHeight,dpr:(t=window.devicePixelRatio)!=null?t:1},device:Re()};return document.referrer&&(e.referrer=v(document.referrer)),n.app&&(e.app=n.app),n.anchor&&(e.anchor=n.anchor),n.breadcrumbs&&n.breadcrumbs.length>0&&(e.breadcrumbs=n.breadcrumbs),e}function Re(){var r;let n=navigator.userAgent,e=/Edg\//.test(n)?"Edge":/OPR\//.test(n)?"Opera":/Firefox\//.test(n)?"Firefox":/Chrome\//.test(n)?"Chrome":/Safari\//.test(n)?"Safari":"Unknown",t=/Windows NT/.test(n)?"Windows":/iPhone|iPad|iPod/.test(n)?"iOS":/Mac OS X/.test(n)?"macOS":/Android/.test(n)?"Android":/Linux/.test(n)?"Linux":"Unknown",o=(r=n.match(/(?:Edg|OPR|Firefox|Chrome|Version)\/(\d+)/))==null?void 0:r[1];return{browser:o?`${e} ${o}`:e,os:t,touch:navigator.maxTouchPoints>0,userAgent:n.slice(0,300)}}function He(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return`UTC${-new Date().getTimezoneOffset()/60}`}}async function ae(n,e=()=>()=>{}){var i;if(typeof((i=navigator.mediaDevices)==null?void 0:i.getDisplayMedia)!="function")return null;let t=n?Pe():()=>{},o=e(),r=null;try{return r=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1,preferCurrentTab:!0,selfBrowserSurface:"include",surfaceSwitching:"exclude",monitorTypeSurfaces:"exclude"}),r.getVideoTracks()[0]?(await new Promise(a=>setTimeout(a,250)),await Fe(r)):null}catch{return null}finally{r==null||r.getTracks().forEach(s=>s.stop()),o(),t()}}var ie=1920,Ce=.82;async function Fe(n){let e=document.createElement("video");e.srcObject=n,e.muted=!0,await e.play().catch(()=>{});let t=e.videoWidth||window.innerWidth,o=e.videoHeight||window.innerHeight,r=t>ie?ie/t:1,i=document.createElement("canvas");i.width=Math.round(t*r),i.height=Math.round(o*r);let s=i.getContext("2d");if(!s)return null;s.imageSmoothingQuality="high",s.drawImage(e,0,0,i.width,i.height),e.pause(),e.srcObject=null;let a=await Ie(i);if(!a)return null;let c=a.type||"image/png";return{blob:a,filename:`screenshot.${c==="image/webp"?"webp":c==="image/jpeg"?"jpg":"png"}`,contentType:c}}async function Ie(n){for(let e of["image/webp","image/jpeg"]){let t=await se(n,e,Ce);if((t==null?void 0:t.type)===e)return t}return se(n,"image/png")}function se(n,e,t){return new Promise(o=>n.toBlob(r=>o(r),e,t))}function Pe(){let n=[...document.querySelectorAll(`[${Z}]`),...document.querySelectorAll('input[type="password"]')],e=n.map(t=>t.style.filter);return n.forEach(t=>{t.style.filter="blur(12px)"}),()=>{n.forEach((t,o)=>{var r;t.style.filter=(r=e[o])!=null?r:""})}}function _(n,e){let t=document.elementFromPoint(n,e);if(!(t instanceof HTMLElement))return{selector:null,offsetX:L(n/window.innerWidth),offsetY:L(e/window.innerHeight),elementText:null};let o=t.getBoundingClientRect();return{selector:Be(t),offsetX:o.width>0?L((n-o.left)/o.width):0,offsetY:o.height>0?L((e-o.top)/o.height):0,elementText:Oe(t)}}function le(n){if(!n.selector)return{x:n.offsetX*window.innerWidth,y:n.offsetY*window.innerHeight};let e=null;try{e=document.querySelector(n.selector)}catch{return null}if(!e)return null;let t=e.getBoundingClientRect();return{x:t.left+n.offsetX*t.width,y:t.top+n.offsetY*t.height}}function Be(n){if(n===document.body)return"body";for(let r of["data-testid","data-test","data-daybook-id","data-cy"]){let i=n.getAttribute(r);if(i){let s=`[${r}="${U(i)}"]`;if(S(s))return s}}if(n.id&&!ce(n.id)){let r=`#${U(n.id)}`;if(S(r))return r}let e=[],t=n;for(;t&&t!==document.body&&e.length<8;){let r=t.tagName.toLowerCase(),i=Array.from(t.classList).filter(c=>!ce(c)).slice(0,2);i.length>0&&(r+=i.map(c=>`.${U(c)}`).join(""));let s=t.parentElement;if(s){let c=Array.from(s.children).filter(l=>l.tagName===t.tagName);c.length>1&&(r+=`:nth-of-type(${c.indexOf(t)+1})`)}e.unshift(r);let a=e.join(" > ");if(S(a))return a;t=s}let o=e.length>0?`body > ${e.join(" > ")}`:null;return o&&S(o)?o:null}function S(n){try{return document.querySelectorAll(n).length===1}catch{return!1}}function ce(n){return/^[a-z]{1,3}[0-9a-f]{5,}$/i.test(n)||/--[0-9a-f]{5,}$/i.test(n)||/^_[0-9a-z]{5,}/i.test(n)||/^v-[0-9a-f]{6,}$/i.test(n)||/^ng-/.test(n)||/[0-9a-f]{8,}/i.test(n)}function Oe(n){var o,r,i;let t=((r=(o=n.innerText)!=null?o:n.textContent)!=null?r:"").replace(/\s+/g," ").trim();if(!t){let s=(i=n.getAttribute("aria-label"))!=null?i:n.getAttribute("title");return(s==null?void 0:s.trim())||null}return t.length>80?`${t.slice(0,77)}\u2026`:t}function L(n){return Number.isFinite(n)?Math.max(0,Math.min(1,n)):0}function U(n){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(n):n.replace(/([^\w-])/g,"\\$1")}var je=/^(image\/(png|jpeg|gif|webp)|video\/(mp4|quicktime|webm))$/;function de(n,e){let t=[];for(let o of n){if(e+t.length>=5)break;let r=je.test(o.type)?o.size>26214400?`Too large (${(o.size/1048576).toFixed(1)} MB, max 25).`:null:"Only images and short videos.";t.push({blob:o,filename:o.name||`pasted-${t.length+1}.${qe(o.type)}`,contentType:o.type,preview:r?null:URL.createObjectURL(o),error:r})}return t}function pe(n){var o;let e=(o=n.clipboardData)==null?void 0:o.items;if(!e)return[];let t=[];for(let r of e){if(r.kind!=="file")continue;let i=r.getAsFile();i&&t.push(i)}return t}function $(n){for(let e of n)e.preview&&URL.revokeObjectURL(e.preview)}function qe(n){var e,t;return(t=(e=n.split("/")[1])==null?void 0:e.replace("quicktime","mov"))!=null?t:"bin"}function he(n){var o;let t=(o=(typeof n.composedPath=="function"?n.composedPath():[])[0])!=null?o:n.target;return!t||t.nodeType!==1?!1:/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)?!0:typeof t.closest=="function"&&t.closest('[contenteditable=""], [contenteditable="true"]')!==null}function Ue(n,e,t){let o=0;for(let s of e){if(s.right<=n.left||s.left>=n.right)continue;let a=n.v==="bottom"?t.height-s.top:s.bottom;a>o&&(o=a)}if(o===0)return 0;let r=n.v==="bottom"?t.height-n.bottom:n.top,i=Math.round(o+12-r);return i<=0||i>t.height*.35?0:i}function ze(n,e,t){if(n===e||e.contains(n)||n.contains(e)||n===document.body||n===document.documentElement)return!1;let o=getComputedStyle(n);if(o.position!=="fixed"&&o.position!=="sticky"||o.visibility==="hidden"||o.display==="none"||Number(o.opacity)===0)return!1;let r=n.getBoundingClientRect();return!(r.width<8||r.height<8||r.width*r.height>t.width*t.height*.25)}function Ne(n,e,t){if(typeof document.elementsFromPoint!="function")return[];let o=new Map,r=[];for(let s=n.left+4;s<n.right;s+=32)r.push(s);r.push(n.right-4);let i=t.height*.35;for(let s=0;s<=i;s+=32){let a=n.v==="bottom"?n.bottom-s:n.top+s;if(a<0||a>t.height)break;for(let c of r)if(!(c<0||c>t.width))for(let l of document.elementsFromPoint(c,a)){if(o.has(l)||!ze(l,e,t))continue;let h=l.getBoundingClientRect();o.set(l,{top:h.top,bottom:h.bottom,left:h.left,right:h.right})}}return[...o.values()]}function ue(n,e){let t={width:window.innerWidth,height:window.innerHeight};return Ue(n,Ne(n,e,t),t)}var R=class{constructor(e,t){this.options=e;this.onSubmit=t;this.mode="idle";this.anchor=null;this.detach=[];this.buttonStyle="pill";this.clearance=0;this.state="ready";this.policy=null;this.dragged=null;this.reference=null;this.uploadsFailed=0;this.host=document.createElement("div"),this.host.setAttribute("data-daybook-feedback",""),this.host.style.cssText="position:fixed;inset:0;z-index:2147483000;pointer-events:none",this.root=this.host.attachShadow({mode:"open"}),this.root.innerHTML=`<style>${xe}</style><style id="theme"></style><style id="place"></style><div id="layer"></div>`}setTheme(e){let t=this.root.getElementById("theme");if(t){if(!e){t.textContent="";return}t.textContent=fe(e),this.buttonStyle=ge(e),this.themePlacement=e.position,this.applyPlacement(),this.launcherLabel=typeof e.launcherLabel=="string"&&e.launcherLabel.length>0?e.launcherLabel.slice(0,24):void 0}}get placement(){var e,t;return(t=(e=this.options.placement)!=null?e:this.themePlacement)!=null?t:"bottom-right"}applyPlacement(){let e=this.root.getElementById("place");if(!e)return;let t=this.placement,o=t.startsWith("bottom")?"bottom":"top",r=t.endsWith("right")?"right":"left",i=m+this.clearance;e.textContent=`:host {
|
|
2
|
-
|
|
1
|
+
"use strict";var DaybookFeedback=(()=>{var P=Object.defineProperty;var Ce=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames;var Ie=Object.prototype.hasOwnProperty;var Fe=(n,e)=>{for(var t in e)P(n,t,{get:e[t],enumerable:!0})},Pe=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of He(e))!Ie.call(n,r)&&r!==t&&P(n,r,{get:()=>e[r],enumerable:!(o=Ce(e,r))||o.enumerable});return n};var je=n=>Pe(P({},"__esModule",{value:!0}),n);var gt={};Fe(gt,{DEFAULT_API_URL:()=>Re,DaybookFeedback:()=>I,captureAnchor:()=>$,init:()=>mt,previewLauncher:()=>_e,resolveAnchor:()=>ye});function x(n){var e;try{let t=new URL(n,location.href);return t.origin===location.origin?t.pathname:`${t.origin}${t.pathname}`}catch{return(e=n.split("?")[0])!=null?e:n}}var Be=/pass|secret|token|auth|cvv|card|ssn|pin|otp|key/i;function ne(n,e){return n.length===0?"":e&&Be.test(e)?"[redacted]":`[${n.length} chars]`}function j(n){var o,r,i,s,a,c;let e=n.tagName.toLowerCase();if(!n.getAttribute("aria-label")&&!n.getAttribute("data-testid")&&!((o=n.textContent)!=null?o:"").trim()){let l=n.closest("button, a, [role=button], [data-testid], label");if(l&&l!==n)return j(l)}if(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement||n instanceof HTMLSelectElement){let l=(i=(r=n.getAttribute("name"))!=null?r:n.id)!=null?i:"",u=n instanceof HTMLInputElement?n.type:e;return`${e}[${u}]${l?` name=${l}`:""}`}let t=(c=(s=n.getAttribute("aria-label"))!=null?s:n.getAttribute("data-testid"))!=null?c:((a=n.textContent)!=null?a:"").replace(/\s+/g," ").trim().slice(0,40);return t?`${e} "${t}"`:e}function oe(n){return n.replace(/[\w.+-]+@[\w-]+\.[\w.]+/g,"[email]").replace(/\b[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g,"[jwt]").replace(/\bBearer\s+[\w.-]+/gi,"Bearer [redacted]").replace(/\b\d{12,19}\b/g,"[number]").slice(0,500)}var k="data-daybook-private";var T=class{constructor(e=40,t=!0){this.limit=e;this.redact=t;this.entries=[];this.detach=[]}list(){return[...this.entries]}add(e,t){for(this.entries.push({at:new Date().toISOString(),type:e,message:this.redact?oe(t):t.slice(0,500)});this.entries.length>this.limit;)this.entries.shift()}start(){let e=a=>{let c=a.target;c instanceof Element&&(c.closest("[data-daybook-feedback]")||this.add("click",j(c)))};document.addEventListener("click",e,{capture:!0,passive:!0}),this.detach.push(()=>document.removeEventListener("click",e,{capture:!0}));let t=history.pushState,o=history.replaceState,r=()=>this.add("nav",x(location.href));history.pushState=(...a)=>{t.apply(history,a),r()},history.replaceState=(...a)=>{o.apply(history,a),r()},window.addEventListener("popstate",r),this.detach.push(()=>{history.pushState=t,history.replaceState=o,window.removeEventListener("popstate",r)});for(let a of["error","warn"]){let c=console[a];console[a]=(...l)=>{this.add("console",`${a}: ${l.map(B).join(" ")}`),c.apply(console,l)},this.detach.push(()=>{console[a]=c})}let i=a=>this.add("console",`uncaught: ${a.message}`),s=a=>this.add("console",`unhandled rejection: ${B(a.reason)}`);window.addEventListener("error",i),window.addEventListener("unhandledrejection",s),this.detach.push(()=>{window.removeEventListener("error",i),window.removeEventListener("unhandledrejection",s)}),this.watchFetch()}stop(){for(let e of this.detach.splice(0))e()}watchFetch(){if(typeof window.fetch!="function")return;let e=window.fetch;window.fetch=async(...t)=>{let o=performance.now();try{let r=await e.apply(window,t),i=Math.round(performance.now()-o);return(!r.ok||i>3e3)&&this.add("network",`${r.status} ${x(re(t[0]))} ${i}ms`),r}catch(r){throw this.add("network",`failed ${x(re(t[0]))}: ${B(r)}`),r}},this.detach.push(()=>{window.fetch=e})}};function re(n){return typeof n=="string"?n:n instanceof URL?n.href:n.url}function B(n){var e,t;if(typeof n=="string")return n;if(n instanceof Error)return`${n.name}: ${n.message}`;try{return(t=(e=JSON.stringify(n))==null?void 0:e.slice(0,200))!=null?t:String(n)}catch{return String(n)}}var q="pm.feedback.queue";var L=class{constructor(e,t){this.apiUrl=e;this.ingestKey=t;this.session=null;this.identityToken=null}setSession(e){this.session=e}async send(e,t=[],o){var c,l,u;let r={idempotencyKey:(c=e.idempotencyKey)!=null?c:ie(),...e,attachments:[...(l=e.attachments)!=null?l:[],...t.map(h=>({filename:h.filename,contentType:h.contentType,size:h.blob.size}))]},i=await this.post("/ingest/v1",r);if(!i.ok)throw await S(i);let s=await i.json(),a=((u=e.attachments)!=null?u:[]).length;return await Promise.all(t.map(async(h,d)=>{let m=Oe(s,a+d);if(!m){o==null||o(h,new Error("The server would not accept that file."));return}try{await this.upload(m,h)}catch(y){o==null||o(h,y)}})),s}async flush(){let e=ae();if(e.length!==0){ce([]);for(let t of e)try{let o=await this.post("/ingest/v1",t);!o.ok&&(o.status===429||o.status>=500)&&O(t)}catch{O(t)}}}queue(e){var t;O({...e,idempotencyKey:(t=e.idempotencyKey)!=null?t:ie(),attachments:void 0})}async signIn(){let e=se(64),t=await qe(e),o=se(16),r=`${this.base()}/ingest/v1/authorize?key=${encodeURIComponent(this.ingestKey)}&origin=${encodeURIComponent(location.origin)}&code_challenge=${encodeURIComponent(t)}&state=${encodeURIComponent(o)}`,i=window.open(r,"daybook-feedback","width=460,height=640");if(!i)throw Object.assign(new Error("Popup blocked"),{code:"popup_blocked"});let s=await new Promise((l,u)=>{let h=setInterval(()=>{i.closed&&(m(),u(Object.assign(new Error("Sign-in cancelled"),{code:"cancelled"})))},400),d=y=>{if(y.origin!==new URL(this.base()).origin)return;let b=y.data;if((b==null?void 0:b.source)==="daybook-feedback"&&b.state===o){if(m(),b.error||!b.code){u(Object.assign(new Error("Sign-in was refused"),{code:b.error||"refused"}));return}l(b.code)}},m=()=>{clearInterval(h),window.removeEventListener("message",d)};window.addEventListener("message",d)}),a=await this.post("/ingest/v1/token",{code:s,codeVerifier:e});if(!a.ok)throw await S(a);let{identityToken:c}=await a.json();return this.identityToken=c,c}base(){return this.apiUrl.replace(/\/$/,"")}resolve(e){try{let t=new URL(this.base()),o=new URL(e,t);return o.hostname===t.hostname?new URL(o.pathname+o.search,t).toString():o.toString()}catch{return e}}async handshake(e){var r,i;let t=await this.post("/ingest/v1/session",{...e,identityToken:(r=this.identityToken)!=null?r:void 0});if(!t.ok)throw await S(t);let o=await t.json();return this.session=(i=o.sessionToken)!=null?i:null,o}post(e,t){let o={"Content-Type":"application/json","X-Ingest-Key":this.ingestKey};return this.session&&(o["X-Feedback-Session"]=this.session),fetch(`${this.base()}${e}`,{method:"POST",headers:o,body:JSON.stringify(t),credentials:"omit"})}async upload(e,t){let o=await fetch(this.resolve(e.uploadUrl),{method:e.method,headers:{"Content-Type":e.contentType,"X-Ingest-Key":this.ingestKey},body:t.blob,credentials:"omit"});if(!o.ok)throw await S(o);await this.post(`/ingest/v1/attachments/${e.id}/confirm`,{})}};function Oe(n,e){let t=n.attachments.find(o=>o.index===e);return t!=null?t:n.attachments.some(o=>typeof o.index=="number")?void 0:n.attachments[e]}function O(n){let e=ae();e.push(n),ce(e.slice(-20))}function ae(){try{let n=localStorage.getItem(q);return n?JSON.parse(n):[]}catch{return[]}}function ce(n){try{n.length===0?localStorage.removeItem(q):localStorage.setItem(q,JSON.stringify(n))}catch{}}async function S(n){let e=`http_${n.status}`;try{let t=await n.json();if(t.code&&(e=t.code),t.message)return Object.assign(new Error(t.message),{code:e})}catch{}return Object.assign(new Error(`Ingest failed (${n.status})`),{code:e})}function ie(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function se(n){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",t=new Uint8Array(n);return crypto.getRandomValues(t),Array.from(t,o=>e[o%e.length]).join("")}async function qe(n){let e=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(n));return btoa(String.fromCharCode(...new Uint8Array(e))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function U(n){var t;let e={platform:"web",route:location.pathname,title:document.title.slice(0,200),locale:navigator.language,timezone:Ne(),viewport:{width:window.innerWidth,height:window.innerHeight,dpr:(t=window.devicePixelRatio)!=null?t:1},device:Ue()};return document.referrer&&(e.referrer=x(document.referrer)),n.app&&(e.app=n.app),n.anchor&&(e.anchor=n.anchor),n.breadcrumbs&&n.breadcrumbs.length>0&&(e.breadcrumbs=n.breadcrumbs),e}function Ue(){var r;let n=navigator.userAgent,e=/Edg\//.test(n)?"Edge":/OPR\//.test(n)?"Opera":/Firefox\//.test(n)?"Firefox":/Chrome\//.test(n)?"Chrome":/Safari\//.test(n)?"Safari":"Unknown",t=/Windows NT/.test(n)?"Windows":/iPhone|iPad|iPod/.test(n)?"iOS":/Mac OS X/.test(n)?"macOS":/Android/.test(n)?"Android":/Linux/.test(n)?"Linux":"Unknown",o=(r=n.match(/(?:Edg|OPR|Firefox|Chrome|Version)\/(\d+)/))==null?void 0:r[1];return{browser:o?`${e} ${o}`:e,os:t,touch:navigator.maxTouchPoints>0,userAgent:n.slice(0,300)}}function Ne(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return`UTC${-new Date().getTimezoneOffset()/60}`}}async function pe(n,e=()=>()=>{}){var i;if(typeof((i=navigator.mediaDevices)==null?void 0:i.getDisplayMedia)!="function")return null;let t=n?Ke():()=>{},o=e(),r=null;try{return r=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1,preferCurrentTab:!0,selfBrowserSurface:"include",surfaceSwitching:"exclude",monitorTypeSurfaces:"exclude"}),r.getVideoTracks()[0]?(await new Promise(a=>setTimeout(a,250)),await De(r)):null}catch{return null}finally{r==null||r.getTracks().forEach(s=>s.stop()),o(),t()}}var le=1920,ze=.82;async function De(n){let e=document.createElement("video");e.srcObject=n,e.muted=!0,await e.play().catch(()=>{});let t=e.videoWidth||window.innerWidth,o=e.videoHeight||window.innerHeight,r=t>le?le/t:1,i=document.createElement("canvas");i.width=Math.round(t*r),i.height=Math.round(o*r);let s=i.getContext("2d");if(!s)return null;s.imageSmoothingQuality="high",s.drawImage(e,0,0,i.width,i.height),e.pause(),e.srcObject=null;let a=await Xe(i);if(!a)return null;let c=a.type||"image/png";return{blob:a,filename:`screenshot.${c==="image/webp"?"webp":c==="image/jpeg"?"jpg":"png"}`,contentType:c}}async function Xe(n){for(let e of["image/webp","image/jpeg"]){let t=await de(n,e,ze);if((t==null?void 0:t.type)===e)return t}return de(n,"image/png")}function de(n,e,t){return new Promise(o=>n.toBlob(r=>o(r),e,t))}function Ke(){let n=[...document.querySelectorAll(`[${k}]`),...document.querySelectorAll('input[type="password"]')],e=n.map(t=>t.style.filter);return n.forEach(t=>{t.style.filter="blur(12px)"}),()=>{n.forEach((t,o)=>{var r;t.style.filter=(r=e[o])!=null?r:""})}}var z=4e5,ue=300,he=600,me=8e3,We=new Set(["SCRIPT","NOSCRIPT","TEMPLATE"]),Ve=["display","position","z-index","opacity","visibility","overflow","width","height","margin","padding","box-sizing","color","background-color","border","border-radius","box-shadow","font-family","font-size","font-weight","line-height","text-align","white-space","flex-direction","justify-content","align-items","gap","grid-template-columns","transform","transition","pointer-events","cursor"],Ye="The page at the moment this was reported. Field values are described rather than reproduced when redacted is true, and data-daybook-private subtrees are withheld. html is last because only the head of this file is inlined beside the report \u2014 download the attachment for the rest of it.";function D(n){let e=[],t=n;for(let o=0;t&&o<4&&t.nodeType===1;o+=1){let r=t.localName;if(t.id){e.unshift(`${r}#${t.id}`);break}let i=Array.from(t.classList).slice(0,3).join(".");i&&(r+=`.${i}`),e.unshift(r),t=t.parentElement}return e.join(" > ")}var Je=(n,e)=>e.length>ue?`${e.slice(0,ue)}\u2026[${e.length}]`:e,N=n=>n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function Qe(n,e){let t=n;if(n.localName==="input"&&(t.type==="checkbox"||t.type==="radio"))return t.checked?"checked":"unchecked";let o=t.value;return typeof o!="string"||o===""?null:e?ne(o,t.name||t.id||t.type):o}function fe(n,e,t,o){var u,h;if(t.used>z)return!1;if(n.nodeType===3){let d=((u=n.textContent)!=null?u:"").replace(/\s+/g," ");if(!d.trim())return!0;let m=d.length>he?`${d.slice(0,he)}\u2026`:d;return e.push(N(m)),t.used+=m.length,!0}if(n.nodeType!==1)return!0;let r=n,i=r.tagName;if(r.hasAttribute("data-daybook-feedback")||We.has(i))return!0;let s=r.localName;if(o&&r.hasAttribute(k))return e.push(`<${s} ${k}>[withheld]</${s}>`),t.used+=32,!0;let a=[];for(let d of Array.from(r.attributes))d.name!=="value"&&a.push(`${d.name}="${N(Je(d.name,d.value))}"`);let c=Qe(r,o);c!==null&&a.push(`value="${N(c)}"`);let l=a.length>0?`<${s} ${a.join(" ")}>`:`<${s}>`;if(e.push(l),t.used+=l.length,s==="style"){let d=(h=r.textContent)!=null?h:"",m=d.length>me?`${d.slice(0,me)}
|
|
2
|
+
/* \u2026${d.length} chars */`:d;e.push(m),t.used+=m.length}else for(let d of Array.from(r.childNodes))if(!fe(d,e,t,o))break;return e.push(`</${s}>`),t.used+=s.length+3,t.used<=z}function Ge(){var e,t;let n=[];for(let o of Array.from((t=(e=document.body)==null?void 0:e.querySelectorAll("*"))!=null?t:[]).slice(0,4e3)){let r=getComputedStyle(o);if(r.position!=="fixed"&&r.position!=="sticky"||r.visibility==="hidden"||r.display==="none"||Number(r.opacity)===0)continue;let i=o.getBoundingClientRect();if(!(i.width<4||i.height<4)&&!o.closest("[data-daybook-feedback]")&&(n.push({selector:D(o),zIndex:r.zIndex,rect:{x:Math.round(i.x),y:Math.round(i.y),w:Math.round(i.width),h:Math.round(i.height)}}),n.length>=20))break}return n}function Ze(n){if(!(n!=null&&n.selector))return;let e=null;try{e=document.querySelector(n.selector)}catch{return}if(!e)return;let t=[];for(let o=e;o&&t.length<5;o=o.parentElement){let r=getComputedStyle(o),i={};for(let s of Ve){let a=r.getPropertyValue(s);a&&(i[s]=a)}t.push({selector:D(o),computed:i})}return{selector:n.selector,path:t}}function et(){return Array.from(document.styleSheets).slice(0,40).map(n=>{try{return{href:n.href,rules:n.cssRules.length}}catch{return{href:n.href,rules:"unreadable"}}})}function ge(n,e){try{let t=[],o={used:0};return fe(document.documentElement,t,o,e),{note:Ye,capturedAtUtc:new Date().toISOString(),url:location.href,title:document.title,redacted:e,truncated:o.used>z,scroll:{x:Math.round(window.scrollX),y:Math.round(window.scrollY)},focus:document.activeElement&&document.activeElement!==document.body?D(document.activeElement):null,anchor:Ze(n),layers:Ge(),stylesheets:et(),html:t.join("")}}catch{return null}}function $(n,e){let t=document.elementFromPoint(n,e);if(!(t instanceof HTMLElement))return{selector:null,offsetX:A(n/window.innerWidth),offsetY:A(e/window.innerHeight),elementText:null};let o=t.getBoundingClientRect();return{selector:tt(t),offsetX:o.width>0?A((n-o.left)/o.width):0,offsetY:o.height>0?A((e-o.top)/o.height):0,elementText:nt(t)}}function ye(n){if(!n.selector)return{x:n.offsetX*window.innerWidth,y:n.offsetY*window.innerHeight};let e=null;try{e=document.querySelector(n.selector)}catch{return null}if(!e)return null;let t=e.getBoundingClientRect();return{x:t.left+n.offsetX*t.width,y:t.top+n.offsetY*t.height}}function tt(n){if(n===document.body)return"body";for(let r of["data-testid","data-test","data-daybook-id","data-cy"]){let i=n.getAttribute(r);if(i){let s=`[${r}="${X(i)}"]`;if(_(s))return s}}if(n.id&&!be(n.id)){let r=`#${X(n.id)}`;if(_(r))return r}let e=[],t=n;for(;t&&t!==document.body&&e.length<8;){let r=t.tagName.toLowerCase(),i=Array.from(t.classList).filter(c=>!be(c)).slice(0,2);i.length>0&&(r+=i.map(c=>`.${X(c)}`).join(""));let s=t.parentElement;if(s){let c=Array.from(s.children).filter(l=>l.tagName===t.tagName);c.length>1&&(r+=`:nth-of-type(${c.indexOf(t)+1})`)}e.unshift(r);let a=e.join(" > ");if(_(a))return a;t=s}let o=e.length>0?`body > ${e.join(" > ")}`:null;return o&&_(o)?o:null}function _(n){try{return document.querySelectorAll(n).length===1}catch{return!1}}function be(n){return/^[a-z]{1,3}[0-9a-f]{5,}$/i.test(n)||/--[0-9a-f]{5,}$/i.test(n)||/^_[0-9a-z]{5,}/i.test(n)||/^v-[0-9a-f]{6,}$/i.test(n)||/^ng-/.test(n)||/[0-9a-f]{8,}/i.test(n)}function nt(n){var o,r,i;let t=((r=(o=n.innerText)!=null?o:n.textContent)!=null?r:"").replace(/\s+/g," ").trim();if(!t){let s=(i=n.getAttribute("aria-label"))!=null?i:n.getAttribute("title");return(s==null?void 0:s.trim())||null}return t.length>80?`${t.slice(0,77)}\u2026`:t}function A(n){return Number.isFinite(n)?Math.max(0,Math.min(1,n)):0}function X(n){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(n):n.replace(/([^\w-])/g,"\\$1")}var ot=/^(image\/(png|jpeg|gif|webp)|video\/(mp4|quicktime|webm))$/;function we(n,e){let t=[];for(let o of n){if(e+t.length>=5)break;let r=ot.test(o.type)?o.size>26214400?`Too large (${(o.size/1048576).toFixed(1)} MB, max 25).`:null:"Only images and short videos.";t.push({blob:o,filename:o.name||`pasted-${t.length+1}.${rt(o.type)}`,contentType:o.type,preview:r?null:URL.createObjectURL(o),error:r})}return t}function ve(n){var o;let e=(o=n.clipboardData)==null?void 0:o.items;if(!e)return[];let t=[];for(let r of e){if(r.kind!=="file")continue;let i=r.getAsFile();i&&t.push(i)}return t}function M(n){for(let e of n)e.preview&&URL.revokeObjectURL(e.preview)}function rt(n){var e,t;return(t=(e=n.split("/")[1])==null?void 0:e.replace("quicktime","mov"))!=null?t:"bin"}function xe(n){var o;let t=(o=(typeof n.composedPath=="function"?n.composedPath():[])[0])!=null?o:n.target;return!t||t.nodeType!==1?!1:/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)?!0:typeof t.closest=="function"&&t.closest('[contenteditable=""], [contenteditable="true"]')!==null}function it(n,e,t){let o=0;for(let s of e){if(s.right<=n.left||s.left>=n.right)continue;let a=n.v==="bottom"?t.height-s.top:s.bottom;a>o&&(o=a)}if(o===0)return 0;let r=n.v==="bottom"?t.height-n.bottom:n.top,i=Math.round(o+12-r);return i<=0||i>t.height*.35?0:i}function st(n,e,t){if(n===e||e.contains(n)||n.contains(e)||n===document.body||n===document.documentElement)return!1;let o=getComputedStyle(n);if(o.position!=="fixed"&&o.position!=="sticky"||o.visibility==="hidden"||o.display==="none"||Number(o.opacity)===0)return!1;let r=n.getBoundingClientRect();return!(r.width<8||r.height<8||r.width*r.height>t.width*t.height*.25)}function at(n,e,t){if(typeof document.elementsFromPoint!="function")return[];let o=new Map,r=[];for(let s=n.left+4;s<n.right;s+=32)r.push(s);r.push(n.right-4);let i=t.height*.35;for(let s=0;s<=i;s+=32){let a=n.v==="bottom"?n.bottom-s:n.top+s;if(a<0||a>t.height)break;for(let c of r)if(!(c<0||c>t.width))for(let l of document.elementsFromPoint(c,a)){if(o.has(l)||!st(l,e,t))continue;let u=l.getBoundingClientRect();o.set(l,{top:u.top,bottom:u.bottom,left:u.left,right:u.right})}}return[...o.values()]}function ke(n,e){let t={width:window.innerWidth,height:window.innerHeight};return it(n,at(n,e,t),t)}var H=class{constructor(e,t){this.options=e;this.onSubmit=t;this.mode="idle";this.anchor=null;this.detach=[];this.buttonStyle="pill";this.clearance=0;this.state="ready";this.policy=null;this.dragged=null;this.reference=null;this.uploadsFailed=0;this.host=document.createElement("div"),this.host.setAttribute("data-daybook-feedback",""),this.host.style.cssText="position:fixed;inset:0;z-index:2147483000;pointer-events:none",this.root=this.host.attachShadow({mode:"open"}),this.root.innerHTML=`<style>${Me}</style><style id="theme"></style><style id="place"></style><div id="layer"></div>`}setTheme(e){let t=this.root.getElementById("theme");if(t){if(!e){t.textContent="";return}t.textContent=Te(e),this.buttonStyle=Se(e),this.themePlacement=e.position,this.applyPlacement(),this.launcherLabel=typeof e.launcherLabel=="string"&&e.launcherLabel.length>0?e.launcherLabel.slice(0,24):void 0}}get placement(){var e,t;return(t=(e=this.options.placement)!=null?e:this.themePlacement)!=null?t:"bottom-right"}applyPlacement(){let e=this.root.getElementById("place");if(!e)return;let t=this.placement,o=t.startsWith("bottom")?"bottom":"top",r=t.endsWith("right")?"right":"left",i=g+this.clearance;e.textContent=`:host {
|
|
3
|
+
--pm-${r}: ${g}px; --pm-${r==="right"?"left":"right"}: auto;
|
|
3
4
|
--pm-${o}: ${i}px; --pm-${o==="bottom"?"top":"bottom"}: auto;
|
|
4
|
-
}`}homeSlot(){let e=this.placement,t=220,o=48,r=e.endsWith("right")?window.innerWidth-
|
|
5
|
+
}`}homeSlot(){let e=this.placement,t=220,o=48,r=e.endsWith("right")?window.innerWidth-g:g+t,i=e.startsWith("bottom")?window.innerHeight-g:g+o;return{left:r-t,right:r,top:i-o,bottom:i,v:e.startsWith("bottom")?"bottom":"top"}}watchClearance(){if(this.options.avoidOverlap===!1)return;let e=!1,t=()=>{if(e=!1,this.mode==="idle")try{let i=ke(this.homeSlot(),this.host);if(Math.abs(i-this.clearance)<4)return;this.clearance=i,this.applyPlacement()}catch{}},o=typeof requestAnimationFrame=="function"?i=>requestAnimationFrame(i):i=>setTimeout(i,16),r=()=>{e||(e=!0,o(t))};if(window.addEventListener("scroll",r,{passive:!0,capture:!0}),window.addEventListener("resize",r),this.detach.push(()=>{window.removeEventListener("scroll",r,{capture:!0}),window.removeEventListener("resize",r)}),typeof MutationObserver=="function"){let i=new MutationObserver(r);i.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class","hidden"]}),this.detach.push(()=>i.disconnect())}r()}setState(e){this.state=e,this.host.isConnected&&this.render()}mount(){var e;if(document.body.appendChild(this.host),this.applyPlacement(),this.render(),this.watchClearance(),this.options.hotkey!==null){let t=((e=this.options.hotkey)!=null?e:"f").toLowerCase(),o=r=>{if(r.key==="Escape"){this.mode==="picking"&&(this.mode="idle",this.anchor=null,this.dragged=null,this.render());return}r.metaKey||r.ctrlKey||r.altKey||xe(r)||this.mode!=="composing"&&r.key.toLowerCase()===t&&(this.mode=this.mode==="picking"?"idle":"picking",this.render())};window.addEventListener("keydown",o),this.detach.push(()=>window.removeEventListener("keydown",o))}}unmount(){for(let e of this.detach.splice(0))e();this.host.remove()}open(){this.mode="picking",this.render()}setReporter(e){this.reporter=e}setPolicy(e){this.policy=e}capture(){var t,o;let e=(t=this.options.screenshots)!=null?t:!0;return e===!1||((o=this.policy)==null?void 0:o.screenshots)===!1?{offered:!1,checked:!1}:{offered:!0,checked:e!=="optional"}}conceal(){let e=this.root.getElementById("layer"),t=e.style.visibility;e.style.visibility="hidden";let o=this.ringAnchor();return()=>{e.style.visibility=t,o==null||o.remove()}}ringAnchor(){var i;let e=(i=this.anchor)==null?void 0:i.selector;if(!e)return null;let t=null;try{t=document.querySelector(e)}catch{return null}if(!t)return null;let o=t.getBoundingClientRect();if(o.width<1||o.height<1)return null;let r=document.createElement("div");return r.className="ring",r.style.left=`${o.left-R}px`,r.style.top=`${o.top-R}px`,r.style.width=`${o.width+R*2}px`,r.style.height=`${o.height+R*2}px`,this.root.appendChild(r),r}movable(e,t){this.place(e),t.classList.add("drag"),t.title="Drag to move \xB7 double-click to reset",t.addEventListener("dblclick",()=>{this.dragged=null,this.place(e)}),t.addEventListener("pointerdown",o=>{if(o.target.closest("button")||o.button!==0)return;o.preventDefault();let r=e.getBoundingClientRect(),i=o.clientX-r.left,s=o.clientY-r.top;t.setPointerCapture(o.pointerId),e.classList.add("panel--dragging");let a=l=>{let u=C(l.clientX-i,g-r.width+K,window.innerWidth-K),h=C(l.clientY-s,0,window.innerHeight-K);e.style.left=`${u}px`,e.style.top=`${h}px`,e.style.right="auto",e.style.bottom="auto"},c=()=>{t.releasePointerCapture(o.pointerId),t.removeEventListener("pointermove",a),t.removeEventListener("pointerup",c),t.removeEventListener("pointercancel",c),e.classList.remove("panel--dragging"),this.dragged=dt(e.getBoundingClientRect()),this.place(e)};t.addEventListener("pointermove",a),t.addEventListener("pointerup",c),t.addEventListener("pointercancel",c)})}place(e){let t=this.dragged;if(!t){e.style.left=e.style.right=e.style.top=e.style.bottom="";return}let o=e.offsetWidth||380,r=e.offsetHeight||240,i=C(t.dx,g,Math.max(g,window.innerWidth-o-g)),s=C(t.dy,g,Math.max(g,window.innerHeight-r-g));e.style.left=t.h==="left"?`${i}px`:"auto",e.style.right=t.h==="right"?`${i}px`:"auto",e.style.top=t.v==="top"?`${s}px`:"auto",e.style.bottom=t.v==="bottom"?`${s}px`:"auto"}render(){let e=this.root.getElementById("layer");if(e.innerHTML="",this.mode==="idle"){e.appendChild(this.state==="pending"?this.pending():this.launcher());return}if(this.mode==="sent"){this.dragged=null,e.appendChild(this.sent());return}if(this.mode==="picking"){e.appendChild(this.picker());return}let t=this.composer();e.appendChild(t),this.place(t)}pending(){let e=document.createElement("div");return e.className="launcher launcher--pending",e.setAttribute("role","status"),e.textContent="Feedback access pending approval",e}sent(){var c;let e=document.createElement("div");e.className="panel panel--sent",e.setAttribute("role","status");let t=this.reference,o=this.uploadsFailed;e.innerHTML=`
|
|
5
6
|
<div class="sent__tick" aria-hidden="true">✓</div>
|
|
6
7
|
<div class="sent__body">
|
|
7
8
|
<div class="panel__title">Thank you \u2014 that is on its way.</div>
|
|
8
9
|
${t?`<div class="sent__ref">
|
|
9
|
-
<code class="sent__id">${
|
|
10
|
+
<code class="sent__id">${W(t)}</code>
|
|
10
11
|
<button type="button" class="sent__copy" data-copy>Copy</button>
|
|
11
12
|
</div>
|
|
12
13
|
<div class="panel__anchor">Quote it if you follow it up.</div>`:""}
|
|
13
14
|
${o>0?`<div class="sent__warn">${o===1?"One attachment could not be uploaded.":`${o} attachments could not be uploaded.`} The report was filed without it.</div>`:""}
|
|
14
15
|
</div>
|
|
15
|
-
${t?'<button type="button" class="panel__close" data-dismiss aria-label="Dismiss">×</button>':""}`;let r=()=>{this.mode==="sent"&&(this.mode="idle",this.render())},i=window.setTimeout(r,o>0?2e4:t?12e3:6e3),s=()=>window.clearTimeout(i);if(this.detach.push(()=>window.clearTimeout(i)),this.contain(e),this.place(e),!t)return e;e.addEventListener("pointerenter",s),e.addEventListener("focusin",s),(c=e.querySelector("[data-dismiss]"))==null||c.addEventListener("click",r);let a=e.querySelector("[data-copy]");return a&&(a.onclick=async()=>{s();let l=await
|
|
16
|
+
${t?'<button type="button" class="panel__close" data-dismiss aria-label="Dismiss">×</button>':""}`;let r=()=>{this.mode==="sent"&&(this.mode="idle",this.render())},i=window.setTimeout(r,o>0?2e4:t?12e3:6e3),s=()=>window.clearTimeout(i);if(this.detach.push(()=>window.clearTimeout(i)),this.contain(e),this.place(e),!t)return e;e.addEventListener("pointerenter",s),e.addEventListener("focusin",s),(c=e.querySelector("[data-dismiss]"))==null||c.addEventListener("click",r);let a=e.querySelector("[data-copy]");return a&&(a.onclick=async()=>{s();let l=await lt(t);a.textContent=l?"Copied":"Copy failed",a.classList.toggle("sent__copy--done",l)}),e}launcher(){var t,o;let e=Le(this.buttonStyle,(t=this.launcherLabel)!=null?t:"Feedback");return e.title=this.options.hotkey===null?"Report a problem":`Report a problem (${((o=this.options.hotkey)!=null?o:"f").toUpperCase()})`,e.onclick=()=>{this.mode="picking",this.render()},e}picker(){let e=document.createElement("div");return e.className="mask",e.innerHTML='<div class="hint">Click the thing that is wrong \xB7 <kbd>Esc</kbd> to cancel</div>',e.onclick=t=>{e.style.pointerEvents="none",this.anchor=$(t.clientX,t.clientY),e.style.pointerEvents="",this.mode="composing",this.render()},e}composer(){var J,Q,G,Z,ee;let e=document.createElement("div");e.className="panel";let t=(J=this.anchor)!=null&&J.elementText?`on \u201C${this.anchor.elementText}\u201D`:(Q=this.anchor)!=null&&Q.selector?`on ${this.anchor.selector}`:"on this page",o=this.capture();e.innerHTML=`
|
|
16
17
|
<div class="panel__head" id="head">
|
|
17
18
|
<span class="panel__grip" aria-hidden="true">\u283F</span>
|
|
18
19
|
<div class="panel__heading">
|
|
19
|
-
<div class="panel__anchor">${
|
|
20
|
+
<div class="panel__anchor">${W(t)}</div>
|
|
20
21
|
<div class="panel__title">Report a problem</div>
|
|
21
22
|
</div>
|
|
22
23
|
<button id="close" class="panel__close" aria-label="Close">×</button>
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
what somebody came here to do is type.
|
|
31
32
|
-->
|
|
32
33
|
<div class="panel__kinds">
|
|
33
|
-
${["bug","idea","praise","question"].map((
|
|
34
|
+
${["bug","idea","praise","question"].map((p,f)=>`<button class="kind${f===0?" kind--on":""}" data-kind="${p}">${p}</button>`).join("")}
|
|
34
35
|
</div>
|
|
35
36
|
|
|
36
37
|
<input id="email" type="email" placeholder="Email (optional, so we can reply)" autocomplete="email" />
|
|
@@ -53,10 +54,10 @@
|
|
|
53
54
|
<div id="status" class="status"></div>
|
|
54
55
|
|
|
55
56
|
<div class="panel__foot">
|
|
56
|
-
<span class="panel__note">Sends
|
|
57
|
+
<span class="panel__note">Sends this page's contents, your browser, and recent errors.</span>
|
|
57
58
|
<button id="cancel" class="ghost">Cancel</button>
|
|
58
59
|
<button id="send" class="primary">Send</button>
|
|
59
|
-
</div>`;let r=[],i=e.querySelector("#files"),s=e.querySelector("#drop"),a=e.querySelector("#file"),c=()=>{i.innerHTML="",r.forEach((
|
|
60
|
+
</div>`;let r=[],i=e.querySelector("#files"),s=e.querySelector("#drop"),a=e.querySelector("#file"),c=()=>{i.innerHTML="",r.forEach((p,f)=>{var te;let w=document.createElement("div");w.className=p.error?"file file--bad":"file",w.innerHTML=p.preview?`<img src="${p.preview}" alt="" />`:'<span class="file__icon">\u25A6</span>';let F=document.createElement("span");F.className="file__name",F.textContent=(te=p.error)!=null?te:p.filename,w.appendChild(F);let E=document.createElement("button");E.className="link",E.textContent="\xD7",E.onclick=()=>{M([p]),r.splice(f,1),c()},w.appendChild(E),i.appendChild(w)}),s.style.display=r.length>=5?"none":""},l=p=>{r.push(...we(p,r.length)),c()};a.onchange=()=>{a.files&&l(a.files)},e.querySelector("#browse").onclick=()=>a.click(),e.addEventListener("paste",p=>{let f=ve(p);f.length>0&&(p.preventDefault(),l(f))}),s.addEventListener("dragover",p=>{p.preventDefault(),s.classList.add("drop--over")}),s.addEventListener("dragleave",()=>s.classList.remove("drop--over")),s.addEventListener("drop",p=>{var f,w;p.preventDefault(),s.classList.remove("drop--over"),l(Array.from((w=(f=p.dataTransfer)==null?void 0:f.files)!=null?w:[]))});let u="bug";e.querySelectorAll(".kind").forEach(p=>{p.onclick=()=>{var f;u=(f=p.dataset.kind)!=null?f:"bug",e.querySelectorAll(".kind").forEach(w=>w.classList.remove("kind--on")),p.classList.add("kind--on")}});let h=e.querySelector("#message"),d=e.querySelector("#email"),m=(ee=(G=this.reporter)==null?void 0:G.email)!=null?ee:(Z=this.options.reporter)==null?void 0:Z.email;m&&!d.value&&(d.value=m);let y=e.querySelector("#shot"),b=e.querySelector("#status"),v=e.querySelector("#send"),V=()=>{M(r),this.mode="idle",this.anchor=null,this.dragged=null,this.render()};e.querySelector("#cancel").onclick=V,e.querySelector("#close").onclick=V;let Y=async()=>{var p;if(!h.value.trim()){b.textContent="Say what happened first.";return}v.disabled=!0,b.textContent="Sending\u2026";try{let f=await this.onSubmit({message:h.value.trim(),kind:u,email:d.value.trim()||void 0,anchor:this.anchor,withScreenshot:(p=y==null?void 0:y.checked)!=null?p:!1,files:r.filter(w=>!w.error)});this.reference=f.reference,this.uploadsFailed=f.uploadsFailed,M(r),this.mode="sent",this.anchor=null,this.render()}catch(f){v.disabled=!1,b.textContent=f instanceof Error?`${f.message} \u2014 saved, will retry.`:"Failed, saved and will retry."}};return v.onclick=Y,h.onkeydown=p=>{(p.metaKey||p.ctrlKey)&&p.key==="Enter"&&Y()},setTimeout(()=>h.focus(),0),this.contain(e),this.movable(e,e.querySelector("#head")),e}contain(e){for(let t of["pointerdown","mousedown","click"])e.addEventListener(t,o=>o.stopPropagation())}};async function lt(n){var t;try{if((t=navigator.clipboard)!=null&&t.writeText)return await navigator.clipboard.writeText(n),!0}catch{}let e=document.createElement("textarea");e.value=n,e.setAttribute("readonly",""),e.style.cssText="position:fixed;top:0;left:0;width:1px;height:1px;opacity:0",document.body.appendChild(e);try{return e.select(),document.execCommand("copy")}catch{return!1}finally{e.remove()}}var g=16,R=3,K=56;function dt(n){let e={left:n.left,right:window.innerWidth-n.right,top:n.top,bottom:window.innerHeight-n.bottom},t=Object.keys(e).reduce((i,s)=>e[s]<e[i]?s:i),o=t==="left"||t==="right"?t:e.left<=e.right?"left":"right",r=t==="top"||t==="bottom"?t:e.top<=e.bottom?"top":"bottom";return{h:o,v:r,dx:t===o?g:Math.max(g,Math.round(e[o])),dy:t===r?g:Math.max(g,Math.round(e[r]))}}function C(n,e,t){return Math.min(Math.max(n,e),t)}function W(n){return n.replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[e])}function pt(n){return typeof n=="string"&&/^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%/]+\)|hsla?\([\d\s.,%/deg]+\)|[a-z]{3,20})$/i.test(n.trim())}var Ee='<svg class="launcher__icon" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path d="M2 6.2C2 4.4 3.4 3 5.2 3h5.6C12.6 3 14 4.4 14 6.2v2.6c0 1.8-1.4 3.2-3.2 3.2H7l-3 2.4v-2.5A3.2 3.2 0 0 1 2 8.8V6.2Z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>';function Te(n){var o;let e=[];pt(n.accent)&&e.push(`--pm-accent: ${n.accent}`);let t={none:"0",sm:"6px",md:"12px",lg:"18px"}[(o=n.cornerRadius)!=null?o:"md"];return t&&e.push(`--pm-radius: ${t}`),n.colorScheme==="dark"?e.push($e):n.colorScheme==="light"&&e.push(Ae),e.length>0?`:host { ${e.join("; ")} }`:""}var Se=n=>ut.includes(n.buttonStyle)?n.buttonStyle:"pill";function Le(n,e){let t=document.createElement("button");return t.className=`launcher launcher--${n}`,n==="icon"?(t.innerHTML=Ee,t.setAttribute("aria-label",e)):n==="pill-icon"?t.innerHTML=`${Ee}<span>${W(e)}</span>`:t.textContent=e,t}function _e(n,e={}){var i;let t=(i=n.shadowRoot)!=null?i:n.attachShadow({mode:"open"}),o=typeof e.launcherLabel=="string"&&e.launcherLabel.length>0?e.launcherLabel.slice(0,24):"Feedback";t.innerHTML=`<style>${Me}</style><style>${Te(e)}</style>`;let r=Le(Se(e),o);r.classList.add("launcher--preview"),r.disabled=!0,t.appendChild(r)}var ut=["pill","pill-icon","icon","text","outline"],Ae="--pm-surface: #fff; --pm-ink: #171717; --pm-muted: #525252; --pm-faint: #a3a3a3; --pm-line: #e5e5e5; --pm-line-strong: #d4d4d4; --pm-sunken: #f5f5f5; --pm-kbd: #404040; --pm-warn: #b45309; --pm-good: #047857; --pm-good-bg: #ecfdf5; --pm-good-line: #a7f3d0; --pm-accent: #171717; --pm-on-accent: #fafafa;",$e="--pm-surface: #1c1c1c; --pm-ink: #fafafa; --pm-muted: #a3a3a3; --pm-faint: #737373; --pm-line: #333; --pm-line-strong: #454545; --pm-sunken: #262626; --pm-kbd: #d4d4d4; --pm-warn: #fbbf24; --pm-good: #34d399; --pm-good-bg: #05271f; --pm-good-line: #065f46; --pm-accent: #fafafa; --pm-on-accent: #171717;",Me=`
|
|
60
61
|
/*
|
|
61
62
|
Every colour in this file is one of these, and there are two sets of them.
|
|
62
63
|
|
|
@@ -78,7 +79,7 @@
|
|
|
78
79
|
:host {
|
|
79
80
|
all: initial;
|
|
80
81
|
|
|
81
|
-
${
|
|
82
|
+
${Ae}
|
|
82
83
|
|
|
83
84
|
--pm-radius: 12px;
|
|
84
85
|
|
|
@@ -91,7 +92,7 @@
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
@media (prefers-color-scheme: dark) {
|
|
94
|
-
:host { ${
|
|
95
|
+
:host { ${$e} }
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
* { box-sizing: border-box; font-family: system-ui, -apple-system, sans-serif }
|
|
@@ -293,4 +294,4 @@ textarea:focus, input:focus { outline: 2px solid var(--pm-ink); outline-offset:
|
|
|
293
294
|
.file__icon { width: 28px; text-align: center }
|
|
294
295
|
.file__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
|
|
295
296
|
.link { border: 0; background: transparent; color: var(--pm-muted); cursor: pointer; font-size: 11px; text-decoration: underline }
|
|
296
|
-
`;var
|
|
297
|
+
`;var Re="https://api.daybook.team",I=class{constructor(e){this.options=e;this.widget=null;this.started=!1;this.inFlight=null;this.epoch=0;this.ready=null;this.stopped=!1;var t;if(!e.ingestKey)throw new Error("ingestKey is required");this.client=new L((t=e.apiUrl)!=null?t:Re,e.ingestKey),this.trail=e.breadcrumbs===!1?null:new T(40,e.redact!==!1)}start(){var e;return this.stopped=!1,(e=this.trail)==null||e.start(),this.mount(),this.started||(this.started=!0,this.client.flush()),this.handshake(),this}mount(){this.widget||this.stopped||(this.widget=new H(this.options,e=>this.submit(e)),this.widget.setReporter(this.options.reporter),this.widget.mount())}handshake(){var o,r,i;let e=JSON.stringify([(o=this.options.reporter)!=null?o:null,(r=this.options.signature)!=null?r:null,this.epoch]);if(((i=this.inFlight)==null?void 0:i.key)===e)return this.inFlight.promise;let t=this.runHandshake().finally(()=>{var s;((s=this.inFlight)==null?void 0:s.promise)===t&&(this.inFlight=null)});return this.inFlight={key:e,promise:t},t}async runHandshake(){var e,t,o,r,i,s,a;try{let c=await this.client.handshake({identity:this.options.reporter,signature:this.options.signature,locale:typeof navigator!="undefined"?navigator.language:void 0});if(this.ready=c,(t=(e=this.options).onReady)==null||t.call(e,c),c.reporterStatus==="Blocked"){(o=this.widget)==null||o.unmount(),this.widget=null;return}this.mount(),this.widget.setTheme(ft(c.theme)),this.widget.setPolicy((r=c.policy)!=null?r:null),this.widget.setState(c.reporterStatus==="Pending"?"pending":"ready")}catch(c){(s=(i=this.options).onError)==null||s.call(i,c),console.warn("[feedback] handshake failed; the widget will not appear",c),(a=this.widget)==null||a.unmount(),this.widget=null}}identify(e){var t;this.options={...this.options,reporter:e?{...this.options.reporter,...e}:void 0},(t=this.widget)==null||t.setReporter(this.options.reporter),this.widget&&this.handshake()}async signIn(){await this.client.signIn(),this.epoch++,await this.handshake()}authenticate(e){this.options={...this.options,signature:e!=null?e:void 0},this.widget&&this.handshake()}stop(){var e,t;this.started=!1,this.stopped=!0,(e=this.trail)==null||e.stop(),(t=this.widget)==null||t.unmount(),this.widget=null}open(){var e;(e=this.widget)==null||e.open()}async report(e,t={}){var o,r,i;return this.client.send({message:e,surface:this.options.surface,...t,context:{...U({breadcrumbs:(o=this.trail)==null?void 0:o.list(),app:this.options.app}),...(r=t.context)!=null?r:{}},reporter:(i=t.reporter)!=null?i:this.options.reporter})}async submit(e){var a,c,l,u,h;let t=e.withScreenshot?await pe(this.options.redact!==!1,()=>{var d,m;return(m=(d=this.widget)==null?void 0:d.conceal())!=null?m:(()=>{})}):null,o=this.options.dom===!1?null:ge(e.anchor,this.options.redact!==!1),r=[...e.files,...t?[t]:[],...o?[ht(o)]:[]],i={message:e.message,kind:e.kind,app:this.options.app,surface:this.options.surface,reporter:e.email?{...this.options.reporter,email:e.email}:this.options.reporter,context:U({anchor:e.anchor,breadcrumbs:(a=this.trail)==null?void 0:a.list(),app:this.options.app})},s=[];try{let d=await this.client.send(i,r,(m,y)=>{var b,v;s.push(y),console.warn(`[feedback] "${m.filename}" did not upload`,y),(v=(b=this.options).onError)==null||v.call(b,y)});return d.uploadsFailed=s.length,(l=(c=this.options).onSent)==null||l.call(c,d),{reference:d.reference,uploadsFailed:s.length}}catch(d){throw this.client.queue(i),(h=(u=this.options).onError)==null||h.call(u,d),d}}};function ht(n){let e=JSON.stringify(n);return{blob:new Blob([e],{type:"application/json"}),filename:"page-snapshot.json",contentType:"application/json"}}function mt(n){return new I(n).start()}function ft(n){if(!n)return null;try{let e=JSON.parse(n);return e&&typeof e=="object"?e:null}catch{return null}}return je(gt);})();
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { BreadcrumbTrail } from './breadcrumbs.js';
|
|
|
2
2
|
import { IngestClient } from './client.js';
|
|
3
3
|
import { captureContext } from './context.js';
|
|
4
4
|
import { captureScreenshot } from './screenshot.js';
|
|
5
|
+
import { captureSnapshot } from './snapshot.js';
|
|
5
6
|
import { FeedbackWidget } from './widget.js';
|
|
6
7
|
/**
|
|
7
8
|
* Where reports go unless the host says otherwise.
|
|
@@ -251,9 +252,34 @@ export class DaybookFeedback {
|
|
|
251
252
|
const screenshot = input.withScreenshot
|
|
252
253
|
? await captureScreenshot(this.options.redact !== false, () => this.widget?.conceal() ?? (() => { }))
|
|
253
254
|
: null;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
255
|
+
/*
|
|
256
|
+
* The page itself, as markup rather than as a picture.
|
|
257
|
+
*
|
|
258
|
+
* Always, and with no prompt: it is the page's own state read by script already running on it,
|
|
259
|
+
* so there is nothing to ask permission for. It goes as an attachment rather than in `context`
|
|
260
|
+
* because context is capped at 64KB server-side and an oversized one is dropped WHOLE — a
|
|
261
|
+
* snapshot in there would silently take the breadcrumbs and the device with it.
|
|
262
|
+
*
|
|
263
|
+
* A screenshot is for a person; this is for whatever reads the report first, which is now
|
|
264
|
+
* usually not a person. Classes, computed style, what is stacked over what and what had focus
|
|
265
|
+
* are all things a PNG makes somebody squint at and an assistant cannot recover at all.
|
|
266
|
+
*/
|
|
267
|
+
const snapshot = this.options.dom === false
|
|
268
|
+
? null
|
|
269
|
+
: captureSnapshot(input.anchor, this.options.redact !== false);
|
|
270
|
+
/*
|
|
271
|
+
* Order matters, because the server takes the first five and drops the rest without saying so.
|
|
272
|
+
*
|
|
273
|
+
* The reporter's own files lead: they chose them, and a file somebody deliberately attached
|
|
274
|
+
* disappearing is the one loss they would notice. Then the screenshot, which they ticked a box
|
|
275
|
+
* for. The snapshot is last because it is the only one nobody asked for — and on the crowded
|
|
276
|
+
* report where it is dropped, the reporter has attached four things and said plenty.
|
|
277
|
+
*/
|
|
278
|
+
const uploads = [
|
|
279
|
+
...input.files,
|
|
280
|
+
...(screenshot ? [screenshot] : []),
|
|
281
|
+
...(snapshot ? [asUpload(snapshot)] : []),
|
|
282
|
+
];
|
|
257
283
|
const request = {
|
|
258
284
|
message: input.message,
|
|
259
285
|
kind: input.kind,
|
|
@@ -293,6 +319,22 @@ export class DaybookFeedback {
|
|
|
293
319
|
}
|
|
294
320
|
}
|
|
295
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* The snapshot as a file to upload.
|
|
324
|
+
*
|
|
325
|
+
* JSON rather than the raw HTML, because the markup is only part of it — the computed styles, the
|
|
326
|
+
* floating layers and what had focus are the parts a picture could never carry, and they need
|
|
327
|
+
* somewhere to live. Named for what it is, so a triager scanning five attachments knows which one
|
|
328
|
+
* nobody chose to attach.
|
|
329
|
+
*/
|
|
330
|
+
function asUpload(snapshot) {
|
|
331
|
+
const body = JSON.stringify(snapshot);
|
|
332
|
+
return {
|
|
333
|
+
blob: new Blob([body], { type: 'application/json' }),
|
|
334
|
+
filename: 'page-snapshot.json',
|
|
335
|
+
contentType: 'application/json',
|
|
336
|
+
};
|
|
337
|
+
}
|
|
296
338
|
export function init(options) {
|
|
297
339
|
return new DaybookFeedback(options).start();
|
|
298
340
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Anchor } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The snapshot, and the ORDER OF THESE FIELDS IS LOAD-BEARING.
|
|
4
|
+
*
|
|
5
|
+
* Whatever reads a report first reads this file inlined beside it, and inlining is bounded — the
|
|
6
|
+
* server extracts the head of a text attachment, not all of it. So the fields are in ascending order
|
|
7
|
+
* of size and descending order of value: the note, then where and when, then the things a picture
|
|
8
|
+
* could never carry, and the markup last. A reader who gets only the first few kilobytes still gets
|
|
9
|
+
* every answer except the tail of the document, and the whole file is behind the attachment's own
|
|
10
|
+
* download URL for anybody who needs it.
|
|
11
|
+
*
|
|
12
|
+
* Put `html` anywhere but last and a truncated read is a truncated document and nothing else.
|
|
13
|
+
*/
|
|
14
|
+
export interface DomSnapshot {
|
|
15
|
+
/** For whoever opens this cold, human or otherwise. */
|
|
16
|
+
note: string;
|
|
17
|
+
capturedAtUtc: string;
|
|
18
|
+
url: string;
|
|
19
|
+
title: string;
|
|
20
|
+
/** Whether values were described rather than reproduced. Says how to read the snapshot. */
|
|
21
|
+
redacted: boolean;
|
|
22
|
+
/** True when the markup hit the cap. What is there is still the top of the document. */
|
|
23
|
+
truncated: boolean;
|
|
24
|
+
scroll: {
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
};
|
|
28
|
+
/** What the keyboard was in, which no screenshot shows. */
|
|
29
|
+
focus: string | null;
|
|
30
|
+
/** The pinned element, its ancestors, and what their styles actually resolved to. */
|
|
31
|
+
anchor?: {
|
|
32
|
+
selector: string;
|
|
33
|
+
path: {
|
|
34
|
+
selector: string;
|
|
35
|
+
computed: Record<string, string>;
|
|
36
|
+
}[];
|
|
37
|
+
};
|
|
38
|
+
/** Everything floating over the page right now: dialogs, drawers, toasts, someone's chat bubble. */
|
|
39
|
+
layers: {
|
|
40
|
+
selector: string;
|
|
41
|
+
zIndex: string;
|
|
42
|
+
rect: {
|
|
43
|
+
x: number;
|
|
44
|
+
y: number;
|
|
45
|
+
w: number;
|
|
46
|
+
h: number;
|
|
47
|
+
};
|
|
48
|
+
}[];
|
|
49
|
+
/** Where the page's CSS came from. Cross-origin sheets cannot be read, and say so. */
|
|
50
|
+
stylesheets: {
|
|
51
|
+
href: string | null;
|
|
52
|
+
rules: number | 'unreadable';
|
|
53
|
+
}[];
|
|
54
|
+
/** Last, deliberately. See the note above the interface. */
|
|
55
|
+
html: string;
|
|
56
|
+
}
|
|
57
|
+
/** The whole snapshot. Never throws — a report without one beats no report. */
|
|
58
|
+
export declare function captureSnapshot(anchor: Anchor | null, redacted: boolean): DomSnapshot | null;
|
package/dist/snapshot.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { redactValue, PRIVATE_ATTRIBUTE } from './redact.js';
|
|
2
|
+
/**
|
|
3
|
+
* The page as a machine can read it: markup, classes, computed style, and what is floating on top.
|
|
4
|
+
*
|
|
5
|
+
* A screenshot is for a person. It is a flat picture, and everything a triager wants to know from it
|
|
6
|
+
* — which element, which classes, what the computed style actually resolved to, what is stacked over
|
|
7
|
+
* what — has to be inferred by looking, and cannot be inferred at all by anything that is not
|
|
8
|
+
* looking. Most feedback now passes an assistant before it passes a person, and to an assistant a
|
|
9
|
+
* PNG is nearly opaque while a DOM is the whole answer.
|
|
10
|
+
*
|
|
11
|
+
* So this is captured on every report, with no prompt and no permission: it is the page's own state,
|
|
12
|
+
* read by script that is already running on the page.
|
|
13
|
+
*
|
|
14
|
+
* <h3>What is deliberately not in it</h3>
|
|
15
|
+
*
|
|
16
|
+
* Script bodies. They are the application bundle, they are megabytes, and the report is about what
|
|
17
|
+
* the page IS rather than how it got there.
|
|
18
|
+
*
|
|
19
|
+
* Input values, unless redaction is off. The rule is the one the rest of the SDK follows: a value is
|
|
20
|
+
* described, never reproduced — `[7 chars]`, or `[redacted]` where the field's name suggests a
|
|
21
|
+
* secret. A DOM snapshot is the single easiest way to ship somebody's half-typed password to a
|
|
22
|
+
* server, and it will not be.
|
|
23
|
+
*
|
|
24
|
+
* Anything under data-daybook-private, which is stripped to a marker rather than emptied, so a
|
|
25
|
+
* reader can see that something was there and was withheld.
|
|
26
|
+
*
|
|
27
|
+
* <h3>What it costs the page</h3>
|
|
28
|
+
*
|
|
29
|
+
* One pass over the tree and a getComputedStyle on the anchor's ancestors — microseconds, and it
|
|
30
|
+
* runs after the reporter presses Send rather than while they are typing. The whole thing is bounded
|
|
31
|
+
* and truncates rather than growing: a page that is somehow fifty megabytes of markup produces a
|
|
32
|
+
* snapshot the same size as any other, with a flag saying so.
|
|
33
|
+
*/
|
|
34
|
+
/** The most markup we will send. Past this the tail is repetition — a table of ten thousand rows. */
|
|
35
|
+
const MAX_HTML = 400000;
|
|
36
|
+
/** No single attribute is this interesting. Caps a base64 data: URI, which is the usual offender. */
|
|
37
|
+
const MAX_ATTRIBUTE = 300;
|
|
38
|
+
/** Long enough for a paragraph, short enough that an article body does not become the snapshot. */
|
|
39
|
+
const MAX_TEXT = 600;
|
|
40
|
+
/** Inline stylesheets are worth having; an entire framework inlined into the head is not. */
|
|
41
|
+
const MAX_STYLE = 8000;
|
|
42
|
+
/** Nothing inside these tells a reader anything about the page's state. */
|
|
43
|
+
const SKIPPED = new Set(['SCRIPT', 'NOSCRIPT', 'TEMPLATE']);
|
|
44
|
+
/** Style properties that explain how something looks, without dumping all three hundred of them. */
|
|
45
|
+
const INTERESTING = [
|
|
46
|
+
'display', 'position', 'z-index', 'opacity', 'visibility', 'overflow',
|
|
47
|
+
'width', 'height', 'margin', 'padding', 'box-sizing',
|
|
48
|
+
'color', 'background-color', 'border', 'border-radius', 'box-shadow',
|
|
49
|
+
'font-family', 'font-size', 'font-weight', 'line-height', 'text-align', 'white-space',
|
|
50
|
+
'flex-direction', 'justify-content', 'align-items', 'gap', 'grid-template-columns',
|
|
51
|
+
'transform', 'transition', 'pointer-events', 'cursor',
|
|
52
|
+
];
|
|
53
|
+
const NOTE = 'The page at the moment this was reported. Field values are described rather than '
|
|
54
|
+
+ 'reproduced when redacted is true, and data-daybook-private subtrees are withheld. html is last '
|
|
55
|
+
+ 'because only the head of this file is inlined beside the report — download the attachment for '
|
|
56
|
+
+ 'the rest of it.';
|
|
57
|
+
/** A CSS-ish path to an element, good enough to find it again and short enough to read. */
|
|
58
|
+
function selectorFor(element) {
|
|
59
|
+
const parts = [];
|
|
60
|
+
let node = element;
|
|
61
|
+
for (let depth = 0; node && depth < 4 && node.nodeType === 1; depth += 1) {
|
|
62
|
+
let part = node.localName;
|
|
63
|
+
if (node.id) {
|
|
64
|
+
parts.unshift(`${part}#${node.id}`);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
const classes = Array.from(node.classList).slice(0, 3).join('.');
|
|
68
|
+
if (classes)
|
|
69
|
+
part += `.${classes}`;
|
|
70
|
+
parts.unshift(part);
|
|
71
|
+
node = node.parentElement;
|
|
72
|
+
}
|
|
73
|
+
return parts.join(' > ');
|
|
74
|
+
}
|
|
75
|
+
const attributeValue = (name, value) => value.length > MAX_ATTRIBUTE ? `${value.slice(0, MAX_ATTRIBUTE)}…[${value.length}]` : value;
|
|
76
|
+
const escape = (text) => text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
77
|
+
/**
|
|
78
|
+
* The value of a field, as the report is allowed to describe it.
|
|
79
|
+
*
|
|
80
|
+
* Checked boxes and selected options are kept as-is: they are a choice among options the markup
|
|
81
|
+
* already lists, not something somebody typed, and "which radio was selected" is frequently the bug.
|
|
82
|
+
*/
|
|
83
|
+
function fieldValue(element, redacted) {
|
|
84
|
+
const input = element;
|
|
85
|
+
if (element.localName === 'input' && (input.type === 'checkbox' || input.type === 'radio')) {
|
|
86
|
+
return input.checked ? 'checked' : 'unchecked';
|
|
87
|
+
}
|
|
88
|
+
const value = input.value;
|
|
89
|
+
if (typeof value !== 'string' || value === '')
|
|
90
|
+
return null;
|
|
91
|
+
return redacted ? redactValue(value, input.name || input.id || input.type) : value;
|
|
92
|
+
}
|
|
93
|
+
/** Serialises one node, appending to `out`, and answers whether there is still room. */
|
|
94
|
+
function write(node, out, size, redacted) {
|
|
95
|
+
if (size.used > MAX_HTML)
|
|
96
|
+
return false;
|
|
97
|
+
if (node.nodeType === 3) {
|
|
98
|
+
const text = (node.textContent ?? '').replace(/\s+/g, ' ');
|
|
99
|
+
if (!text.trim())
|
|
100
|
+
return true;
|
|
101
|
+
const clipped = text.length > MAX_TEXT ? `${text.slice(0, MAX_TEXT)}…` : text;
|
|
102
|
+
out.push(escape(clipped));
|
|
103
|
+
size.used += clipped.length;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
if (node.nodeType !== 1)
|
|
107
|
+
return true;
|
|
108
|
+
const element = node;
|
|
109
|
+
const tag = element.tagName;
|
|
110
|
+
// Our own widget is not the page. A report whose DOM is half feedback composer is a report about
|
|
111
|
+
// the wrong thing.
|
|
112
|
+
if (element.hasAttribute('data-daybook-feedback'))
|
|
113
|
+
return true;
|
|
114
|
+
if (SKIPPED.has(tag))
|
|
115
|
+
return true;
|
|
116
|
+
const name = element.localName;
|
|
117
|
+
if (redacted && element.hasAttribute(PRIVATE_ATTRIBUTE)) {
|
|
118
|
+
out.push(`<${name} ${PRIVATE_ATTRIBUTE}>[withheld]</${name}>`);
|
|
119
|
+
size.used += 32;
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
const attributes = [];
|
|
123
|
+
for (const attribute of Array.from(element.attributes)) {
|
|
124
|
+
if (attribute.name === 'value')
|
|
125
|
+
continue;
|
|
126
|
+
attributes.push(`${attribute.name}="${escape(attributeValue(attribute.name, attribute.value))}"`);
|
|
127
|
+
}
|
|
128
|
+
const value = fieldValue(element, redacted);
|
|
129
|
+
if (value !== null)
|
|
130
|
+
attributes.push(`value="${escape(value)}"`);
|
|
131
|
+
const open = attributes.length > 0 ? `<${name} ${attributes.join(' ')}>` : `<${name}>`;
|
|
132
|
+
out.push(open);
|
|
133
|
+
size.used += open.length;
|
|
134
|
+
if (name === 'style') {
|
|
135
|
+
const css = element.textContent ?? '';
|
|
136
|
+
const clipped = css.length > MAX_STYLE ? `${css.slice(0, MAX_STYLE)}\n/* …${css.length} chars */` : css;
|
|
137
|
+
out.push(clipped);
|
|
138
|
+
size.used += clipped.length;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
for (const child of Array.from(element.childNodes)) {
|
|
142
|
+
if (!write(child, out, size, redacted))
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
out.push(`</${name}>`);
|
|
147
|
+
size.used += name.length + 3;
|
|
148
|
+
return size.used <= MAX_HTML;
|
|
149
|
+
}
|
|
150
|
+
/** Whatever is floating over the page: our own furniture excluded, since we know about ours. */
|
|
151
|
+
function layers() {
|
|
152
|
+
const found = [];
|
|
153
|
+
for (const element of Array.from(document.body?.querySelectorAll('*') ?? []).slice(0, 4000)) {
|
|
154
|
+
const style = getComputedStyle(element);
|
|
155
|
+
if (style.position !== 'fixed' && style.position !== 'sticky')
|
|
156
|
+
continue;
|
|
157
|
+
if (style.visibility === 'hidden' || style.display === 'none' || Number(style.opacity) === 0)
|
|
158
|
+
continue;
|
|
159
|
+
const rect = element.getBoundingClientRect();
|
|
160
|
+
if (rect.width < 4 || rect.height < 4)
|
|
161
|
+
continue;
|
|
162
|
+
if (element.closest('[data-daybook-feedback]'))
|
|
163
|
+
continue;
|
|
164
|
+
found.push({
|
|
165
|
+
selector: selectorFor(element),
|
|
166
|
+
zIndex: style.zIndex,
|
|
167
|
+
rect: { x: Math.round(rect.x), y: Math.round(rect.y), w: Math.round(rect.width), h: Math.round(rect.height) },
|
|
168
|
+
});
|
|
169
|
+
if (found.length >= 20)
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
return found;
|
|
173
|
+
}
|
|
174
|
+
/** The anchored element and its ancestors, with the styles that decide how it looks. */
|
|
175
|
+
function anchorPath(anchor) {
|
|
176
|
+
if (!anchor?.selector)
|
|
177
|
+
return undefined;
|
|
178
|
+
let element = null;
|
|
179
|
+
try {
|
|
180
|
+
element = document.querySelector(anchor.selector);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
if (!element)
|
|
186
|
+
return undefined;
|
|
187
|
+
const path = [];
|
|
188
|
+
for (let node = element; node && path.length < 5; node = node.parentElement) {
|
|
189
|
+
const style = getComputedStyle(node);
|
|
190
|
+
const computed = {};
|
|
191
|
+
for (const property of INTERESTING) {
|
|
192
|
+
const value = style.getPropertyValue(property);
|
|
193
|
+
if (value)
|
|
194
|
+
computed[property] = value;
|
|
195
|
+
}
|
|
196
|
+
path.push({ selector: selectorFor(node), computed });
|
|
197
|
+
}
|
|
198
|
+
return { selector: anchor.selector, path };
|
|
199
|
+
}
|
|
200
|
+
function stylesheets() {
|
|
201
|
+
return Array.from(document.styleSheets).slice(0, 40).map((sheet) => {
|
|
202
|
+
try {
|
|
203
|
+
// Reading rules from a cross-origin sheet throws, and that is worth recording: a triager
|
|
204
|
+
// looking at markup with no matching CSS should know the CSS was unreadable, not absent.
|
|
205
|
+
return { href: sheet.href, rules: sheet.cssRules.length };
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return { href: sheet.href, rules: 'unreadable' };
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/** The whole snapshot. Never throws — a report without one beats no report. */
|
|
213
|
+
export function captureSnapshot(anchor, redacted) {
|
|
214
|
+
try {
|
|
215
|
+
const out = [];
|
|
216
|
+
const size = { used: 0 };
|
|
217
|
+
write(document.documentElement, out, size, redacted);
|
|
218
|
+
return {
|
|
219
|
+
note: NOTE,
|
|
220
|
+
capturedAtUtc: new Date().toISOString(),
|
|
221
|
+
url: location.href,
|
|
222
|
+
title: document.title,
|
|
223
|
+
redacted,
|
|
224
|
+
truncated: size.used > MAX_HTML,
|
|
225
|
+
scroll: { x: Math.round(window.scrollX), y: Math.round(window.scrollY) },
|
|
226
|
+
focus: document.activeElement && document.activeElement !== document.body
|
|
227
|
+
? selectorFor(document.activeElement)
|
|
228
|
+
: null,
|
|
229
|
+
anchor: anchorPath(anchor),
|
|
230
|
+
layers: layers(),
|
|
231
|
+
stylesheets: stylesheets(),
|
|
232
|
+
html: out.join(''),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -185,6 +185,17 @@ export interface FeedbackOptions {
|
|
|
185
185
|
redact?: boolean;
|
|
186
186
|
/** Console errors, failed requests and navigation. On by default, capped and redacted. */
|
|
187
187
|
breadcrumbs?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Attach the page's DOM to every report — markup, classes, computed style for the pinned element,
|
|
190
|
+
* and what is floating over the page. On by default, and it needs no permission: it is the page's
|
|
191
|
+
* own state, read by script already running on it.
|
|
192
|
+
*
|
|
193
|
+
* It obeys `redact`, so field values are described rather than reproduced and anything marked
|
|
194
|
+
* data-daybook-private is withheld. What it does carry is the page's visible text, because that is
|
|
195
|
+
* what the page is. On a screen showing somebody's personal data, decide whether that belongs in a
|
|
196
|
+
* report before leaving this on.
|
|
197
|
+
*/
|
|
198
|
+
dom?: boolean;
|
|
188
199
|
/** Keyboard shortcut to enter pick mode. Defaults to "f". Set null to disable. */
|
|
189
200
|
hotkey?: string | null;
|
|
190
201
|
/**
|
package/dist/widget.js
CHANGED
|
@@ -593,7 +593,7 @@ export class FeedbackWidget {
|
|
|
593
593
|
<div id="status" class="status"></div>
|
|
594
594
|
|
|
595
595
|
<div class="panel__foot">
|
|
596
|
-
<span class="panel__note">Sends
|
|
596
|
+
<span class="panel__note">Sends this page's contents, your browser, and recent errors.</span>
|
|
597
597
|
<button id="cancel" class="ghost">Cancel</button>
|
|
598
598
|
<button id="send" class="primary">Send</button>
|
|
599
599
|
</div>`;
|
package/package.json
CHANGED