var background=(function(){function e(e){return e==null||typeof e==`function`?{main:e}:e}var t=globalThis.browser?.runtime?.id?globalThis.browser:globalThis.chrome,n=`pdfuse.errlog.v1`;function r(){try{return typeof localStorage<`u`?localStorage:null}catch{return null}}async function i(e,t){try{let i=r();if(!i)return;let o=t instanceof Error?t:Error(String(t)),s={at:Date.now(),where:e,name:o.name,msg:(o.message||``).slice(0,300),stack1:(o.stack?.split(`
`)[1]??``).trim().slice(0,200)},c=a(i);i.setItem(n,JSON.stringify([...c,s].slice(-50)))}catch{}}function a(e){try{let t=JSON.parse(e.getItem(n)??`[]`);return Array.isArray(t)?t:[]}catch{return[]}}function o(e){let t=globalThis;typeof t.addEventListener==`function`&&(t.addEventListener(`error`,t=>{let n=t;i(e,n.error??n.message)}),t.addEventListener(`unhandledrejection`,t=>{i(e,t.reason)}))}var s=`pdfuse.locale.v1`;function c(){try{return typeof localStorage<`u`?localStorage:null}catch{return null}}var l=[`en`,`zh_CN`,`zh_TW`,`es`,`pt_BR`,`de`,`fr`,`it`,`nl`,`pl`,`ru`,`uk`,`tr`,`ja`,`ko`,`hi`,`id`,`th`,`vi`];async function u(){return c()?.getItem(s)??``}function d(e,t,n){if(e&&n.includes(e))return e;let r=(t||`en`).replace(/-/g,`_`);if(n.includes(r))return r;let i=r.split(`_`)[0];return i===`zh`?/TW|HK|Hant/i.test(r)?`zh_TW`:`zh_CN`:n.find(e=>e.split(`_`)[0]===i)??`en`}async function f(e=l){let n=t.i18n?.getUILanguage?.()??`en`;return d(await u(),n,e)}var p={en:``,zh_CN:`zh-cn`,zh_TW:`zh-tw`,es:`es`,pt_BR:`pt-br`,de:`de`,fr:`fr`,it:`it`,nl:`nl`,pl:`pl`,ru:`ru`,uk:`uk`,tr:`tr`,ja:`ja`,ko:`ko`,hi:`hi`,id:`id`,th:`th`,vi:`vi`},m=`https://extensionsly.com`,h=`pdfmerge`,g=`/bundle/`,_=`ext`;function v(e,t){let n=p[t]??``;return`${m}${n?`/`+n:``}${e}`}function y(e,{medium:t,content:n}){let r=new URL(e);return r.searchParams.set(`utm_source`,_),r.searchParams.set(`utm_medium`,t),r.searchParams.set(`utm_campaign`,h),n&&r.searchParams.set(`utm_content`,n),r.toString()}function b(e,t,n=g){return y(v(n,e),t)}`${h}`;var x={popupFooter:{medium:`footer`},workbenchFooter:{medium:`card`},welcome:{medium:`bundle`,content:`welcome`},uninstall:{medium:`bundle`,content:`uninstall`}};function S(e,t){return b(e,x[t])}async function C(){try{t.runtime.setUninstallURL(S(await f(),`uninstall`))}catch(e){i(`background`,e)}}var w=e=>(...t)=>{try{e(...t)}catch(e){i(`background`,e)}},T=e(()=>{o(`background`),C(),t.runtime.onInstalled.addListener(w(e=>{C(),e.reason===`install`&&t.tabs.create({url:t.runtime.getURL(`/onboarding.html`)})})),t.runtime.onStartup.addListener(w(()=>void C())),t.runtime.onMessage.addListener((e,t,n)=>{if(e&&e.__perfPing)return n({ok:!0}),!0})}),E={debug:(...e)=>([...e],void 0),log:(...e)=>([...e],void 0),warn:(...e)=>([...e],void 0),error:(...e)=>([...e],void 0)},D;try{D=T.main(),D instanceof Promise&&console.warn(`The background's main() function return a promise, but it must be synchronous`)}catch(e){throw E.error(`The background crashed on startup!`),e}return D})();