"use strict";(globalThis.wpRiseJsonp=globalThis.wpRiseJsonp||[]).push([["profiler"],{60776(ie,N,u){u.d(N,{createRumProfiler:()=>G});var w=u(60407),g=u(80937),R=u(19649),V=u(80611),f=u(98657),P=u(19972),A=u(68432);function L(t){let s=0;for(const i of t)i.stackId!==void 0&&s++;return s}const j=/\/(?![vV]\d{1,2}\/)([^/\d?]*\d+[^/?]*)/g;function U(t){return t?t.replace(j,"/?"):"/"}const y=(t,s)=>t||U(s);var x=u(97633);function B(t,s,i){const r={application:{id:s}};i&&(r.session={id:i});const{ids:d,names:m}=F(t.views);d.length&&(r.view={id:d,name:m});const p=t.longTasks.map(l=>l.id).filter(l=>l!==void 0);return p.length&&(r.long_task={id:p}),r}function F(t){const s={ids:[],names:[]};for(const i of t)s.ids.push(i.viewId),i.viewName&&s.names.push(i.viewName);return s.names=Array.from(new Set(s.names)),s}function H(t,s,i){return{event:J(t,s,i),"wall-time.json":t}}function J(t,s,i){const r=(0,x.m5)(s),d=B(t,s.applicationId,i),m=z(r);return{...d,attachments:["wall-time.json"],start:new Date(t.startClocks.timeStamp).toISOString(),end:new Date(t.endClocks.timeStamp).toISOString(),family:"chrome",runtime:"chrome",format:"json",version:4,tags_profiler:m.join(","),_dd:{clock_drift:(0,f.TP)()}}}function z(t){return t.concat(["language:javascript","runtime:chrome","family:chrome","host:browser"])}const C={sampleIntervalMs:10,collectIntervalMs:6e4,minProfileDurationMs:5e3,minNumberOfSamples:50};function G(t,s,i,r,d,m,p,l=C){const X=(0,A.wP)(t,s,m,6);let b;const I=[];let n={state:"stopped",stateReason:"initializing"};s.subscribe(9,()=>{S("session-expired").catch(w.Dx)}),s.subscribe(10,()=>{n.state==="stopped"&&n.stateReason==="session-expired"&&E()});function E(){if(n.state==="running")return;const e=p.findView();b=e?{startClocks:e.startClocks,viewId:e.id,viewName:y(e.name,document.location.pathname)}:void 0,I.push((0,g.q)(t,window,"visibilitychange",$).stop,(0,g.q)(t,window,"beforeunload",q).stop),v()}async function Z(){await S("stopped-by-user")}async function S(e){await Q(e),I.forEach(a=>a()),r.set({status:"stopped",error_reason:void 0})}function K(e){if(e.state==="running")return{cleanupTasks:e.cleanupTasks};const a=[],c=s.subscribe(2,o=>{const h={viewId:o.id,viewName:y(o.name,document.location.pathname),startClocks:o.startClocks};D(h),b=h});return a.push(c.unsubscribe),{cleanupTasks:a}}function v(){const e=(0,R.VZ)().Profiler;if(!e)throw r.set({status:"error",error_reason:"not-supported-by-browser"}),new Error("RUM Profiler is not supported in this browser.");T(n).catch(w.Dx);const{cleanupTasks:a}=K(n);let c;try{c=new e({sampleInterval:l.sampleIntervalMs,maxBufferSize:Math.round(l.collectIntervalMs*1.5/l.sampleIntervalMs)})}catch(o){o instanceof Error&&o.message.includes("disabled by Document Policy")?(V.Vy.warn("[DD_RUM] Profiler startup failed. Ensure your server includes the `Document-Policy: js-profiling` response header when serving HTML pages.",o),r.set({status:"error",error_reason:"missing-document-policy-header"})):r.set({status:"error",error_reason:"unexpected-exception"});return}r.set({status:"running",error_reason:void 0}),n={state:"running",startClocks:(0,f.M8)(),profiler:c,timeoutId:(0,P.wg)(v,l.collectIntervalMs),views:[],cleanupTasks:a,longTasks:[]},D(b),c.addEventListener("samplebufferfull",O)}async function T(e){if(e.state!=="running")return;(0,P.DJ)(e.timeoutId),e.profiler.removeEventListener("samplebufferfull",O);const{startClocks:a,views:c}=e;await e.profiler.stop().then(o=>{const h=(0,f.M8)(),M=d.findLongTasks(a.relative),se=(0,f.vk)(a.timeStamp,h.timeStamp)<l.minProfileDurationMs,ne=L(o.samples)<l.minNumberOfSamples;M.length===0&&(se||ne)||Y(Object.assign(o,{startClocks:a,endClocks:h,clocksOrigin:(0,f.Oc)(),longTasks:M,views:c,sampleInterval:l.sampleIntervalMs}))}).catch(w.Dx)}async function Q(e){n.state==="running"&&(await k(),n={state:"stopped",stateReason:e})}async function W(){n.state==="running"&&(await k(),n={state:"paused"})}async function k(){n.state==="running"&&(n.cleanupTasks.forEach(e=>e()),await T(n))}function D(e){n.state!=="running"||!e||n.views.push(e)}function Y(e){var a;const c=(a=i.findTrackedSession())===null||a===void 0?void 0:a.id,o=H(e,t,c);X.send(o)}function O(){v()}function $(){document.visibilityState==="hidden"&&n.state==="running"?W().catch(w.Dx):document.visibilityState==="visible"&&n.state==="paused"&&v()}function q(){v()}function _(){return n.state==="stopped"}function ee(){return n.state==="running"}function te(){return n.state==="paused"}return{start:E,stop:Z,isStopped:_,isRunning:ee,isPaused:te}}}}]);
