!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).biliMirror={})}(this,(function(e){"use strict";function t(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;let n=!1;function r(){return!1===n&&(n="undefined"!=typeof window),n}var o;const i=function(){if(r())return window}();function s(){if(r())return i.__biliMirror__=i.__biliMirror__||{},i.__biliMirror__}const c=r()&&(null===(o=document.getElementsByTagName("meta").spm_prefix)||void 0===o?void 0:o.content)||"0.0";function a(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];e.addEventListener(t,n,r)}function l(){return Date.now()}const u=Object.prototype.toString;function d(e){return function(t){return u.call(t)===`[object ${e}]`}}const f={isNumber:d("Number"),isString:d("String"),isBoolean:d("Boolean"),isNull:d("Null"),isUndefined:d("Undefined"),isSymbol:d("Symbol"),isFunction:d("Function"),isObject:d("Object"),isArray:d("Array"),isProcess:d("process"),isWindow:d("Window")};function h(e){const t=/^[0-9a-zA-Z_-]+$/.test(e);return t||console.warn(`字符串:${e},不符合条件,任意数字,字母、下划线、中划线组成`),t}const p=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:["chrome-extension"],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(0===t.length)return!1;if(null==(null==e?void 0:e.message))return!0;const[r]=e.message.split("?");if(r.includes(location.hostname))return!0;const o=(null==e?void 0:e.fileName)||"";if(n&&!o.endsWith(".js"))return!0;try{return t.map((e=>new RegExp(String.raw`${e}`))).some((e=>e.test(r)||e.test(o)))}catch(e){return console.error("Invalid regular expression:",e),!1}};function m(e){if("0"===e)return 0;if(f.isNumber(e))return e>10?10:e<=0?1:e;if(f.isString(e)&&!isNaN(e)){const t=parseInt(e);return t>10?10:t<=0?1:t}return console.warn("mirror-kv-[config] sampling rate error,please set 1-10"),1}function g(e){return Math.floor(10*Math.random()+1)>e}function v(){return"undefined"==typeof document||null==document.location?"":document.location.href}function y(e){if(!e)return{};const t=e.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)return{};const n=t[6]||"",r=t[8]||"";return{host:t[4],path:t[5],protocol:t[2],relative:t[5]+n+r}}function w(e,t,n){if(void 0!==e&&(t in e||arguments.length>3&&void 0!==arguments[3]&&arguments[3])){const r=n(e[t]);"function"==typeof r&&(e[t]=r)}}const b=(e,t)=>{let n=!0;return function(){if(n){for(var r=arguments.length,o=new Array(r),i=0;i{n=!0}),t)}}},E=(e,t)=>{let n;return function(){for(var r=arguments.length,o=new Array(r),i=0;i{e.apply(this,o)}),t)}};function R(e){return e&&"object"==typeof e&&!Array.isArray(e)}function O(e,t){let n=Object.assign({},e);return R(e)&&R(t)&&Object.keys(t).forEach((r=>{R(t[r])?r in e?n[r]=O(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})})),n}var _="1.6.36";const S="@bilibili/bili-mirror",I=_;var T=function(e){"undefined"!=typeof window&&window.__BILI_X_ENGINE_SCRIPT_CACHE__&&void 0!==window.__BILI_X_ENGINE_SCRIPT_CACHE__[e]&&delete window.__BILI_X_ENGINE_SCRIPT_CACHE__[e]},N=function(e,t){if("undefined"==typeof window)return Promise.reject(new Error("window is not defined"));var n,r=e=e.replace(/^https?:\/\//,"//"),o=(n=r,"undefined"==typeof window?null:window.__BILI_X_ENGINE_SCRIPT_CACHE__&&window.__BILI_X_ENGINE_SCRIPT_CACHE__[n]||null);if(null!=o&&o.promise)return o.promise;var i=new Promise((function(n,r){var o=document.createElement("script");o.src=e,null!=t&&t.behavior&&o.setAttribute(t.behavior,""),o.onload=function(){var o=window;if(t.lib)return o[t.lib]?n(o[t.lib]):r(new Error('Failed to access library "'+t.lib+'" from '+e));n(null)},o.onerror=function(){r(new Error("Failed to load "+e))},document.head.appendChild(o)}));return function(e,t){"undefined"!=typeof window&&(window.__BILI_X_ENGINE_SCRIPT_CACHE__||(window.__BILI_X_ENGINE_SCRIPT_CACHE__={}),window.__BILI_X_ENGINE_SCRIPT_CACHE__[e]=t)}(r,{promise:i,lib:null==t?void 0:t.lib}),i.then((function(){!1===(null==t?void 0:t.cache)&&T(r)})).catch((function(){!1===(null==t?void 0:t.cache)&&T(r)})),i},C=function(e){return Promise.resolve(function(){try{return window.KvSDK?Promise.resolve(window.KvSDK):Promise.resolve(N("//s1.hdslb.com/bfs/seed/jinkela/kv-sdk/index.js",{lib:"KvSDK"}))}catch(e){return Promise.reject(e)}}()).then((function(t){return new t(e)}))},P=function(e){return Promise.resolve(function(){try{return window.ReporterPb?Promise.resolve(window.ReporterPb):Promise.resolve(N("//s1.hdslb.com/bfs/seed/jinkela/short/reporter-pb/index.js",{lib:"ReporterPb"}))}catch(e){return Promise.reject(e)}}()).then((function(t){return new t(e)}))};const k=s(),L={SPMID:"333.1333",GROUP:"bilimirror",KEY:"whitelist",KEYTOP:"toplist"};class j{constructor(){this.origin="bili",this.module="common",this.config={},this.kvOptions={},this._defaultKvConfig={performance:1,poll:5,techpv:5,userLog:[],resourceTime:{},userLogDeep:10,track:{},filterEndJs:!1,limitDomain:[]}}fetchWhiteListConfig(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return new Promise(((r,o)=>{e.get(t).then((t=>{if(!t)return n||console.warn(`${e.storage.appKey}-没有对应配置,返回默认配置`),void r(n?this._defaultKvConfig:{});const o=JSON.parse(t);r(o)})).catch((t=>{console.warn(`${e.storage.appKey},mirror获取白名单配置失败,返回默认配置`),r(this._defaultKvConfig)}))}))}getConfig(){return t(this,void 0,void 0,(function*(){this._defaultConfigSDK=yield C(Object.assign({appKey:L.SPMID,strict:1,reporter:{ignoreAppKeyNotFound:!0}},this.kvOptions));const{SPMID:e,GROUP:t,KEY:n,KEYTOP:r}=L,o=this.spmId||c,i=yield this.fetchWhiteListConfig(this._defaultConfigSDK,`${t}.${n}`,!0),s=yield this.fetchWhiteListConfig(this._defaultConfigSDK,`${t}.${r}`,!0);let a={};e!==o&&(this._configSDK&&delete this._configSDK,this._configSDK=yield C(Object.assign({appKey:o,strict:1,reporter:{ignoreAppKeyNotFound:!0}},this.kvOptions)),a=yield this.fetchWhiteListConfig(this._configSDK,`${t}.${n}`));let l=O(i,a);return l=O(l,s),new Promise((e=>{this.config.white=(null==l?void 0:l.white)||{},this.config["white-performance-rate"]=l.performance?m(null==l?void 0:l.performance):1,this.config["poll-time"]=l.poll?m(null==l?void 0:l.poll):5,this.config["tech-pv"]=l.techpv?m(null==l?void 0:l.techpv):5,this.config["user-log"]=(null==l?void 0:l.userLog)||[],this.config["resource-time"]=(null==l?void 0:l.resourceTime)||{},this.config["user-log-deep"]=(null==l?void 0:l.userLogDeep)||10,this.config.track=(null==l?void 0:l.track)||{},this.config["filter-end-js"]=(null==l?void 0:l.filterEndjs)||!1,this.config["player-log-umd"]=(null==l?void 0:l.playLogUmd)||"",this.config["track-gray"]=(null==l?void 0:l.trackGrayV2)||0,this.config["limit-control"]=(null==l?void 0:l.control)||{},this.config["limit-domain"]=(null==l?void 0:l.limitDomain)||[],e()}))}))}bindOptions(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return t(this,void 0,void 0,(function*(){return k.mirrorVersion=I,Object.keys(e).forEach((t=>{"config"!==t&&("module"===t&&"function"==typeof e[t]?this[t]=e[t]():this[t]=e[t])})),yield this.getConfig(),Promise.resolve("ok")}))}updateModule(e){this.module=e}}function x(){return k.options||(k.options=new j)}const A=r()?x():null;function $(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return t(this,void 0,void 0,(function*(){if(r()){return yield A.bindOptions(e)}}))}var M,D=-1,H=function(e){addEventListener("pageshow",(function(t){t.persisted&&(D=t.timeStamp,e(t))}),!0)},B=function(){var e=self.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart=0?r="back-forward-cache":n&&(document.prerendering||F()>0?r="prerender":document.wasDiscarded?r="restore":n.type&&(r=n.type.replace(/_/g,"-"))),{name:e,value:void 0===t?-1:t,rating:"good",delta:0,entries:[],id:"v4-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:r}},K=function(e,t,n){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var r=new PerformanceObserver((function(e){Promise.resolve().then((function(){t(e.getEntries())}))}));return r.observe(Object.assign({type:e,buffered:!0},n||{})),r}}catch(e){}},G=function(e,t,n,r){var o,i;return function(s){t.value>=0&&(s||r)&&((i=t.value-(o||0))||void 0===o)&&(o=t.value,t.delta=i,t.rating=function(e,t){return e>t[1]?"poor":e>t[0]?"needs-improvement":"good"}(t.value,n),e(t))}},W=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},J=function(e){document.addEventListener("visibilitychange",(function(){"hidden"===document.visibilityState&&e()}))},q=function(e){var t=!1;return function(){t||(e(),t=!0)}},V=-1,Y=function(){return"hidden"!==document.visibilityState||document.prerendering?1/0:0},X=function(e){"hidden"===document.visibilityState&&V>-1&&(V="visibilitychange"===e.type?e.timeStamp:0,Q())},z=function(){addEventListener("visibilitychange",X,!0),addEventListener("prerenderingchange",X,!0)},Q=function(){removeEventListener("visibilitychange",X,!0),removeEventListener("prerenderingchange",X,!0)},Z=function(){return V<0&&(V=Y(),z(),H((function(){setTimeout((function(){V=Y(),z()}),0)}))),{get firstHiddenTime(){return V}}},ee=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},te=[1800,3e3],ne=function(e,t){t=t||{},ee((function(){var n,r=Z(),o=U("FCP"),i=K("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(i.disconnect(),e.startTimet.latency){if(n)e.duration>n.latency?(n.entries=[e],n.latency=e.duration):e.duration===n.latency&&e.startTime===n.entries[0].startTime&&n.entries.push(e);else{var r={id:e.interactionId,latency:e.duration,entries:[e]};de.set(r.id,r),ue.push(r)}ue.sort((function(e,t){return t.latency-e.latency})),ue.length>10&&ue.splice(10).forEach((function(e){return de.delete(e.id)}))}}},me=function(e){var t=self.requestIdleCallback||self.setTimeout,n=-1;return e=q(e),"hidden"===document.visibilityState?e():(n=t(e),J(e)),n},ge=[200,500],ve=function(e,t){"PerformanceEventTiming"in self&&"interactionId"in PerformanceEventTiming.prototype&&(t=t||{},ee((function(){var n;le();var r,o=U("INP"),i=function(e){me((function(){e.forEach(pe);var t=function(){var e=Math.min(ue.length-1,Math.floor((ae()-fe)/50));return ue[e]}();t&&t.latency!==o.value&&(o.value=t.latency,o.entries=t.entries,r())}))},s=K("event",i,{durationThreshold:null!==(n=t.durationThreshold)&&void 0!==n?n:40});r=G(e,o,ge,t.reportAllChanges),s&&(s.observe({type:"first-input",buffered:!0}),J((function(){i(s.takeRecords()),r(!0)})),H((function(){fe=ae(),ue.length=0,de.clear(),o=U("INP"),r=G(e,o,ge,t.reportAllChanges)})))})))},ye=[2500,4e3],we={},be=[800,1800],Ee=function e(t){document.prerendering?ee((function(){return e(t)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(t)}),!0):setTimeout(t,0)},Re=function(e,t){t=t||{};var n=U("TTFB"),r=G(e,n,be,t.reportAllChanges);Ee((function(){var o=B();o&&(n.value=Math.max(o.responseStart-F(),0),n.entries=[o],r(!0),H((function(){n=U("TTFB",0),(r=G(e,n,be,t.reportAllChanges))(!0)})))}))};const Oe=e=>!!r()&&(()=>{try{return r()&&PerformanceObserver?PerformanceObserver.supportedEntryTypes||[]:null}catch(e){console.error("bili-mirror: supportList 解析异常:",e)}})().includes(e);function _e(e){window.performance.getEntriesByType&&window.addEventListener("load",(function(){const t=window.performance;t&&setTimeout((()=>{let n=t.getEntriesByType("navigation")[0];n=n.toJSON();const r=Object.assign({},n);delete r.serverTiming;const o=window._naToH5?{nativeContainerStartTime:(null===window||void 0===window?void 0:window._naToH5.containerStartTime)||(null===window||void 0===window?void 0:window._naToH5.webviewInitTime)||0,nativeContainerShowTime:(null===window||void 0===window?void 0:window._naToH5.containerShowTime)||(null===window||void 0===window?void 0:window._naToH5.webviewLoadUrlTime)||0,nativeLoadStartTime:(null===window||void 0===window?void 0:window._naToH5.loadStartTime)||0,nativeLoadFinishTime:(null===window||void 0===window?void 0:window._naToH5.loadFinishTime)||0}:{},i=Object.assign(Object.assign(Object.assign({_version:"2.0"},r),o||{}),{pageStartTimeTs:t.timing.navigationStart});e({name:"PAGETIME",data:i,value:1})}),1e3)}))}function Se(e){/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)?(!function(e){if(!Oe("first-input"))return;const t=new PerformanceObserver((n=>{for(const r of n.getEntries()){t.disconnect();const n=r.processingStart-r.startTime;e({name:"FID",value:n,rating:n<100?"good":n>100&&n<300?"normal":"poor"})}}));t.observe({type:"first-input",buffered:!0})}((t=>{e(t)})),function(e){if(!Oe("paint"))return;const t=new PerformanceObserver((n=>{for(const r of n.getEntries())"first-contentful-paint"===r.name&&(t.disconnect(),e({name:"FCP",value:r.startTime,rating:r.startTime<1600?"good":r.startTime>1600&&r.startTime<3e3?"normal":"poor"}))}));t.observe({type:"paint",buffered:!0})}((t=>{e(t)})),function(e){if(!Oe("largest-contentful-paint"))return;const t=new PerformanceObserver((n=>{for(const r of n.getEntries())t.disconnect(),e({name:"LCP",value:r.startTime,rating:r.startTime<1600?"good":r.startTime>1600&&r.startTime<3e3?"normal":"poor"})}));t.observe({type:"largest-contentful-paint",buffered:!0})}((t=>{e(t)})),function(e){window.addEventListener("load",(function(){let{responseStart:t,navigationStart:n}=window.performance.timing,r=t-n;e({name:"TTFB",value:r,rating:r<200?"good":r>200&&r<500?"normal":"poor"})}))}((t=>{e(t)})),_e((t=>{e(t)}))):(!function(e,t){t=t||{},ee((function(){var n,r=Z(),o=U("LCP"),i=function(e){t.reportAllChanges||(e=e.slice(-1)),e.forEach((function(e){e.startTime{e(t)})),ve((t=>{e(t)})),function(e,t){t=t||{},ne(q((function(){var n,r=U("CLS",0),o=0,i=[],s=function(e){e.forEach((function(e){if(!e.hadRecentInput){var t=i[0],n=i[i.length-1];o&&e.startTime-n.startTime<1e3&&e.startTime-t.startTime<5e3?(o+=e.value,i.push(e)):(o=e.value,i=[e])}})),o>r.value&&(r.value=o,r.entries=i,n())},c=K("layout-shift",s);c&&(n=G(e,r,re,t.reportAllChanges),J((function(){s(c.takeRecords()),n(!0)})),H((function(){o=0,r=U("CLS",0),n=G(e,r,re,t.reportAllChanges),W((function(){return n()}))})),setTimeout(n,0))})))}((t=>{e(t)})),ne((t=>{e(t)})),Re((t=>{e(t)})),_e((t=>{e(t)})))}const Ie="MIRROR_TRACK_V2",Te="log",Ne="key",Ce={createIndexedDB(){if(window.indexedDB)return new Promise(((e,t)=>{const n=indexedDB.open(Ie,1);n.onupgradeneeded=e=>{const t=e.target.result;t.objectStoreNames.contains(Te)||t.createObjectStore(Te,{keyPath:Ne})},n.onsuccess=t=>{(null==t?void 0:t.target).result.close(),e()},n.onerror=()=>{console.log("Indexed Start Error"),t()}}))},add(e){if(!window.indexedDB)return;const t=function(){const e=new Date;return`${e.getFullYear()}-${1===String(e.getMonth()+1).length?"0"+(e.getMonth()+1):String(e.getMonth()+1)}-${1===String(e.getDate()).length?"0"+e.getDate():String(e.getDate())} ${1===String(e.getHours()).length?"0"+e.getHours():String(e.getHours())}:${1===String(e.getMinutes()).length?"0"+e.getMinutes():String(e.getMinutes())}:${1===String(e.getSeconds()).length?"0"+e.getSeconds():String(e.getSeconds())}`}()+"_"+Math.ceil(999*Math.random())+"Z",n=indexedDB.open(Ie,1);n.onupgradeneeded=e=>{const t=e.target.result;t.objectStoreNames.contains(Te)||t.createObjectStore(Te,{keyPath:Ne})},n.onsuccess=n=>{const r=n.target.result;if(!r.objectStoreNames.contains(Te))return;const o=r.transaction(Te,"readwrite").objectStore(Te),i=o.count();i.onsuccess=()=>{o.put({[Ne]:t,log:e}),Number(i.result)<=5e3||(o.openCursor().onsuccess=e=>{const t=e.target.result;t&&t.delete()})},i.onerror=()=>{console.log("mirror indexDb count error")},r.close()},n.onerror=()=>{console.log("add Indexed Open Error")}},getAll(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(window.indexedDB)return new Promise(((t,n)=>{let r=[];const o=indexedDB.open(Ie);o.onsuccess=o=>{const i=o.target.result;if(!i.objectStoreNames.contains(Te))return void n(`the store log not exists in the ${Ie} dataBase`);const s=i.transaction(Te,"readonly").objectStore(Te);if(e)s.openCursor().onsuccess=e=>{var o,i;const s=e.target.result;if(s){const e=`${null===(o=s.value)||void 0===o?void 0:o.key}-${null===(i=s.value)||void 0===i?void 0:i.log}`;r.push(e),r.push("\r\n"),s.continue()}else if(0===r.length)n("No data in the store");else{const e=new Blob(r,{type:"text/plain;charset=utf-8"});t(e)}},s.openCursor().onerror=()=>{n("OpenCursor Error")};else{s.getAll().onsuccess=function(e){const n=e.target.result;t(n)}}i.close()},o.onerror=()=>{n("Indexed Open Error")}}))},clearStore(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Ie,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Te;if(!window.indexedDB)return;const n=indexedDB.open(e);n.onsuccess=e=>{const n=e.target.result;if(!n.objectStoreNames.contains(t))return;n.transaction(t,"readwrite").objectStore(t).clear().onsuccess=function(e){},n.close()},n.onerror=function(e){console.log("Error opening db",e.target.error)}},deleteIndexedDB(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Ie;if(!window.indexedDB)return;const t=indexedDB.deleteDatabase(e);t.onsuccess=()=>{},t.onerror=()=>{console.log("Delete Error")}}};var Pe,ke,Le,je,xe,Ae,$e;!function(e){e.INIT="init",e.ERROR="error",e.UNHANDLEDREJECTION="unhandledrejection",e.RESOURCE="resource",e.PERFORMANCE="performance",e.WHITESCREEN="whiteScreen",e.BREABCRUMB="breadcrumb"}(Pe||(Pe={})),function(e){e.ERROR="error",e.CLICK="click",e.HISTORY="history",e.HASHCHANGE="hashchange",e.UNHANDLEDREJECTION="unhandledrejection",e.RESOURCE="resource",e.WHITE="white",e.CUSTOM="custom",e.SCROLL="scroll",e.API="request"}(ke||(ke={})),function(e){e.BEFORE="mirrorHandlerBefore",e.AFTER="mirrorHandlerAfter"}(Le||(Le={})),function(e){e.ERROR="error",e.OK="ok"}(je||(je={})),function(e){e.AUTO="auto",e.DEFAULT="default"}(xe||(xe={})),function(e){e.HISTORY="history",e.HASH="hash",e.DOM="dom",e.JS="js",e.PROMISE="promise",e.RESOURCE="resource",e.WHITE="white",e.SCROLL="scroll",e.API="request"}(Ae||(Ae={})),function(e){e.LOAD="info-load",e.REFRESH="info-refresh",e.PAGETABSTATUS="info-visibilitychange",e.DEVICE="info-device",e.SCROLL="info-scroll",e.PAGECLOSE="info-close",e.CLICK="info-click",e.HISTORY="info-history",e.HASHCHANGE="info-hashchange",e.APIUNKNOWN="info-request-unknown",e.APISUCCESS="success-request",e.APIERROR="error-request",e.ERROR="error-js",e.UNHANDLEDREJECTION="error-unhandledrejection",e.RESOURCE="error-resource",e.WHITE="error-white"}($e||($e={}));const Me={isExclusive:1},De={mirrorPolymer:3},He=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"before",r=arguments.length>2?arguments[2]:void 0;const o=[];let i=!1,s=0;return{start(){return new Promise((c=>t(this,void 0,void 0,(function*(){if(!i){for(i=!0;s{e(),this.repeat(e,t)}),t)}clear(){clearTimeout(this.timeID)}}let Fe=null;class Ue{before(e,n){return new Promise((r=>t(this,void 0,void 0,(function*(){if(A.plugins&&f.isArray(A.plugins))try{const t=A.plugins,o=yield He(t,"before",{type:e,data:n}).start();let[i]=o.slice(-1);r(i)}catch(e){console.warn("bili-mirror:plugin function before hook error,please check"),r(!0)}else if(A.plugins&&A.plugins.mirrorHandleBefore)try{A.plugins.mirrorHandleBefore(e,n).then((e=>{r(e)}))}catch(e){console.warn("bili-mirror:plugin function before hook error,please check"),r(!0)}else r(!0)}))))}after(e,n){return new Promise((r=>t(this,void 0,void 0,(function*(){if(A.plugins&&f.isArray(A.plugins))try{const t=A.plugins;yield He(t,"after",{type:e,data:n}).start(),r()}catch(e){console.warn("bili-mirror:plugin function after hook error,please check"),r()}else if(A.plugins&&A.plugins.mirrorHandleAfter)try{A.plugins.mirrorHandleAfter(e,n).then((()=>{r()}))}catch(e){console.warn("bili-mirror:plugin function after hook error,please check"),r()}else r()}))))}}Fe||(Fe=new Ue);const Ke=s();const Ge=r()?Ke.breadcrumb||(Ke.breadcrumb=new class{constructor(){this.maxBreadcrumbs=10,this.stack=[],this.isSet=!1}push(e){return t(this,void 0,void 0,(function*(){(null==A?void 0:A.config["user-log-deep"])&&!this.isSet&&(this.maxBreadcrumbs=null==A?void 0:A.config["user-log-deep"],this.isSet=!0);(yield Fe.before(Pe.BREABCRUMB,e))&&(this.immediatePush(e),a(i,"beforeunload",(()=>{this.stack.filter((e=>"error"===e.status)).length&&(this.goToReport(this.stack),window.__biliMirrorPbInstance__&&window.__biliMirrorPbInstance__.flush&&window.__biliMirrorPbInstance__.flush())})))}))}immediatePush(e){if(e.time||(e.time=l()),this.stack.length>=this.maxBreadcrumbs){this.stack.filter((e=>"error"===e.status)).length?(this.goToReport(this.stack),this.clear()):this.clear()}this.stack.push(e),this.stack.sort(((e,t)=>e.time-t.time))}shift(){return void 0!==this.stack.shift()}clear(){this.stack=[]}getStack(){return this.stack}goToReport(e){let t={};e.forEach(((e,n)=>{t[`logStep-${n}`]=e})),xt({type:"custom",event:`${A.origin}.${A.module}.USERLOG`,msg:Object.assign({userLogInfo:Object.assign({},t)},Me)}),Fe.after(Pe.BREABCRUMB,this.stack),this.clear()}}):null;let We=null;const Je=s();function qe(e){const t=(null==A?void 0:A.config["user-log"])||null;return!!t&&t.find((t=>t===e))}function Ve(){return"log"!==(null==Je?void 0:Je.logType)}class Ye{constructor(){}handleHistory(e){const{from:t,to:n}=e,{relative:r}=y(t),{relative:o}=y(n);Ve()&<($e.HISTORY,"history跳转",{from:r||"/",to:o||"/",url:location.href}),qe(Ae.HISTORY)&&Ge.push({category:ke.HISTORY,status:je.OK,time:l(),msg:{from:r||"/",to:o||"/"}})}handleHashChange(e){const{oldURL:t,newURL:n}=e,{relative:r}=y(t),{relative:o}=y(n);Ve()&<($e.HASHCHANGE,"hashChange跳转",{from:r,to:o,url:location.href}),qe(Ae.HASH)&&Ge.push({category:ke.HASHCHANGE,status:je.OK,time:l(),msg:{from:r,to:o}})}handleDomClick(e){const t=function(e){const t=e.target.tagName.toLowerCase();if("html"===t||"body"===t)return"";let n=e.target.outerHTML;"path"===t&&(n=n.replace(/ d="[^"]*"/,""));const r=n.match(/<[^>]*>/),o=e.target.childNodes.length>0&&3===e.target.childNodes[0].nodeType?e.target.childNodes[0].nodeValue:"";return r?r[0]+o+"":""}(e);t&&(Ve()&<($e.CLICK,"点击",{dom:t,url:location.href}),qe(Ae.DOM)&&Ge.push({category:ke.CLICK,status:je.OK,time:l(),msg:{clickDom:t}}))}handleScroll(){const e=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop;Ve()&<($e.SCROLL,"页面滚动",{top:e,url:location.href}),qe(Ae.SCROLL)&&Ge.push({category:ke.SCROLL,status:je.OK,time:l(),msg:{top:e}})}handleJsError(e){Ve()&<($e.ERROR,"js报错",{message:e.message,url:location.href}),qe(Ae.JS)&&Ge.push({category:ke.ERROR,status:je.ERROR,time:e.time||l(),msg:{message:e.message}})}handlePromiseError(e){Ve()&<($e.UNHANDLEDREJECTION,"rejection错误",{message:e.message,url:location.href}),qe(Ae.PROMISE)&&Ge.push({category:ke.UNHANDLEDREJECTION,status:je.ERROR,time:e.time||l(),msg:{message:e.message}})}handleResourceError(e){Ve()&<($e.RESOURCE,"resource错误",{message:e.message,name:null==e?void 0:e.name,url:location.href}),qe(Ae.RESOURCE)&&Ge.push({category:ke.RESOURCE,status:je.ERROR,time:e.time||l(),msg:{message:e.message,name:null==e?void 0:e.name}})}handleWhiteScreen(){Ve()&<($e.WHITE,"白屏错误",{url:location.href}),qe(Ae.WHITE)&&Ge.push({category:ke.WHITE,status:je.ERROR,time:l(),msg:{url:location.href}})}handleRequest(e){var t,n,r,o;Ve()&<(Xe(e.httpCode),`请求httpCode:${e.httpCode}`,{api:null==e?void 0:e.api,traceId:(null===(t=null==e?void 0:e.headers)||void 0===t?void 0:t["X-Bili-Trace-Id"])||(null===(n=null==e?void 0:e.headers)||void 0===n?void 0:n["Bili-Trace-Id"])||"",code:null==e?void 0:e.code,message:null==e?void 0:e.msg,url:location.href}),qe(Ae.API)&&Ge.push({category:ke.API,status:Xe(e.httpCode),time:l(),msg:{api:null==e?void 0:e.api,traceId:(null===(r=null==e?void 0:e.headers)||void 0===r?void 0:r["X-Bili-Trace-Id"])||(null===(o=null==e?void 0:e.headers)||void 0===o?void 0:o["Bili-Trace-Id"])||"",code:null==e?void 0:e.code,message:null==e?void 0:e.msg}})}}function Xe(e){return e?e>=200&&e<300?$e.APISUCCESS:$e.APIERROR:$e.APIUNKNOWN}We||(We=new Ye);let ze=v();const Qe={historyReplace(){if(!function(){const e=i.chrome,t=e&&e.app&&e.app.runtime,n="history"in i&&!!i.history.pushState&&!!i.history.replaceState;return!t&&n}())return;const e=i.onpopstate;function t(e){return function(){for(var t=arguments.length,n=new Array(t),r=0;r2?n[2]:void 0;if(o){const e=ze,t=String(o);ze=t,We.handleHistory({from:e,to:t})}return e.apply(this,n)}}i.onpopstate=function(){const t=v(),n=ze;ze=t,We.handleHistory({from:n,to:t});for(var r=arguments.length,o=new Array(r),i=0;i=0;--i){var s=this.tryEntries[i],c=s.completion;if("root"===s.tryLoc)return o("end");if(s.tryLoc<=this.prev){var a=r.call(s,"catchLoc"),l=r.call(s,"finallyLoc");if(a&&l){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),C(n),g}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;C(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:k(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),g}},t}var tt="https://s1.hdslb.com/bfs/static/dynamic-import/es-module-shims@1.9.0.js",nt=function(e,t,n){return new Promise((function(r,o){var i=function(e){try{c(n.next(e))}catch(e){o(e)}},s=function(e){try{c(n.throw(e))}catch(e){o(e)}},c=function(e){return e.done?r(e.value):Promise.resolve(e.value).then(i,s)};c((n=n.apply(e,t)).next())}))};function rt(e){return new Promise((function(t,n){var r=document.createElement("script");r.onload=function(){t(window[e.name]),r.remove()},r.onerror=n,r.src=e.url,document.head.appendChild(r)}))}const ot=s(),it="https://s1.hdslb.com/bfs/static/log-manipulator@0.2.1/index.js";function st(e){const t=document.cookie.match(new RegExp("(^| )"+e+"=([^;]+)"));return t?decodeURIComponent(t[2]):null}function ct(){try{const e=null==A?void 0:A.config.track,t=null==A?void 0:A.config["track-gray"],n=st("buvid3"),r=st("DedeUserID");return!(!r||!function(e,t){if("string"==typeof t&&(t=parseFloat(t)),t<0||t>1)throw new Error("Rate must be between 0 and 1");return parseInt(null==e?void 0:e.substring(0,2),16)>256*t}(n,t))||!!e&&(0!==Object.keys(e).length&&(Array.isArray(null==e?void 0:e.mid)?(null==e?void 0:e.mid.includes(r))||(null==e?void 0:e.mid.includes("*")):!!Array.isArray(null==e?void 0:e.buvid)&&((null==e?void 0:e.buvid.includes(n))||(null==e?void 0:e.buvid.includes("*")))))}catch(e){return!1}}function at(){const e=ct(),t=function(){var e;return null===(e=null==A?void 0:A.config["user-log"])||void 0===e?void 0:e.length}();return e&&t?"all":e&&!t?"track":!e&&t?"log":"none"}function lt(e,t,n){let r=`[${e}]: ${t} ${"string"==typeof n?n:JSON.stringify(n||"")}`;Ce.add(r)}function ut(e){let n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return new Promise(((r,o)=>t(this,void 0,void 0,(function*(){const t=new FormData;t.append("log",e),t.append("project",function(){const{spmId:e,origin:t,module:n}=ot.options;return`${e||c}.${t}.${n}`}()),t.append("is_player_log",String(n));try{const e=yield fetch("https://api.bilibili.com/x/web-frontend/action-log/upload",{method:"POST",body:t,credentials:"include"});if(!e.ok)throw new Error(`HTTP error! status: ${e.status}`);const n=yield e.json();r(n)}catch(e){o("Failed to upload log: "+e)}}))))}function dt(e){return t(this,void 0,void 0,(function*(){try{const{reportLogs:t}=yield function(e){return nt(this,null,et().mark((function t(){var n;return et().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,rt({name:"importShim",url:tt});case 2:return n=t.sent,t.abrupt("return",n(e));case 4:case"end":return t.stop()}}),t)})))}((null==A?void 0:A.config["player-log-umd"])||it);return new Promise(((n,r)=>{t("boolean"==typeof e?"all":e).then((e=>{if(e){const t=new Blob([e],{type:"text/plain;charset=utf-8"});n(ut(t,!0))}r("log not found")}))}))}catch(e){console.error("Failed to upload play log: "+e)}}))}function ft(){return t(this,void 0,void 0,(function*(){try{if(!r())return;if(!window.indexedDB)return;if(Ce.deleteIndexedDB("MIRROR_TRACK"),ot.logType=at(),"none"===ot.logType)return;"log"!==ot.logType&&(yield Ce.createIndexedDB(),function(){const e=st("buvid3")||"-",t=st("DedeUserID")||"-";let n=performance.getEntriesByType("navigation");if(n.length>0)if("reload"===n[0].type)lt($e.REFRESH,"页面刷新",{url:location.href,mid:t,buvid:e});else{lt($e.LOAD,"页面载入",{url:location.href,mid:t,buvid:e});const n=window.innerWidth,r=window.innerHeight;lt($e.DEVICE,"设备信息",{ua:navigator.userAgent,window_size:`${n}*${r}`,url:location.href})}i.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState?lt($e.PAGETABSTATUS,"选项卡被激活",{url:location.href}):"hidden"===document.visibilityState&<($e.PAGETABSTATUS,"选项卡被隐藏",{url:location.href})})),i.addEventListener("beforeunload",(()=>{lt($e.PAGECLOSE,"页面关闭",{url:location.href})}))}()),Qe.historyReplace(),Qe.hashChangeReplace(),Qe.domClickReplace(),Qe.scrollReplace()}catch(e){console.error("Failed to start tracking: "+e)}}))}function ht(e,n){return new Promise(((r,o)=>t(this,void 0,void 0,(function*(){window.indexedDB?e?dt(e).then((()=>{r("player log upload success")})):new Promise(((e,t)=>{Ce.getAll().then((n=>{ut(n).then((t=>{e(t)})).catch((e=>{t(e)}))})).catch((e=>{t(e)}))})).then((()=>{if(n)return Ce.clearStore("MIRROR_TRACK_V2","log"),void r("web log upload success, and clear db");r("web log upload success")})):o("not support indexedDB")}))))}let pt=null,mt=null,gt=6e4*((null==A?void 0:A.config["poll-time"])||5);const vt="BILI_MIRROR_REPORT_POOL";(null==A?void 0:A.config["poll-time"])||setTimeout((()=>{gt=6e4*((null==A?void 0:A.config["poll-time"])||5)}),1e3);const yt=()=>{try{let e=JSON.parse(localStorage.getItem(vt)||"{}");if(!Object.keys(e).length)return;Object.entries(e).forEach((e=>{let[t,n]=e;pt.tech(t,n)})),localStorage.setItem(vt,"{}")}catch(e){}},wt=()=>{mt||(mt=new Be,mt.repeat(yt,gt),a(i,"beforeunload",(function(){yt(),bt()})))},bt=()=>{pt&&pt.flush&&pt.flush(),null==mt||mt.clear()},Et="_BiliGreyResult",Rt=()=>{const e=Ot("offline-version"),t=Ot("offline-name"),n=Ot("offline-plat"),r=Ot("offline-type");return e?{offlineVersion:e,offlineName:t,offlinePlat:n,offlineType:r}:{}},Ot=e=>{var t;return(null===(t=document.getElementsByTagName("meta")[e])||void 0===t?void 0:t.content)||void 0},_t=(()=>{if(!r())return{};if(!i[Et])return{};const e=i[Et];var t={};Object.entries(e).forEach((e=>{let[n,r]=e;t[`${Et}_${n}`]=r}));const n=Rt();return Object.assign(Object.assign({},t),n)})(),St=[];let It=!1,Tt="",Nt=null;const Ct=e=>{let t="";return t=e.diyevent?e.eventId||e.event:e.otherSpmId?`${e.otherSpmId}.${e.eventId}`:(null==A?void 0:A.spmId)?`${null==A?void 0:A.spmId}.${e.eventId}`:`${c}.${e.eventId}`,t};function Pt(){if(St.length&&!It){It=!0;const[e,t,n,r]=St.shift();if("middleWare"===t){if(Nt)return It=!1,At(n,r),void Pt();e(!0).then((e=>{var t;It=!1,Nt=e,pt!==(t=Nt)&&(pt=t),$t(n,r),Pt()}))}else e(!1,r).then((()=>{It=!1,t&&n&&t(n,r||void 0),Pt()}))}}const kt=e=>{if(Ht(e,"custom"))return;const t=Tt?window[Tt]:window.__biliMirrorPbInstance__;e=Bt(e);const n=Ct(e);null==t||t[e.type](n,e.msg)},Lt=(e,t)=>{if(Ht(e,"tech"))return;t&&Object.keys(t).length>0&&Mt(t),e=Bt(e);const n=Ct(e),r=Tt?window[Tt]:window.__biliMirrorPbInstance__,o=Object.assign(Object.assign(Object.assign({},e.msg),_t),{mirrorVersion:_,type:e.type||"custom"});null==r||r.tech(n,o)},jt=e=>{St.push([Dt,kt,e]),Pt()},xt=(e,t)=>{St.push([Dt,Lt,e,t]),Pt()},At=(e,t)=>new Promise(((n,r)=>{try{o=e.msg,"none"!==at()&&Qe.apiReplace(o),!e.msg.message&&e.msg.msg&&(e.msg.message=e.msg.msg),Nt?($t(e,t),n()):(St.push([Dt,"middleWare",e,t]),Pt(),n())}catch(e){r(e)}var o})),$t=(e,t)=>{t&&void 0!==(null==t?void 0:t.isBatch)||(t=Object.assign(t||{},{isBatch:!1}));const n=((null==t?void 0:t.spmId)||c)+"."+((null==t?void 0:t.origin)||(null==A?void 0:A.origin))+"."+((null==t?void 0:t.module)||(null==A?void 0:A.module));(null==t?void 0:t.isBatch)?((e,t,n)=>{var r;const o=(null===(r=null==t?void 0:t.api)||void 0===r?void 0:r.split("?")[0])||"";try{let t=JSON.parse(localStorage.getItem(vt)||"{}");t[e]||(t[e]=Object.assign(Object.assign({},n),De)),t[e][o]?t[e][o]++:t[e][o]=1,localStorage.setItem(vt,JSON.stringify(t))}catch(e){}wt()})(n+(t.eventId||".DATA.successReport"),e.msg,Object.assign({type:"custom",mirrorVersion:_},_t)):Nt.tech(n+(t.eventId||".ERROR.errorReport"),Object.assign(Object.assign({type:e.type||"custom",mirrorVersion:_},e.msg),_t))},Mt=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{feature:{tech:!0}};window.__biliMirrorPbInstance__.options=Object.assign({feature:{tech:!0}},e)},Dt=function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;try{return new Promise(((n,o)=>{if(r()||o("not support in server"),e){const e={feature:{tech:!0},autoPv:!1,batch:!1};if(window.ReporterPb){const t=new window.ReporterPb(Object.assign({},e));n(t)}else P(Object.assign({},e)).then((e=>{n(e)}))}else{const e=(null==A?void 0:A.pbOtherNameIns)?null==A?void 0:A.pbOtherNameIns:"";if(f.isObject(window[e])&&Object.keys(window[e]).length)Tt=e,console.warn(`Is using ${e} to report,Please confirm open [tech] config`),n();else if(window.__biliMirrorPbInstance__)n();else{const e={feature:{tech:!0},extra:Object.assign(Object.assign({},_t),{mirrorVersion:_})};let r={};"0.0"===c&&A.spmId&&(r.spmPrefix=A.spmId),r=O(e,t||((null==A?void 0:A.pbOptions)||{})),window.ReporterPb?(window.__biliMirrorPbInstance__=new window.ReporterPb(r),n()):P(Object.assign({},r)).then((e=>{window.__biliMirrorPbInstance__=e,n()}))}}}))}catch(e){console.error("bili-mirror:load pb-report-Error load failed:",e)}};function Ht(e,t){var n;const r=e.eventId||e.event,o=null===(n=A.config)||void 0===n?void 0:n["limit-control"];if(!o||!Object.keys(o).length)return!1;const i="tech"===t?o.tech:o.custom;return!(!i||!i.length)&&i.some((e=>-1!==r.indexOf(e.key)&&g(e.val)))}function Bt(e){e.event&&!e.eventId&&(e.eventId=e.event);return e.eventId.split(".").length<=1&&(e.eventId=`${null==A?void 0:A.origin}.${null==A?void 0:A.module}.${e.eventId}`),"appear"!==e.type&&"show"!==e.type||(e.type="exposure"),e}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function Ft(e,t){return e(t={exports:{}},t.exports),t.exports}var Ut=Ft((function(e,t){e.exports=function(){function e(e){return!isNaN(parseFloat(e))&&isFinite(e)}function t(e){return e.charAt(0).toUpperCase()+e.substring(1)}function n(e){return function(){return this[e]}}var r=["isConstructor","isEval","isNative","isToplevel"],o=["columnNumber","lineNumber"],i=["fileName","functionName","source"],s=["args"],c=["evalOrigin"],a=r.concat(o,i,s,c);function l(e){if(e)for(var n=0;n-1&&(e=e.replace(/eval code/g,"eval").replace(/(\(eval at [^()]*)|(,.*$)/g,""));var t=e.replace(/^\s+/,"").replace(/\(eval code/g,"(").replace(/^.*?\s+/,""),r=t.match(/ (\(.+\)$)/);t=r?t.replace(r[0],""):t;var o=this.extractLocation(r?r[1]:t),i=r&&t||void 0,s=["eval",""].indexOf(o[0])>-1?void 0:o[0];return new n({functionName:i,fileName:s,lineNumber:o[1],columnNumber:o[2],source:e})}),this)},parseFFOrSafari:function(e){return e.stack.split("\n").filter((function(e){return!e.match(i)}),this).map((function(e){if(e.indexOf(" > eval")>-1&&(e=e.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,":$1")),-1===e.indexOf("@")&&-1===e.indexOf(":"))return new n({functionName:e});var t=/((.*".+"[^@]*)?[^@]*)(?:@)/,r=e.match(t),o=r&&r[1]?r[1]:void 0,i=this.extractLocation(e.replace(t,""));return new n({functionName:o,fileName:i[0],lineNumber:i[1],columnNumber:i[2],source:e})}),this)},parseOpera:function(e){return!e.stacktrace||e.message.indexOf("\n")>-1&&e.message.split("\n").length>e.stacktrace.split("\n").length?this.parseOpera9(e):e.stack?this.parseOpera11(e):this.parseOpera10(e)},parseOpera9:function(e){for(var t=/Line (\d+).*script (?:in )?(\S+)/i,r=e.message.split("\n"),o=[],i=2,s=r.length;i/,"$2").replace(/\([^)]*\)/g,"")||void 0;i.match(/\(([^)]*)\)/)&&(t=i.replace(/^[^(]+\(([^)]*)\)$/,"$1"));var c=void 0===t||"[arguments not available]"===t?void 0:t.split(",");return new n({functionName:s,args:c,fileName:o[0],lineNumber:o[1],columnNumber:o[2],source:e})}),this)}})}));const Gt=e=>{const t=e.target;if(null==t?void 0:t.localName){const e=function(e){return{time:l(),message:e.src||e.href||"",name:e.localName}}(t);return Object.assign(Object.assign({},e),{type:"resourceError"})}return null};var Wt;!function(e){e.ERROR="error",e.OK="ok"}(Wt||(Wt={}));let Jt=!1;const qt=[];let Vt=!1;const Yt=()=>({js_event:`${A.origin}.${A.module}.ERROR.jsError`,resource_event:`${A.origin}.${A.module}.ERROR.resourceError`,unhandledrejection_event:`${A.origin}.${A.module}.ERROR.rejectionError`,performance_event:`${A.origin}.${A.module}.PERFORMANCE`}),Xt=e=>{const t=(n=(null==e?void 0:e.message)||(null==e?void 0:e.fileName),window.btoa(decodeURIComponent(encodeURIComponent(n))));var n;return qt.includes(t)?(console.warn(`Duplicate error, not reported, ${null==e?void 0:e.message}`),!1):(qt.push(t),!0)},zt=()=>{var e,t,n,r;const o=(null!==(e=null==i?void 0:i.screen.width)&&void 0!==e?e:0)<=100||(null!==(t=null==i?void 0:i.screen.height)&&void 0!==t?t:0)<=100||(null!==(n=null==i?void 0:i.innerWidth)&&void 0!==n?n:0)<=100||(null!==(r=null==i?void 0:i.innerHeight)&&void 0!==r?r:0)<=100;return Vt||o||Qt()},Qt=()=>{var e,t,n;const r=(null===(e=null==A?void 0:A.config)||void 0===e?void 0:e["limit-domain"])||[];if(r.length){if(!r.some((e=>location.href.includes(e))))return!0}const o=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(0===e.length)return!1;try{return e.some((e=>new RegExp(String.raw`${e}`).test(navigator.userAgent)))}catch(e){return!1}}(null===(n=null===(t=null==A?void 0:A.config)||void 0===t?void 0:t.white)||void 0===n?void 0:n.ua);return!!o},Zt={_reportEvent(e,n,r){var o;return t(this,void 0,void 0,(function*(){(yield Fe.before(e,n))&&(xt({type:e.toLowerCase().includes("performance")?"performance":"error",eventId:r,msg:n},null!==(o=A.pbOptions)&&void 0!==o?o:{}),Fe.after(e,n))}))},handleError(e){return t(this,void 0,void 0,(function*(){if(zt())return;const t=e.target;try{!t||e.target&&!e.target.localName?yield this.handlerJsErrorFn(e):(null==t?void 0:t.localName)&&(yield this.handlerResourceErrorFn(e))}catch(e){console.warn("bili-mirror: handleError-Error parsing failed:",e)}}))},handlerJsErrorFn(e){var n,r,o;return t(this,void 0,void 0,(function*(){const t=(e=>{var t;const n=e.target;if(!n||e.target&&!(null===(t=e.target)||void 0===t?void 0:t.localName)){let t=Kt.parse(n?e.error:e).slice(0,10),r=[];t.forEach((e=>{let{source:t}=e;const n=t?t.split(" ").join("").split("./"):"";r.push(n)}));let o=Kt.parse(n?e.error:e)[0],{fileName:i,columnNumber:s,lineNumber:c}=o;return{type:"error",time:l(),message:e.message,fileName:i,line:c,column:s,stack:JSON.stringify(r)}}return null})(e),i=null===(r=null===(n=null==A?void 0:A.config)||void 0===n?void 0:n.white)||void 0===r?void 0:r.error,s=(null===(o=null==A?void 0:A.config)||void 0===o?void 0:o["filter-end-js"])||!1;!p(t,i,s)&&Xt(t)&&(this._reportEvent(Pe.ERROR,t,Yt().js_event),Qe.jsErrorReplace(t))}))},handlerResourceErrorFn(e){var n,r;return t(this,void 0,void 0,(function*(){const t=Gt(e);if(!t||!t.message.trim().length)return;const o=null===(r=null===(n=null==A?void 0:A.config)||void 0===n?void 0:n.white)||void 0===r?void 0:r.resource;!p(t,o)&&Xt(t)&&(this._reportEvent(Pe.RESOURCE,t,Yt().resource_event),Qe.resourceErrorReplace(t))}))},unhandRejection(e){var n,r,o;return t(this,void 0,void 0,(function*(){try{if(zt())return;const t=(e=>{let t=Kt.parse(e.reason).slice(0,10),n=[];t.forEach((e=>{let{source:t}=e;const r=t?t.split(" ").join("").split("./"):"";n.push(r)}));let r=Kt.parse(e.reason)[0],{fileName:o,columnNumber:i,lineNumber:s}=r;var c;return{type:"rejectionError",time:l(),message:(c=e.reason.message||e.reason.stack,f.isString(c)?c:f.isUndefined(c)?"undefined":JSON.stringify(c)),fileName:o,line:s,column:i,stack:JSON.stringify(n)}})(e),i=null===(r=null===(n=null==A?void 0:A.config)||void 0===n?void 0:n.white)||void 0===r?void 0:r.rejection,s=(null===(o=null==A?void 0:A.config)||void 0===o?void 0:o["filter-end-js"])||!1;!p(t,i,s)&&Xt(t)&&(this._reportEvent(Pe.UNHANDLEDREJECTION,t,Yt().unhandledrejection_event),Qe.promiseErrorReplace(t))}catch(e){console.warn("bili-mirror: unhandRejection-Error parsing failed:",e)}}))},handlePerformance(){return t(this,void 0,void 0,(function*(){try{if(zt())return;if(!PerformanceObserver||!(null===PerformanceObserver||void 0===PerformanceObserver?void 0:PerformanceObserver.supportedEntryTypes))return;if(g(A.config["white-performance-rate"]))return;Se((e=>t(this,void 0,void 0,(function*(){let{name:t,value:n}=e;if(!n||n<0)return;const r="PAGETIME"===t?Object.assign({},null==e?void 0:e.data):Object.assign({},e);this._reportEvent(Pe.PERFORMANCE,r,`${Yt().performance_event}.${t}`)}))))}catch(e){console.warn("bili-mirror: performance-Error parsing failed:",e)}}))},handleWhiteScreen(e){try{if(zt())return;!function(e){if(null==e?void 0:e.debug){Jt=!0;var n=document.createElement("canvas");document.body.appendChild(n);var r=n.getContext("2d");n.width=window.innerWidth,n.height=window.innerHeight,n.style.position="absolute",n.style.top="0",n.style.left="0",n.style.zIndex="9999"}const o=e.maxLoop||9,c=e.elemArry||e.checkDom||["html","body","#app"],a=e.callback||function(){},l=s();let u=0;const d=[];let f=[],h={};function p(e){return e.id?"#"+e.id:e.className&&"string"==typeof e.className?"."+e.className.split(" ").filter((e=>!!e)).join("."):e.nodeName.toLowerCase()}function m(t){const n=p(t);e.isSkeleton&&(u?f.push(n):d.push(n));let r=!1;if(!n||!c)return r;for(let e=0;e<=c.length;e++)if(c[e]&&n.match(c[e])){r=!0;break}return r}function g(){return t(this,void 0,void 0,(function*(){if(!document||!document.elementsFromPoint)return void console.warn("当前浏览器不支持elementsFromPoint方法,白屏检测跳过");if(!(yield Fe.before(Pe.WHITESCREEN)))return;h.check_list=c;let t=!0;for(let e=1;e<=9;e++){const n=i.innerWidth*e/10,r=i.innerHeight/2,o=i.innerWidth/2,s=i.innerHeight*e/10,c=document.elementsFromPoint(n,r),a=document.elementsFromPoint(o,s),l=[];h[`pointX-${n}-${r}`]||(h[`pointX-${n}-${r}`]=[]),Jt&&v(n,r);for(let e=0;e=o&&(xt({type:"error",eventId:`${A.origin}.${A.module}.ERROR.whiteScreen`,msg:{_BiliCheckDom_Point:Object.assign({},h)}}),Qe.whiteErrorReplace()),Fe.after(Pe.WHITESCREEN,Object.assign({},h))}))}function v(e,t){r.beginPath(),r.arc(e,t,10,0,2*Math.PI),r.fill()}function y(){u>=o&&l._loopTimer?(clearTimeout(l._loopTimer),l._loopTimer=null):l._loopTimer=setTimeout((()=>{u++,e.isSkeleton&&(f=[]),g()}),1e3)}e.isSkeleton?"complete"!=document.readyState&&g():"complete"===document.readyState?g():i.addEventListener("load",g)}(e.whiteScreen)}catch(e){console.error("bili-mirror: whiteScreen错误解析异常:",e)}}};"undefined"!=typeof window&&window.addEventListener("beforeunload",(()=>{Vt=!0}));const en=s();let tn=null;const nn=["xmlhttprequest","fetch","img","image","link","css","video","iframe","script"],rn={API:"xmlhttprequest,fetch",IMG:"img,image",CSS:"link,css",JS:"script",VIDEO:"video",IFRAME:"iframe"};const on=r()?en.resourceTimeIns||(en.resourceTimeIns=new class{constructor(){this.regexCache=new Map,this.config=A.config["resource-time"]||{},this.resourceWaitList=[],this.disablePush=!1}on(){A.config["resource-time"]&&(this.config=A.config["resource-time"],0!==Object.keys(this.config).length&&PerformanceObserver&&(null===PerformanceObserver||void 0===PerformanceObserver?void 0:PerformanceObserver.supportedEntryTypes)&&(this._getAllData(),this._createObserver()))}destroy(){tn&&tn.disconnect()}_getAllData(){const e=performance.getEntriesByType("resource");(e||e.length)&&(e.forEach((e=>{this.resourceWaitList.push(e)})),this._handlerResourceInit())}_handlerResourceInit(){for(this.disablePush=!0;this.resourceWaitList.length;){let e=this.resourceWaitList.shift();if(!this._isCheckResource(e))continue;const t=this._computeResourceData_(e);this._waitRequest(t)}this.disablePush=!1}_waitRequest(e){"requestIdleCallback"in window?this._reportResourceTime(e):setTimeout((()=>{this._reportResourceTime(e)}),0)}_reportResourceTime(e){xt({type:"performance",eventId:`${A.origin}.${A.module}.PERFORMANCE.RESOURCETIME`,msg:e})}_isCheckResource(e){if(!nn.includes(e.initiatorType))return!1;if(!Object.keys(this.config).length)return!1;let t=!1;for(let n in this.config){if(rn[n].split(",").includes(e.initiatorType)){if(!this.config[n])continue;if(Array.isArray(this.config[n])&&this.config[n].length)for(let r=0;r{e.getEntries().forEach((e=>{this.resourceWaitList.push(e.toJSON())})),this.disablePush||this._handlerResourceInit()})),tn.observe({entryTypes:["resource"]})}}):null;function sn(e){if(r()){if(a(i,"error",(function(e){Zt.handleError(e)}),!0),a(i,"unhandledrejection",(function(e){Zt.unhandRejection(e)})),Zt.handlePerformance(),null==e?void 0:e.whiteScreen)try{Zt.handleWhiteScreen(e)}catch(e){console.error("bili-mirror: whiteScreen错误解析异常:",e)}if(A.config["resource-time"]&&Object.keys(A.config["resource-time"]).length)try{on.on()}catch(e){on.destroy(),console.warn("bili-mirror:resource-watch error",e)}}}let cn=null;class an{constructor(){this.checkInterval=null,this.checkTimeout=null,this.originalMethods=new Map}init(){this.monitorMethods(window)}monitorMethods(e){for(const t of Object.getOwnPropertyNames(e))try{const n=Object.getOwnPropertyDescriptor(e,t);if(n&&"function"==typeof n.value){n.value.toString().includes("[native code]")&&this.originalMethods.set(t,!0)}}catch(e){console.error(`Error getting descriptor for ${t}:`,e)}}checkOverwrittenMethods(){for(const[e]of this.originalMethods.entries())try{window[e].toString().includes("[native code]")||(console.warn(`Method ${e} has been overwritten.`),xt({type:"error",eventId:`${A.origin}.${A.module}.ERROR.METHOD_OVERWRITE`,msg:{url:window.location.href,method:e}}))}catch(t){console.error(`Error checking method ${e}:`,t)}}startCheck(){null===this.checkInterval&&null===this.checkTimeout?(this.checkInterval=window.setInterval((()=>this.checkOverwrittenMethods()),5e3),this.checkTimeout=window.setTimeout((()=>this.stopCheck()),12e4)):console.warn("Check is already running.")}stopCheck(){null!==this.checkInterval&&(clearInterval(this.checkInterval),this.checkInterval=null),null!==this.checkTimeout&&(clearTimeout(this.checkTimeout),this.checkTimeout=null)}}try{!cn&&r()?cn=new an:console.log("mirrorMonitorMethods is already defined")}catch(e){console.error("bili-mirror:MethodMonitor init error:",e)}var ln;const un=s(),dn="__MIRROR_CONFIG__",fn=e=>{!function(e){const t=x();null==t||t.updateModule(e)}(e)},hn=e=>{r()&&jt(e)},pn=(e,t)=>{r()&&xt(e,t)},mn=e=>{r()&&Mt(e)},gn=(e,t)=>{r()&&jt({type:"pv",eventId:"0.0",msg:e,otherSpmId:t||null})},vn=e=>{r()&&h(e.key)&&xt({type:"custom",eventId:e.eventId,diyevent:!0,msg:Object.assign(Object.assign({exclusiveFrom:(null==e?void 0:e.key)||""},e.msg),Me)})},yn=function(){return ht(arguments.length>0&&void 0!==arguments[0]&&arguments[0],arguments.length>1&&void 0!==arguments[1]&&arguments[1])},wn=(e,t,n)=>{lt(e,t,n)},bn=()=>Ce.getAll(!1);function En(e){r()&&(un.isInited||(un.isInited=!0,un.mirrorInitMode||(un.mirrorInitMode=xe.DEFAULT),$(e).then((()=>t(this,void 0,void 0,(function*(){var t;yield Dt();(yield Fe.before(Pe.INIT,e))&&((null===(t=null==e?void 0:e.config)||void 0===t?void 0:t.isMonitorMethod)&&(null==cn||cn.init(),null==cn||cn.startCheck()),sn(null==e?void 0:e.config),ft(),Fe.after(Pe.INIT,e),console.info("%c%s","line-height: 30px; color: #FF6699",`bili-fe-mirror:${I}`))})))).catch((e=>{console.warn(e)}))))}const Rn=e=>{Zt.handleError(e)},On=(e,t)=>{if(r())return At(e,t)},_n=e=>{if(!r())return;if(!h(e.name))return;const t=`${A.origin}.${A.module}.PERFORMANCE.${e.name}`;xt({type:"performance",eventId:t,msg:{name:e.name,value:e.value}})},Sn=function(){};function In(e,t){window[e]||(window[e]=t)}if(r()&&(In("__INITIAL_MIRROR__",En),In("__MIRROR_REPORT__",{techReportPb:pn,customReportPb:hn,pbReportPv:gn,changePbOptions:mn,canBatchTechReport:On,customPerformanceQuota:_n,exclusiveBisReport:vn,changeMirrorModule:fn,mirrorTechPvReport:Sn,trackLogReport:yn,trackCustomLog:wn,trackGetLog:bn,_mirrorHandleErrorReport:Rn}),window[dn]&&f.isObject(window[dn]))){const e=window[dn];(null===(ln=e.config)||void 0===ln?void 0:ln.isAutoInit)&&(!un.mirrorInitMode&&(un.mirrorInitMode=xe.AUTO),En(e))}var Tn={SDK_NAME:S,SDK_VERSION:I,init:En,install:function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=e.config.errorHandler;e.config.errorHandler=function(e,t,r){Zt.handleError(e),n&&n.apply(null,[e,t,r]),console.error(e)},En(t)},errorBoundary:e=>{Zt.handleError(e)}};e.canBatchTechReport=On,e.changeMirrorModule=fn,e.changePbOptions=mn,e.customPerformanceQuota=_n,e.customReport=hn,e.customReportPb=hn,e.default=Tn,e.exclusiveBisReport=vn,e.mirrorTechPvReport=Sn,e.pbReportPv=gn,e.techReportPb=pn,e.trackCustomLog=wn,e.trackGetLog=bn,e.trackLogReport=yn,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=biliMirror.umd.mini.js.map