!function(){"use strict";const e="single-file-response-fetch",r="Host fetch error (SingleFile)",t=Boolean(window.wrappedJSObject),a=window.fetch.bind(window);let s,n=0,i=new Map;async function o(c,d={},u=!0){try{const n={cache:d.cache||"force-cache",headers:d.headers,referrerPolicy:d.referrerPolicy||"strict-origin-when-cross-origin"};let i;try{i=d.referrer&&!t||!u?await a(c,n):await async function(t,a){if(void 0===s&&(s=!1,document.addEventListener("single-file-response-fetch-supported",(()=>s=!0),!1),document.dispatchEvent(new CustomEvent("single-file-request-fetch-supported"))),s)return new Promise(((r,s)=>{document.dispatchEvent(new CustomEvent("single-file-request-fetch",{detail:JSON.stringify({url:t,options:a})})),document.addEventListener(e,(function a(n){n.detail?n.detail.url==t&&(document.removeEventListener(e,a,!1),n.detail.response?r({status:n.detail.status,headers:new Map(n.detail.headers),arrayBuffer:async()=>n.detail.response}):s(n.detail.error)):s()}),!1)}));throw new Error(r)}(c,n),401!=i.status&&403!=i.status&&404!=i.status||"no-referrer"==n.referrerPolicy||d.referrer||(i=await o(c,{...n,referrerPolicy:"no-referrer"},u))}catch(e){if(e&&e.message==r)i=await o(c,{...n},!1);else{if("no-referrer"==n.referrerPolicy||d.referrer)throw e;i=await o(c,{...n,referrerPolicy:"no-referrer"},u)}}return i}catch(e){n++;const r=new Promise(((e,r)=>i.set(n,{resolve:e,reject:r})));return await f({method:"singlefile.fetch",url:c,requestId:n,referrer:d.referrer,headers:d.headers}),r}}async function c(e,r){const t=await f({method:"singlefile.fetchFrame",url:e,frameId:r.frameId,referrer:r.referrer,headers:r.headers});return{status:t.status,headers:new Map(t.headers),arrayBuffer:async()=>new Uint8Array(t.array).buffer}}async function f(e){const r=await browser.runtime.sendMessage(e);if(!r||r.error)throw new Error(r&&r.error&&r.error.toString());return r}browser.runtime.onMessage.addListener((e=>"singlefile.fetchFrame"==e.method&&window.frameId&&window.frameId==e.frameId?async function(e){try{const r=await a(e.url,{cache:"force-cache",headers:e.headers,referrerPolicy:"strict-origin-when-cross-origin"});return{status:r.status,headers:[...r.headers],array:Array.from(new Uint8Array(await r.arrayBuffer()))}}catch(e){return{error:e&&(e.message||e.toString())}}}(e):"singlefile.fetchResponse"==e.method?async function(e){const r=i.get(e.requestId);r&&(e.error?(r.reject(new Error(e.error)),i.delete(e.requestId)):(e.truncated&&(r.array?r.array=r.array.concat(e.array):(r.array=e.array,i.set(e.requestId,r)),e.finished&&(e.array=r.array)),e.truncated&&!e.finished||(r.resolve({status:e.status,headers:{get:r=>e.headers&&e.headers[r]},arrayBuffer:async()=>new Uint8Array(e.array).buffer}),i.delete(e.requestId))));return{}}(e):void 0));const d={getPageData:globalThis.singlefile.getPageData};globalThis.singlefile.getPageData=function(e,r={fetch:o,frameFetch:c},t,a){return d.getPageData(e,r,t,a)}}();
