fix: update metric and events (#78)

diff --git a/src/performance/fmp.ts b/src/performance/fmp.ts
index f0002dc..3bd2e00 100644
--- a/src/performance/fmp.ts
+++ b/src/performance/fmp.ts
@@ -145,7 +145,7 @@
           time = this.statusCollector[index].time;
         } else {
           const match = getStyle(item.ele, 'background-image').match(/url\(\"(.*?)\"\)/);
-          let url: string;
+          let url: string = '';
           if (match && match[1]) {
             url = match[1];
           }
diff --git a/src/performance/index.ts b/src/performance/index.ts
index 4cb068c..6c637e0 100644
--- a/src/performance/index.ts
+++ b/src/performance/index.ts
@@ -28,14 +28,14 @@
 
   public async recordPerf(options: CustomOptionsType) {
     let fmp: { fmpTime: number | undefined } = { fmpTime: undefined };
-    if (options.autoTracePerf) {
-      this.perfConfig.perfDetail = await new pagePerf().getPerfTiming();
-      if (options.useFmp) {
-        fmp = await new FMP();
-      }
+    if (options.autoTracePerf && options.useFmp) {
+      fmp = await new FMP();
     }
     // auto report pv and perf data
     setTimeout(() => {
+      if (options.autoTracePerf) {
+        this.perfConfig.perfDetail = new pagePerf().getPerfTiming();
+      }
       const perfDetail = options.autoTracePerf
         ? {
             ...this.perfConfig.perfDetail,
diff --git a/src/services/task.ts b/src/services/task.ts
index 2fb29b8..544c9d0 100644
--- a/src/services/task.ts
+++ b/src/services/task.ts
@@ -35,12 +35,12 @@
   }
 
   public finallyFireTasks() {
-    window.onbeforeunload = () => {
+    window.addEventListener('beforeunload', () => {
       if (!this.queues.length) {
         return;
       }
       new Report('ERRORS', this.collector).sendByXhr(this.queues);
-    };
+    });
   }
 }
 
diff --git a/src/trace/segment.ts b/src/trace/segment.ts
index 836ef7b..1a3d072 100644
--- a/src/trace/segment.ts
+++ b/src/trace/segment.ts
@@ -26,13 +26,12 @@
   // inject interceptor
   xhrInterceptor(options, segments);
   windowFetch(options, segments);
-
-  window.onbeforeunload = function (e: Event) {
+  window.addEventListener('beforeunload', () => {
     if (!segments.length) {
       return;
     }
     new Report('SEGMENTS', options.collector).sendByXhr(segments);
-  };
+  });
   //report per options.traceTimeInterval min
   setInterval(() => {
     if (!segments.length) {