import{j as c}from"./bootstrap-DlNJH-GE.js";class u{sendTabMessage;queryTabs;defaultMaxChars;constructor(t={}){const a=globalThis.chrome;this.sendTabMessage=t.sendTabMessage??(a?.tabs?.sendMessage?(s,e)=>a.tabs.sendMessage(s,e):n()),this.queryTabs=t.queryTabs??(a?.tabs?.query?s=>a.tabs.query(s):n()),this.defaultMaxChars=t.defaultMaxChars??2e5}async connect(){}async close(){}async scrape(t){const a=t.tabId??await this.findTabId(t.url);if(a==null)return{url:t.url,capturedAt:new Date().toISOString(),skipReason:"no open tab for url; deferred (Phase 4 has no headless fetch path)"};const s=await this.sendTabMessage(a,{kind:"wkms/scrape",url:t.url,maxChars:t.maxChars??this.defaultMaxChars,withScreenshot:!!t.withScreenshot});if(!s?.ok||!s.result)return{url:t.url,capturedAt:new Date().toISOString(),skipReason:s?.error??"content script returned no result"};const e=s.result,r=e.markdown??e.text??"";return{...e,url:t.url,finalUrl:e.finalUrl??t.url,capturedAt:e.capturedAt??new Date().toISOString(),contentHash:e.contentHash??(r?c(r):void 0)}}async findTabId(t){try{return(await this.queryTabs({url:t}))[0]?.id}catch{return}}}function n(o){throw new Error("ContentScriptScraper: chrome.tabs is missing — this adapter is only valid in the MV3 SW. Use MemoryScraper for tests.")}export{u as ContentScriptScraper};
//# sourceMappingURL=content_script_scraper-DB-BIwbC.js.map
