class Xs{constructor(t,e){this._snapshotIds=new Map,this._snapshotStorage=t,this._resourceLoader=e}serveSnapshot(t,e,n){const r=this._snapshot(t,e);if(!r)return new Response(null,{status:404});const i=r.render();return this._snapshotIds.set(n,r),new Response(i.html,{status:200,headers:{"Content-Type":"text/html; charset=utf-8"}})}async serveClosestScreenshot(t,e){const n=this._snapshot(t,e),r=n==null?void 0:n.closestScreenshot();return r?new Response(await this._resourceLoader(r)):new Response(null,{status:404})}serveSnapshotInfo(t,e){const n=this._snapshot(t,e);return this._respondWithJson(n?{viewport:n.viewport(),url:n.snapshot().frameUrl,timestamp:n.snapshot().timestamp,wallTime:n.snapshot().wallTime}:{error:"No snapshot found"})}_snapshot(t,e){const n=e.get("name");return this._snapshotStorage.snapshotByName(t,n)}_respondWithJson(t){return new Response(JSON.stringify(t),{status:200,headers:{"Cache-Control":"public, max-age=31536000","Content-Type":"application/json"}})}async serveResource(t,e,n){let r;const i=this._snapshotIds.get(n);for(const T of t)if(r=i==null?void 0:i.resourceByUrl($s(T),e),r)break;if(!r)return new Response(null,{status:404});const a=r.response.content._sha1,o=a?await this._resourceLoader(a)||new Blob([]):new Blob([]);let c=r.response.content.mimeType;/^text\/|^application\/(javascript|json)/.test(c)&&!c.includes("charset")&&(c=`${c}; charset=utf-8`);const d=new Headers;c!=="x-unknown"&&d.set("Content-Type",c);for(const{name:T,value:A}of r.response.headers)d.set(T,A);d.delete("Content-Encoding"),d.delete("Access-Control-Allow-Origin"),d.set("Access-Control-Allow-Origin","*"),d.delete("Content-Length"),d.set("Content-Length",String(o.size)),this._snapshotStorage.hasResourceOverride(r.request.url)?d.set("Cache-Control","no-store, no-cache, max-age=0"):d.set("Cache-Control","public, max-age=31536000");const{status:m}=r.response,w=m===101||m===204||m===205||m===304;return new Response(w?null:o,{headers:d,status:r.response.status,statusText:r.response.statusText})}}function $s(s){try{const t=new URL(s);return t.hash="",t.toString()}catch{return s}}function Js(s){const t=new Map,{files:e,stacks:n}=s;for(const r of n){const[i,a]=r;t.set(`call@${i}`,a.map(o=>({file:e[o[0]],line:o[1],column:o[2],function:o[3]})))}return t}const Un={"&":"&","<":"<",">":">",'"':""","'":"'"};function Qs(s){return s.replace(/[&<>"']/ug,t=>Un[t])}function zs(s){return s.replace(/[&<]/ug,t=>Un[t])}function Mt(s,t,e){return s.find((n,r)=>{if(r===s.length-1)return!0;const i=s[r+1];return Math.abs(t(n)-e)i.frameSwapWallTime,t):Mt(this._screencastFrames,i=>i.timestamp,e);return n==null?void 0:n.sha1}render(){const t=[],e=(i,a,o,c)=>{if(typeof i=="string"){o==="STYLE"||o==="style"?t.push(fr(or(i))):t.push(zs(i));return}if(er(i)){const h=a-i[0][0];if(h>=0&&h<=a){const d=rr(this._snapshots[h]),m=i[0][1];if(m>=0&&m_[0]===u),O=w==="SOURCE"&&o==="PICTURE"&&(c==null?void 0:c.some(_=>_[0]===u)),b=g&&A.some(_=>_[0].toLowerCase()==="http-equiv"&&!sr.has(_[1].trim().toLowerCase()));for(const[_,E]of A){let y=_;if(_.toLowerCase().startsWith("on"))continue;l&&_.toLowerCase()==="src"&&(y="__playwright_src__"),l&&(_.toLowerCase()==="srcdoc"||_.toLowerCase()==="sandbox")&&(y="__playwright_"+_.toLowerCase()+"__"),w==="OBJECT"&&_.toLowerCase()==="data"&&(y="__playwright_data__"),w==="EMBED"&&_.toLowerCase()==="src"&&(y="__playwright_src__"),p&&_===u&&(y="src"),["src","srcset"].includes(_.toLowerCase())&&(C||O)&&(y="_"+y),b&&(_.toLowerCase()==="http-equiv"||_.toLowerCase()==="content")&&(y="_"+_);let x=E;!f&&(_.toLowerCase()==="href"||_.toLowerCase()==="src"||_===u)&&(x=lt(E)),t.push(" ",y,'="',Qs(x),'"')}t.push(">");for(const _ of m)e(_,a,T,A);nr.has(T)||t.push("");return}else return},n=this._snapshot;return{html:this._htmlCache.getOrCompute(this,()=>{var c;e(n.html,this._index,void 0,void 0);const i=(c=n.doctype)==null?void 0:c.replace(/[^a-zA-Z0-9]/g,""),o=(i?``:"")+["",`