brave-real-playwright-core
Version:
Brave-optimized Playwright Core (v1.56.1) with comprehensive stealth patches and error stack sanitization
3 lines (2 loc) • 6.36 kB
JavaScript
import{M as x,r,T as C,W as I,j as e,D as z,a as O,b as U,c as V,d as $,e as q}from"./assets/defaultSettingsView-w0zYjHsW.js";const A=()=>{const[i,c]=r.useState(!1),[l,d]=r.useState([]),[h,p]=r.useState([]),[f,b]=r.useState(P),[w,j]=r.useState({done:0,total:0}),[E,v]=r.useState(!1),[S,T]=r.useState(null),[y,R]=r.useState(null),[W,N]=r.useState(!1),m=r.useCallback(t=>{const a=[],o=[],s=new URL(window.location.href);for(let n=0;n<t.length;n++){const g=t.item(n);if(!g)continue;const k=URL.createObjectURL(g);a.push(k),o.push(g.name),s.searchParams.append("trace",k),s.searchParams.append("traceFileName",g.name)}const u=s.toString();window.history.pushState({},"",u),d(a),p(o),v(!1),T(null)},[]);r.useEffect(()=>{const t=async a=>{var o;if((o=a.clipboardData)!=null&&o.files.length){for(const s of a.clipboardData.files)if(s.type!=="application/zip")return;a.preventDefault(),m(a.clipboardData.files)}};return document.addEventListener("paste",t),()=>document.removeEventListener("paste",t)}),r.useEffect(()=>{const t=a=>{const{method:o,params:s}=a.data;if(o!=="load"||!((s==null?void 0:s.trace)instanceof Blob))return;const u=new File([s.trace],"trace.zip",{type:"application/zip"}),n=new DataTransfer;n.items.add(u),m(n.files)};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)});const M=r.useCallback(t=>{t.preventDefault(),m(t.dataTransfer.files)},[m]),F=r.useCallback(t=>{t.preventDefault(),t.target.files&&m(t.target.files)},[m]);r.useEffect(()=>{const t=new URL(window.location.href).searchParams,a=t.getAll("trace");c(t.has("isServer"));for(const o of a)if(o.startsWith("file:")){R(o||null);return}if(t.has("isServer")){const o=new URLSearchParams(window.location.search).get("ws"),s=new URL(`../${o}`,window.location.toString());s.protocol=window.location.protocol==="https:"?"wss:":"ws:";const u=new C(new I(s));u.onLoadTraceRequested(async n=>{d(n.traceUrl?[n.traceUrl]:[]),v(!1),T(null)}),u.initialize({}).catch(()=>{})}else a.some(o=>o.startsWith("blob:"))||d(a)},[]),r.useEffect(()=>{(async()=>{if(l.length){const t=s=>{s.data.method==="progress"&&j(s.data.params)};navigator.serviceWorker.addEventListener("message",t),j({done:0,total:1});const a=[];for(let s=0;s<l.length;s++){const u=l[s],n=new URLSearchParams;n.set("trace",u),h.length&&n.set("traceFileName",h[s]),n.set("limit",String(l.length));const g=await fetch(`contexts?${n.toString()}`);if(!g.ok){i||d([]),T((await g.json()).error);return}a.push(...await g.json())}navigator.serviceWorker.removeEventListener("message",t);const o=new x(a);j({done:0,total:0}),b(o)}else b(P)})()},[i,l,h]);const D=w.done!==w.total&&w.total!==0&&!S;r.useEffect(()=>{if(D){const t=setTimeout(()=>{N(!0)},200);return()=>clearTimeout(t)}else N(!1)},[D]);const L=!!(!i&&!E&&!y&&(!l.length||S));return e.jsxs("div",{className:"vbox workbench-loader",onDragOver:t=>{t.preventDefault(),v(!0)},children:[e.jsxs("div",{className:"hbox header",...L?{inert:!0}:{},children:[e.jsx("div",{className:"logo",children:e.jsx("img",{src:"playwright-logo.svg",alt:"Playwright logo"})}),e.jsx("div",{className:"product",children:"Playwright"}),f.title&&e.jsx("div",{className:"title",children:f.title}),e.jsx("div",{className:"spacer"}),e.jsx(z,{icon:"settings-gear",title:"Settings",dialogDataTestId:"settings-toolbar-dialog",children:e.jsx(O,{})})]}),e.jsx(U,{model:f,inert:L}),y&&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:y,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"})]})]}),e.jsx(V,{open:W,isModal:!0,className:"progress-dialog",children:e.jsxs("div",{className:"progress-content",children:[e.jsx("div",{className:"title",role:"heading","aria-level":1,children:"Loading Playwright Trace..."}),e.jsx("div",{className:"progress-wrapper",children:e.jsx("div",{className:"inner-progress",style:{width:w.total?100*w.done/w.total+"%":0}})})]})}),L&&e.jsxs("div",{className:"drop-target",children:[e.jsx("div",{className:"processing-error",role:"alert",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 t=document.createElement("input");t.type="file",t.multiple=!0,t.click(),t.addEventListener("change",a=>F(a))},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."})]}),i&&!l.length&&e.jsx("div",{className:"drop-target",children:e.jsx("div",{className:"title",children:"Select test to see the trace"})}),E&&e.jsx("div",{className:"drop-target",onDragLeave:()=>{v(!1)},onDrop:t=>M(t),children:e.jsx("div",{className:"title",children:"Release to analyse the Playwright Trace"})})]})},P=new x([]),B=({traceJson:i})=>{const[c,l]=r.useState(void 0),[d,h]=r.useState(0),p=r.useRef(null);return r.useEffect(()=>(p.current&&clearTimeout(p.current),p.current=setTimeout(async()=>{try{const f=await G(i);l(f)}catch{const f=new x([]);l(f)}finally{h(d+1)}},500),()=>{p.current&&clearTimeout(p.current)}),[i,d]),e.jsx(U,{model:c,isLive:!0})};async function G(i){const c=new URLSearchParams;c.set("trace",i),c.set("limit","1");const d=await(await fetch(`contexts?${c.toString()}`)).json();return new x(d)}(async()=>{const i=new URLSearchParams(window.location.search);if($(),window.location.protocol!=="file:"){if(i.get("isUnderTest")==="true"&&await new Promise(h=>setTimeout(h,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(h=>{navigator.serviceWorker.oncontrollerchange=()=>h()}),setInterval(function(){fetch("ping")},1e4)}const c=i.get("trace"),d=(c==null?void 0:c.endsWith(".json"))?e.jsx(B,{traceJson:c}):e.jsx(A,{});q.createRoot(document.querySelector("#root")).render(d)})();