keeson-web-report-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle.min.js +1 -0
- package/package.json +18 -0
package/bundle.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(o,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((o="undefined"!=typeof globalThis?globalThis:o||self).umd={})}(this,function(o){"use strict";function t(o){const t=[];return t.push(function(o){const t=history.pushState,e=history.replaceState;history.pushState=function(...e){const n=window.location.href,r=t.apply(this,e),i=window.location.href;return n!==i&&o({to:i,from:n}),r},history.replaceState=function(...t){const n=window.location.href,r=e.apply(this,t),i=window.location.href;return n!==i&&o({to:i,from:n}),r};const n=()=>{o({to:window.location.href,from:window.location.href})};return window.addEventListener("popstate",n),()=>{window.removeEventListener("popstate",n),history.pushState=t,history.replaceState=e}}(o)),()=>{t.forEach(o=>o())}}const e={appId:"",env:"production",appUrl:window.location.origin,reportError:!0,reportPromiseReject:!0,reportVueError:!0,vueInstance:null,reportPerformance:!0,reportLongTimeRequest:!0,longTimeRequestThreshold:2e3,reportErrorReqest:!0,reportUserNavigate:!0};class n{records=[];timer=null;options={};constructor(o){this.options={...e,...o}}init(){var o,e,n,r;if(this.options.reportError&&(o=({msg:o,url:t,line:e,col:n,error:r})=>{console.log({msg:o,url:t,line:e,col:n,error:r})},window.onerror=function(t,e,n,r,i){o&&o({msg:t,url:e,line:n,col:r,error:i})}),this.options.reportPromiseReject&&function(o){window.addEventListener("unhandledrejection",function(t){o&&o(t)})}(o=>{console.log("Unhandled Promise Rejection:",o,o.reason)}),this.options.reportVueError&&this.options.vueInstance&&function(o,t){o.config.errorHandler=function(o,e,n){console.error(`Error in ${n}:`,o),t&&t({err:o,vm:e,info:n})}}(this.options.vueInstance,({err:o,vm:t,info:e})=>{console.log("Vue error:",o,t,e)}),this.options.reportPerformance&&function(o){if(PerformanceNavigationTiming){const t=PerformanceNavigationTiming.loadEventEnd-PerformanceNavigationTiming.navigationStart;console.log("Page load time: "+t+"ms");const e=PerformanceNavigationTiming.getEntriesByType("largest-contentful-paint")[0];console.log("Largest Contentful Paint:",e.startTime);const n=PerformanceNavigationTiming.getEntriesByType("first-contentful-paint")[0];console.log("First Contentful Paint:",n.startTime);const r=PerformanceNavigationTiming.getEntriesByType("layout-shift")[0];console.log("Cumulative Layout Shift:",r.value);const i=PerformanceNavigationTiming.getEntriesByType("first-input-delay")[0];console.log("First Input Delay:",i.startTime),console.log("Total Blocking Time:",i.value);const s=PerformanceNavigationTiming.getEntriesByType("first-input")[0];console.log("First Input:",s.startTime);const a=PerformanceNavigationTiming.domainLookupEnd-PerformanceNavigationTiming.domainLookupStart;console.log("DNS查询时间:",a),o&&o({time:t,lcp:e,fcp:n,cls:r,fmp:i,FID:s,dnsTime:a})}}(({time:o,lcp:t,fcp:e,cls:n,fmp:r,FID:i,dnsTime:s})=>{console.log({time:o,lcp:t,fcp:e,cls:n,fmp:r,FID:i,dnsTime:s})}),this.options.reportLongTimeRequest&&(e=o=>{console.log(o)},n=o=>{console.log(o)},r=XMLHttpRequest.prototype.open,XMLHttpRequest.prototype.open=function(o,t,i,s,a){let c=Date.now();this.addEventListener("load",function(){const n=Date.now();e&&e({url:t,method:o,duration:n-c,status:this.status,statusText:this.statusText,response:this.responseText}),console.log("Response:",this.responseText)}),this.addEventListener("error",function(){console.log("Error:",this.statusText),n&&n({url:t,method:o,duration:duration,status:this.status,statusText:this.statusText,response:this.responseText})}),console.log("Request URL:",t),console.log("Request Method:",o),r.call(this,o,t,i,s,a)},function(o,t){var e=window.fetch;window.fetch=function(n,r){console.log("Fetch URL:",n),console.log("Fetch Options:",r),r&&r.headers&&(r.headers["X-Custom-Header"]="Value");let i=Date.now();return e(n,r).then(t=>{const e=Date.now();return o&&o({url:n,method:method,duration:e-i,status:t.status,statusText:t.statusText,response:t.responseText}),console.log("Response:",t),t}).catch(o=>{console.log("Error:",o),t&&t({url:n,method:method,duration:duration})})}}(o=>{console.log(o)},o=>{console.log(o)})),this.options.reportUserNavigate){const o=window.location.href;console.log("current href:",o),t(o=>{console.log("route change:",o)})}}addReportRecord(o){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{try{this.sendReport(JSON.parse(JSON.stringify(this.records))),this.records=[]}catch(o){console.log(o)}},1e3),this.records.push(o)}sendReport(o){this.apiDo(this.records)}}let r;o.init=function(o={}){r||(r=new n(o)),r.init()}});
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "keeson-web-report-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "for web/h5",
|
|
5
|
+
"main": "bundle.min.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"build": "rollup --config rollup.config.js"
|
|
10
|
+
},
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
15
|
+
"rollup": "^4.55.1"
|
|
16
|
+
},
|
|
17
|
+
"files": ["bundle.min.js"]
|
|
18
|
+
}
|