This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-client-js.git


The following commit(s) were added to refs/heads/master by this push:
     new 093005f  fix: reporting errors when close pages  (#53)
093005f is described below

commit 093005f50561cc68184ef5c71135745f02afbc5b
Author: Qiuxia Fan <[email protected]>
AuthorDate: Thu Apr 29 17:33:11 2021 +0800

    fix: reporting errors when close pages  (#53)
---
 src/services/base.ts | 1 +
 src/services/task.ts | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/src/services/base.ts b/src/services/base.ts
index 16908fe..f6cd98b 100644
--- a/src/services/base.ts
+++ b/src/services/base.ts
@@ -45,6 +45,7 @@ export default class Base {
 
     delete this.logInfo.collector;
     Task.addTask(this.logInfo, collector);
+    Task.finallyFireTasks();
     // report errors within 1min
     setTimeout(() => {
       Task.fireTasks();
diff --git a/src/services/task.ts b/src/services/task.ts
index 952a098..2fb29b8 100644
--- a/src/services/task.ts
+++ b/src/services/task.ts
@@ -33,6 +33,15 @@ class TaskQueue {
     new Report('ERRORS', this.collector).sendByXhr(this.queues);
     this.queues = [];
   }
+
+  public finallyFireTasks() {
+    window.onbeforeunload = () => {
+      if (!this.queues.length) {
+        return;
+      }
+      new Report('ERRORS', this.collector).sendByXhr(this.queues);
+    };
+  }
 }
 
 export default new TaskQueue();

Reply via email to