import{M as k,r as a,c as D,j as e,T as R,t as M,W as C,a as F,b as O}from"./assets/wsPort-bjM5Q4Pn.js";const A=()=>{const[l,E]=a.useState(!1),[c,d]=a.useState([]),[p,L]=a.useState([]),[u,y]=a.useState(N),[v,m]=a.useState({done:0,total:0}),[T,h]=a.useState(!1),[S,f]=a.useState(null),[w,P]=a.useState(null),g=a.useCallback(r=>{const o=[],s=[],t=new URL(window.location.href);for(let n=0;n<r.length;n++){const i=r.item(n);if(!i)continue;const b=URL.createObjectURL(i);o.push(b),s.push(i.name),t.searchParams.append("trace",b),t.searchParams.append("traceFileName",i.name)}const j=t.toString();window.history.pushState({},"",j),d(o),L(s),h(!1),f(null)},[]),W=a.useCallback(r=>{r.preventDefault(),g(r.dataTransfer.files)},[g]),U=a.useCallback(r=>{r.preventDefault(),r.target.files&&g(r.target.files)},[g]);a.useEffect(()=>{const r=new URL(window.location.href).searchParams,o=r.getAll("trace");E(r.has("isServer"));for(const s of o)if(s.startsWith("file:")){P(s||null);return}r.has("isServer")?D({onEvent(s,t){s==="loadTrace"&&(d(t.url?[t.url]:[]),h(!1),f(null))},onClose(){}}).then(s=>{s("ready")}):o.some(s=>s.startsWith("blob:"))||d(o)},[]),a.useEffect(()=>{(async()=>{if(c.length){const r=t=>{t.data.method==="progress"&&m(t.data.params)};navigator.serviceWorker.addEventListener("message",r),m({done:0,total:1});const o=[];for(let t=0;t<c.length;t++){const j=c[t],n=new URLSearchParams;n.set("trace",j),p.length&&n.set("traceFileName",p[t]);const i=await fetch(`contexts?${n.toString()}`);if(!i.ok){l||d([]),f((await i.json()).error);return}o.push(...await i.json())}navigator.serviceWorker.removeEventListener("message",r);const s=new k(o);m({done:0,total:0}),y(s)}else y(N)})()},[l,c,p]);const x=!!(!l&&!T&&!w&&(!c.length||S));return e.jsxs("div",{className:"vbox workbench-loader",onDragOver:r=>{r.preventDefault(),h(!0)},children:[e.jsxs("div",{className:"hbox header",...x?{inert:"true"}:{},children:[e.jsx("div",{className:"logo",children:e.jsx("img",{src:"playwright-logo.svg",alt:"Playwright logo"})}),e.jsx("div",{className:"product",children:"Playwright"}),u.title&&e.jsx("div",{className:"title",children:u.title}),e.jsx("div",{className:"spacer"}),e.jsx(R,{icon:"color-mode",title:"Toggle color mode",toggled:!1,onClick:()=>M()})]}),e.jsx("div",{className:"progress",children:e.jsx("div",{className:"inner-progress",style:{width:v.total?100*v.done/v.total+"%":0}})}),e.jsx(C,{model:u,inert:x}),w&&e.jsxs("div",{className:"drop-target",children:[e.jsx("div",{children:"Trace Viewer uses Service Workers to show traces. To view trace:"}),e.jsxs("div",{style:{paddingTop:20},children:[e.jsxs("div",{children:["1. Click ",e.jsx("a",{href:w,children:"here"})," to put your trace into the download shelf"]}),e.jsxs("div",{children:["2. Go to ",e.jsx("a",{href:"https://trace.playwright.dev",children:"trace.playwright.dev"})]}),e.jsx("div",{children:"3. Drop the trace from the download shelf into the page"})]})]}),x&&e.jsxs("div",{className:"drop-target",children:[e.jsx("div",{className:"processing-error","aria-live":"assertive",children:S}),e.jsx("div",{className:"title",role:"heading","aria-level":1,children:"Drop Playwright Trace to load"}),e.jsx("div",{children:"or"}),e.jsx("button",{onClick:()=>{const r=document.createElement("input");r.type="file",r.multiple=!0,r.click(),r.addEventListener("change",o=>U(o))},type:"button",children:"Select file(s)"}),e.jsx("div",{style:{maxWidth:400},children:"Playwright Trace Viewer is a Progressive Web App, it does not send your trace anywhere, it opens it locally."})]}),l&&!c.length&&e.jsx("div",{className:"drop-target",children:e.jsx("div",{className:"title",children:"Select test to see the trace"})}),T&&e.jsx("div",{className:"drop-target",onDragLeave:()=>{h(!1)},onDrop:r=>W(r),children:e.jsx("div",{className:"title",children:"Release to analyse the Playwright Trace"})})]})},N=new k([]);(async()=>{if(F(),window.location.protocol!=="file:"){if(window.location.href.includes("isUnderTest=true")&&await new Promise(l=>setTimeout(l,1e3)),!navigator.serviceWorker)throw new Error(`Service workers are not supported.
Make sure to serve the Trace Viewer (${window.location}) via HTTPS or localhost.`);navigator.serviceWorker.register("sw.bundle.js"),navigator.serviceWorker.controller||await new Promise(l=>{navigator.serviceWorker.oncontrollerchange=()=>l()}),setInterval(function(){fetch("ping")},1e4)}O.render(e.jsx(A,{}),document.querySelector("#root"))})();
