web-tracing-core 2.1.0 → 2.1.2

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.
@@ -65,6 +65,9 @@ describe('err', () => {
65
65
 
66
66
  it('firstResource performance should be captured correctly', async () => {
67
67
  const page = await loadTestPage()
68
+ await page.waitForFunction(
69
+ () => (window as any).__WebTracingData__ !== undefined
70
+ )
68
71
  const webTracingData = (await page.evaluate(
69
72
  `window.__WebTracingData__`
70
73
  )) as any[]
@@ -68,6 +68,34 @@ export function replaceLast(str: string, find: string, replace: string) {
68
68
  export async function launchPuppeteer(
69
69
  options?: Parameters<(typeof puppeteer)['launch']>[0]
70
70
  ) {
71
+ const resolveExecutablePath = () => {
72
+ const envPath =
73
+ process.env.PUPPETEER_EXECUTABLE_PATH || process.env.PUPPETEER_EXEC_PATH
74
+ const candidates = [
75
+ envPath,
76
+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
77
+ '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
78
+ '/Applications/Chromium.app/Contents/MacOS/Chromium',
79
+ '/opt/homebrew/bin/chromium',
80
+ '/opt/homebrew/bin/google-chrome',
81
+ '/usr/bin/google-chrome',
82
+ '/usr/bin/chromium-browser',
83
+ '/usr/bin/chromium'
84
+ ].filter(Boolean) as string[]
85
+
86
+ for (const p of candidates) {
87
+ try {
88
+ if (fs.existsSync(p) && fs.statSync(p).isFile()) return p
89
+ } catch {
90
+ continue
91
+ }
92
+ }
93
+ return undefined
94
+ }
95
+
96
+ const resolvedExecutablePath =
97
+ options?.executablePath || resolveExecutablePath()
98
+
71
99
  return await puppeteer.launch({
72
100
  headless: true,
73
101
  defaultViewport: {
@@ -75,6 +103,11 @@ export async function launchPuppeteer(
75
103
  height: 1080
76
104
  },
77
105
  args: ['--no-sandbox'],
106
+ ...(resolvedExecutablePath
107
+ ? { executablePath: resolvedExecutablePath }
108
+ : options?.channel
109
+ ? {}
110
+ : { channel: 'chrome' }),
78
111
  ...options
79
112
  })
80
113
  }
package/dist/README.md CHANGED
@@ -19,6 +19,10 @@
19
19
 
20
20
  [vue3版本 https://github.com/M-cheng-web/web-tracing-examples-vue3](https://github.com/M-cheng-web/web-tracing-examples-vue3)
21
21
 
22
+ [react版本 https://github.com/boychina/web-tracing-examples-react](https://github.com/boychina/web-tracing-examples-react)
23
+
24
+ [nuxt版本 https://github.com/boychina/web-tracing-examples-nuxt](https://github.com/boychina/web-tracing-examples-nuxt)
25
+
22
26
  ## 演示
23
27
  ### 事件监听
24
28
  <img src="https://github.com/M-cheng-web/image-provider/raw/main/web-tracing/image.4388hbrc1gc0.jpg" width="1200" alt="logo" />
@@ -63,6 +67,10 @@
63
67
 
64
68
  针对首屏加载的监控做出更多精细化的东西,例如考虑sdk的绝对轻量化
65
69
 
70
+ ## 三方监控平台
71
+ 目前支持的三方监控平台有:
72
+ + [WebTracingAnalysis](https://github.com/boychina/web-tracing-analysis) : Spring Boot + MySQL + React + Ant Design(支持容器化部署)
73
+
66
74
  ## 联系我
67
75
  <img align="left" width="180" src="https://github.com/M-cheng-web/image-provider/raw/main/web-tracing/image.19hrnxwgkdpc.jpg" />
68
76
 
package/dist/index.cjs CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ if (typeof window === "undefined" && typeof global !== "undefined") {
6
+ global.window = global;
7
+ global.self = global;
8
+ if (!global.requestAnimationFrame) {
9
+ global.requestAnimationFrame = (callback) => setTimeout(callback, 0);
10
+ }
11
+ if (!global.cancelAnimationFrame) {
12
+ global.cancelAnimationFrame = (id) => clearTimeout(id);
13
+ }
14
+ }
15
+
5
16
  function isType(type) {
6
17
  return function(value) {
7
18
  return Object.prototype.toString.call(value) === `[object ${type}]`;
@@ -22,7 +33,7 @@ function isEmpty(wat) {
22
33
  }
23
34
 
24
35
  const isBrowserEnv = isWindow(typeof window !== "undefined" ? window : 0);
25
- const isElectronEnv = !!window?.process?.versions?.electron;
36
+ const isElectronEnv = typeof window !== "undefined" && !!window.process?.versions?.electron;
26
37
  const isTestEnv = typeof navigator !== "undefined" && navigator.userAgent.includes("jsdom") || // @ts-expect-error: jsdom
27
38
  typeof window !== "undefined" && window.jsdom;
28
39
  function getGlobal() {
@@ -681,6 +692,8 @@ function uuid() {
681
692
  return `${guid.slice(0, 8)}-${guid.slice(8, 16)}-${guid.slice(16)}`;
682
693
  }
683
694
  function getCookieByName(name) {
695
+ if (typeof document === "undefined")
696
+ return void 0;
684
697
  const result = document.cookie.match(new RegExp(`${name}=([^;]+)(;|$)`));
685
698
  return result ? result[1] : void 0;
686
699
  }
@@ -764,7 +777,7 @@ const arrayFilter = Array.prototype.filter || function filterPolyfill(fn) {
764
777
  function filter(arr, fn) {
765
778
  return arrayFilter.call(arr, fn);
766
779
  }
767
- const nextTime = window.requestIdleCallback || window.requestAnimationFrame || ((callback) => setTimeout(callback, 17));
780
+ const nextTime = typeof window !== "undefined" && window.requestIdleCallback || typeof window !== "undefined" && window.requestAnimationFrame || ((callback) => setTimeout(callback, 17));
768
781
  function isObjectOverSizeLimit(object, limitInKB) {
769
782
  const serializedObject = JSON.stringify(object);
770
783
  const sizeInBytes = new TextEncoder().encode(serializedObject).length;
@@ -2836,7 +2849,9 @@ function refreshSession() {
2836
2849
  function getSessionId() {
2837
2850
  return getCookieByName(SESSION_KEY) || refreshSession();
2838
2851
  }
2839
- refreshSession();
2852
+ if (typeof document !== "undefined") {
2853
+ refreshSession();
2854
+ }
2840
2855
 
2841
2856
  function is_ipv4(d) {
2842
2857
  return regex_v4.test(d);
@@ -15681,7 +15696,11 @@ class Intersection {
15681
15696
  sendData.emit({
15682
15697
  eventType: SEDNEVENTTYPES.INTERSECTION,
15683
15698
  triggerPageUrl: getLocationHref(),
15684
- ...targetObj
15699
+ threshold: targetObj.threshold,
15700
+ observeTime: targetObj.observeTime,
15701
+ showTime: targetObj.showTime,
15702
+ showEndTime: targetObj.showEndTime,
15703
+ params: targetObj.params
15685
15704
  });
15686
15705
  }
15687
15706
  /**
@@ -1,6 +1,17 @@
1
1
  (function (exports) {
2
2
  'use strict';
3
3
 
4
+ if (typeof window === "undefined" && typeof global !== "undefined") {
5
+ global.window = global;
6
+ global.self = global;
7
+ if (!global.requestAnimationFrame) {
8
+ global.requestAnimationFrame = (callback) => setTimeout(callback, 0);
9
+ }
10
+ if (!global.cancelAnimationFrame) {
11
+ global.cancelAnimationFrame = (id) => clearTimeout(id);
12
+ }
13
+ }
14
+
4
15
  function isType(type) {
5
16
  return function(value) {
6
17
  return Object.prototype.toString.call(value) === `[object ${type}]`;
@@ -21,7 +32,7 @@
21
32
  }
22
33
 
23
34
  const isBrowserEnv = isWindow(typeof window !== "undefined" ? window : 0);
24
- const isElectronEnv = !!window?.process?.versions?.electron;
35
+ const isElectronEnv = typeof window !== "undefined" && !!window.process?.versions?.electron;
25
36
  const isTestEnv = typeof navigator !== "undefined" && navigator.userAgent.includes("jsdom") || // @ts-expect-error: jsdom
26
37
  typeof window !== "undefined" && window.jsdom;
27
38
  function getGlobal() {
@@ -680,6 +691,8 @@
680
691
  return `${guid.slice(0, 8)}-${guid.slice(8, 16)}-${guid.slice(16)}`;
681
692
  }
682
693
  function getCookieByName(name) {
694
+ if (typeof document === "undefined")
695
+ return void 0;
683
696
  const result = document.cookie.match(new RegExp(`${name}=([^;]+)(;|$)`));
684
697
  return result ? result[1] : void 0;
685
698
  }
@@ -763,7 +776,7 @@
763
776
  function filter(arr, fn) {
764
777
  return arrayFilter.call(arr, fn);
765
778
  }
766
- const nextTime = window.requestIdleCallback || window.requestAnimationFrame || ((callback) => setTimeout(callback, 17));
779
+ const nextTime = typeof window !== "undefined" && window.requestIdleCallback || typeof window !== "undefined" && window.requestAnimationFrame || ((callback) => setTimeout(callback, 17));
767
780
  function isObjectOverSizeLimit(object, limitInKB) {
768
781
  const serializedObject = JSON.stringify(object);
769
782
  const sizeInBytes = new TextEncoder().encode(serializedObject).length;
@@ -2835,7 +2848,9 @@
2835
2848
  function getSessionId() {
2836
2849
  return getCookieByName(SESSION_KEY) || refreshSession();
2837
2850
  }
2838
- refreshSession();
2851
+ if (typeof document !== "undefined") {
2852
+ refreshSession();
2853
+ }
2839
2854
 
2840
2855
  function is_ipv4(d) {
2841
2856
  return regex_v4.test(d);
@@ -15680,7 +15695,11 @@
15680
15695
  sendData.emit({
15681
15696
  eventType: SEDNEVENTTYPES.INTERSECTION,
15682
15697
  triggerPageUrl: getLocationHref(),
15683
- ...targetObj
15698
+ threshold: targetObj.threshold,
15699
+ observeTime: targetObj.observeTime,
15700
+ showTime: targetObj.showTime,
15701
+ showEndTime: targetObj.showEndTime,
15702
+ params: targetObj.params
15684
15703
  });
15685
15704
  }
15686
15705
  /**