var global=globalThis,shopeeFetch=(function(){var e=Object.defineProperty,t=(e,t)=>()=>(e&&(t=e(e=0)),t),n=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};function r(e){return e}function i(){if(!a&&(a=typeof crypto<`u`&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!a))throw Error(`crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported`);return a(o)}var a,o,s=t((()=>{o=new Uint8Array(16)}));function c(e,t=0){return l[e[t+0]]+l[e[t+1]]+l[e[t+2]]+l[e[t+3]]+`-`+l[e[t+4]]+l[e[t+5]]+`-`+l[e[t+6]]+l[e[t+7]]+`-`+l[e[t+8]]+l[e[t+9]]+`-`+l[e[t+10]]+l[e[t+11]]+l[e[t+12]]+l[e[t+13]]+l[e[t+14]]+l[e[t+15]]}var l,u=t((()=>{l=[];for(let e=0;e<256;++e)l.push((e+256).toString(16).slice(1))})),d,f,p=t((()=>{d=typeof crypto<`u`&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),f={randomUUID:d}}));function m(e,t,n){if(f.randomUUID&&!t&&!e)return f.randomUUID();e||={};let r=e.random||(e.rng||i)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){n||=0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return c(r)}var h=t((()=>{p(),s(),u()})),g=t((()=>{h()})),_,v,y,b=t((()=>{g(),_=class{constructor(e,t=2e3){this.channelRequest=[`ATSP`,e,`REQUEST`].join(`_`),this.channelReply=[`ATSP`,e,`REPLY`].join(`_`),this.timeout=t}handlerMessage(e,t){if(e.source!==window)return!1;let{channelRequest:n,channelReply:r}=this;if(e.data.channelRequest!==n)return!1;let{messageId:i,payload:a}=e.data;return t(a).then(e=>{let t={channelReply:r,messageId:i,response:e};window.postMessage(t,`*`)}),!0}startHandler(e){if(!e)throw`HANDLER_REQURIED`;window.addEventListener(`message`,t=>this.handlerMessage(t,e))}sendMessage(e){let t=m(),{channelRequest:n,channelReply:r,timeout:i}=this,a={channelRequest:n,messageId:t,payload:e};return new Promise((e,n)=>{let o=n=>{if(n.source!==window)return!1;n.data.channelReply===r&&n.data.messageId===t&&(window.removeEventListener(`message`,o),e(n.data.response))};window.addEventListener(`message`,o),window.postMessage(a,`*`),setTimeout(()=>{window.removeEventListener(`message`,o),n(Error(`TIME_OUT`))},i)})}},v=new _(`FETCH_URL`,5e3),y=new _(`FETCH_LISTENER`,3e3)})),x=n({}),S,C,w,T=t((()=>{b(),S=async e=>{let{url:t,method:n,body:r}=e,i=t,a={method:n,headers:{accept:`application/json`,"af-ac-enc-dat":null,"af-ac-enc-sz-token":``,"content-type":`application/json`}};return n===`POST`&&(a.body=JSON.stringify(r)),await(await fetch(i,a)).json()},C=e=>{let{fetch:t}=window;window.fetch=async(...n)=>{let[r,i]=n,a=await t(...n);return r.includes(`/api/`)&&a.clone().json().then(t=>{e({json:t,url:r,payload:i})}),a}},w=async()=>{v.startHandler(S),C(e=>y.sendMessage(e))},w()})),E=r({matches:[`https://shopee.vn/*`,`https://banhang.shopee.vn/*`],world:`MAIN`,main(){Promise.resolve().then(()=>(T(),x))}}),D={debug:(...e)=>([...e],void 0),log:(...e)=>([...e],void 0),warn:(...e)=>([...e],void 0),error:(...e)=>([...e],void 0)};return(async()=>{try{return await E.main()}catch(e){throw D.error(`The content script "shopee-fetch" crashed on startup!`,e),e}})()})();
shopeeFetch;