import{n as e}from"./facade-loader-DFzIYYt_-4bzFvy-b.mjs";import"node:fs";import"node:path";import"node:os";let t;function n(e){return e.some(e=>!!e?.trim())}function r(){return t??=e({dirName:`browser`,artifactBasename:`browser-maintenance.js`}),t}async function i(e){if(!n(e.sessionKeys))return 0;let t;try{t=r()}catch(t){return e.onWarn?.(`browser cleanup unavailable: ${String(t)}`),0}return await t.closeTrackedBrowserTabsForSessions(e)}async function a(e){try{return await e.cleanup()}catch(t){e.onError?.(t);return}}function o(e){let t=new Set;for(let n of e){let e=n.trim();e&&t.add(e)}return[...t]}async function s(e){let t=o(e.sessionKeys);t.length!==0&&await a({cleanup:async()=>{await i({sessionKeys:t,onWarn:e.onWarn})},onError:e.onError})}export{s as cleanupBrowserSessionsForLifecycleEnd};