Преглед изворни кода

前端监控:优化采样率的获取方式

Michael Wang пре 6 година
родитељ
комит
4f5d48e885
1 измењених фајлова са 58 додато и 35 уклоњено
  1. 58 35
      public/index.html

+ 58 - 35
public/index.html

@@ -1,40 +1,63 @@
 <!DOCTYPE html>
 <html>
+  <head>
+    <meta charset="utf-8" />
+    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
+    <link rel="icon" href="<%= BASE_URL %>favicon.ico" />
+    <title>网考学生端</title>
+    <script>
+      // 重命名 Electron 提供的 require 详细请参考:https://www.w3cschool.cn/electronmanual/electronmanual-electron-faq.html
+      if (typeof require != "undefined") {
+        window.nodeRequire = require;
+        delete window.require;
+        delete window.exports;
+        delete window.module;
+      }
+    </script>
+  </head>
 
-<head>
-  <meta charset="utf-8">
-  <meta http-equiv="X-UA-Compatible" content="IE=edge">
-  <meta name="viewport" content="width=device-width,initial-scale=1.0">
-  <link rel="icon" href="<%= BASE_URL %>favicon.ico">
-  <title>网考学生端</title>
-  <script>
-    // 重命名 Electron 提供的 require 详细请参考:https://www.w3cschool.cn/electronmanual/electronmanual-electron-faq.html
-    if (typeof (require) != "undefined") {
-      window.nodeRequire = require;
-      delete window.require;
-      delete window.exports;
-      delete window.module;
-    }
-  </script>
-  <script src="https://ecs.qmth.com.cn:8878/electron-config/ali-arms.js"></script>
+  <body>
+    <script>
+      if (location.host.includes("ecs.qmth.com.cn")) {
+        (async function() {
+          var __sampleRateInt = 100;
+          try {
+            var res = await fetch("/electron-config/ali-arms.js", {
+              cache: "no-store"
+            });
+            var text = await res.text();
+            __sampleRateInt = parseInt(text) || 100;
+          } catch (error) {
+            console.log(error);
+          } finally {
+            console.log("ARMS sample: " + __sampleRateInt);
 
-</head>
+            !(function(c, b, d, a) {
+              c[a] || (c[a] = {});
+              c[a].config = {
+                pid: "hworw@48e147d26fd751a",
+                enableSPA: true,
+                sample: __sampleRateInt,
+                sendResource: true,
+                imgUrl: "https://arms-retcode.aliyuncs.com/r.png?"
+              };
+              with (b)
+                with (body)
+                  with (insertBefore(createElement("script"), firstChild))
+                    setAttribute("crossorigin", "", (src = d));
+            })(
+              window,
+              document,
+              "https://retcode.alicdn.com/retcode/bl.js",
+              "__bl"
+            );
+          }
+        })();
+      }
+    </script>
 
-<body>
-  <script>
-    if (location.host.includes('ecs.qmth.com.cn')) {
-      window.__sampleRateInt = parseInt(window.__sampleRateInt) || 100
-      console.log('ARMS sample: ' + window.__sampleRateInt);
-      !(function (c, b, d, a) {
-        c[a] || (c[a] = {}); c[a].config = { pid: "hworw@48e147d26fd751a", enableSPA: true, sample: window.__sampleRateInt, sendResource: true, imgUrl: "https://arms-retcode.aliyuncs.com/r.png?" };
-        with (b) with (body) with (insertBefore(createElement("script"), firstChild))
-        setAttribute("crossorigin", "", src = d)
-      })(window, document, "https://retcode.alicdn.com/retcode/bl.js", "__bl");
-    }
-  </script>
-
-  <div id="app"></div>
-  <!-- built files will be auto injected -->
-</body>
-
-</html>
+    <div id="app"></div>
+    <!-- built files will be auto injected -->
+  </body>
+</html>