(function(){try{var g=typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:{};g["__faroBundleId_Speechify Chrome Extension"]="13.4.1"}catch(l){}})();
import{M as l,O as W,_ as L,aa as v,ba as d,ca as P,m as h,n as b,o as w,p as y}from"./chunk-XBBZ57XW.js";import{a as m}from"./chunk-7OA7UB43.js";import{m as p,n as x}from"./chunk-LZ6UXASV.js";import{a as u,f as n,g as o,h as a}from"./chunk-XBE3KAOI.js";var g,S=u(()=>{"use strict";n();a();g=i=>i?["about:","arc://","brave://","browser://","chrome://","chrome-extension://","dia://","edge://","extension://","opera://","vivaldi://"].some(t=>i.startsWith(t)):!0});var A,k=u(()=>{"use strict";n();a();A=(i,e)=>!!(e?.summaryData||i&&i.length>0||e?.isLoadingSummary)});var s,f,J,M=u(()=>{n();a();x();S();k();L();P();W();s=p("TabManager"),f=class i{static instance;currentTab=null;initialTab=null;currentWindowId=null;constructor(){this.init()}static getInstance(){return i.instance||(i.instance=new i),i.instance}async init(){await this.updateCurrentTab(),o.tabs.onActivated.addListener(this.handleTabActivation),o.tabs.onUpdated.addListener(this.handleTabUpdate),setTimeout(async()=>{try{await l(),await d()}catch(e){s.warn("❌ Failed initial content availability check:",e)}},1e3)}handleTabActivation=async e=>{this.currentWindowId!==null&&e.windowId!==this.currentWindowId||(await this.updateCurrentTab(e.tabId),v(),d().catch(()=>{}))};handleSummarizationRequest=async()=>{try{let t=m.getState().currentSessionState;if(A(t?.messages,t))return;await(async()=>{let C=Date.now();for(;Date.now()-C<1e4;){if(m.getState().currentUrlState?.hasContent)return!0;await l(),await new Promise(U=>setTimeout(U,500))}return!1})()?window.dispatchEvent(new CustomEvent("speechify-start-summarization")):s.warn("Timeout waiting for content, cannot summarize")}catch(e){s.error("Error handling summarization request:",e)}};isInternalTab(e){return!e||g(e)}handleTabUpdate=async(e,t)=>{let r=await o.tabs.get(e);if(r.active&&!(this.currentWindowId!==null&&r.windowId!==this.currentWindowId)){if(t.url){this.updateCurrentTab(e);return}if((t.title||t.favIconUrl)&&r.url===this.currentTab?.url){this.currentTab&&(t.title!==void 0&&(this.currentTab.title=r.title),t.favIconUrl!==void 0&&(this.currentTab.favIconUrl=r.favIconUrl));let c={};t.title!==void 0&&(c.title=r.title),t.favIconUrl!==void 0&&(c.favIconUrl=r.favIconUrl),y(c)}}};async updateCurrentTab(e){let t;if(e){if(t=await o.tabs.get(e),this.currentWindowId!==null&&t.windowId!==this.currentWindowId)return}else t=(await o.tabs.query({active:!0,currentWindow:!0}))[0];if(t&&t.id&&t.url){if(this.currentWindowId=t.windowId??this.currentWindowId,g(t.url))return;if(t.url!==this.currentTab?.url){s.debug("🔄 Tab URL changed:",{oldUrl:this.currentTab?.url,newUrl:t.url,tabId:t.id,title:t.title}),this.currentTab={id:t.id,url:t.url,title:t.title,favIconUrl:t.favIconUrl},this.initialTab||(this.initialTab={...this.currentTab},h(this.currentTab.url)),await b(this.currentTab.url,{title:this.currentTab.title,favIconUrl:this.currentTab.favIconUrl,tabId:this.currentTab.id}),await w({hasContent:!1,contentCount:0,latestTitle:this.currentTab.title??""});try{await l()}catch(r){s.warn("❌ Failed to check content availability on URL change:",r)}}}else s.warn("Invalid tab data received:",{tab:t,hasId:!!t?.id,hasUrl:!!t?.url})}getCurrentTab(){return this.currentTab}cleanup(){o.tabs.onActivated.removeListener(this.handleTabActivation),o.tabs.onUpdated.removeListener(this.handleTabUpdate)}},J=f});export{g as a,S as b,A as c,k as d,J as e,M as f};
//# sourceMappingURL=chunk-HLQJEXCG.js.map
