@cloudcare/browser-rum 3.2.33 → 3.2.36

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.
Files changed (32) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/domain/assembly.js +1 -0
  4. package/cjs/domain/assembly.js.map +1 -1
  5. package/cjs/domain/contexts/internalContext.js +1 -0
  6. package/cjs/domain/contexts/internalContext.js.map +1 -1
  7. package/cjs/domain/contexts/urlContexts.js +4 -2
  8. package/cjs/domain/contexts/urlContexts.js.map +1 -1
  9. package/cjs/domain/deflate/deflateEncoder.js +36 -41
  10. package/cjs/domain/deflate/deflateEncoder.js.map +1 -1
  11. package/cjs/domain/deflate/deflateWorker.js +1 -1
  12. package/cjs/domain/locationChangeObservable.js +7 -2
  13. package/cjs/domain/locationChangeObservable.js.map +1 -1
  14. package/esm/boot/buildEnv.js +1 -1
  15. package/esm/domain/assembly.js +1 -0
  16. package/esm/domain/assembly.js.map +1 -1
  17. package/esm/domain/contexts/internalContext.js +1 -0
  18. package/esm/domain/contexts/internalContext.js.map +1 -1
  19. package/esm/domain/contexts/urlContexts.js +4 -2
  20. package/esm/domain/contexts/urlContexts.js.map +1 -1
  21. package/esm/domain/deflate/deflateEncoder.js +36 -41
  22. package/esm/domain/deflate/deflateEncoder.js.map +1 -1
  23. package/esm/domain/deflate/deflateWorker.js +1 -1
  24. package/esm/domain/locationChangeObservable.js +7 -2
  25. package/esm/domain/locationChangeObservable.js.map +1 -1
  26. package/package.json +4 -4
  27. package/src/domain/assembly.js +1 -0
  28. package/src/domain/contexts/internalContext.js +1 -0
  29. package/src/domain/contexts/urlContexts.js +4 -2
  30. package/src/domain/deflate/deflateEncoder.js +42 -40
  31. package/src/domain/locationChangeObservable.js +9 -2
  32. package/types/index.d.ts +1 -0
@@ -13,6 +13,7 @@ export function createDeflateEncoder(worker, streamId) {
13
13
  var compressedData = []
14
14
  var compressedDataTrailer
15
15
 
16
+ var isEmpty = true
16
17
  var nextWriteActionId = 0
17
18
  var pendingWriteActions = []
18
19
 
@@ -24,40 +25,41 @@ export function createDeflateEncoder(worker, streamId) {
24
25
  ) {
25
26
  return
26
27
  }
27
-
28
- rawBytesCount += workerResponse.additionalBytesCount
29
- compressedData.push(workerResponse.result)
30
- compressedDataTrailer = workerResponse.trailer
31
- var nextPendingAction = pendingWriteActions.shift()
32
- if (nextPendingAction && nextPendingAction.id === workerResponse.id) {
33
- if (nextPendingAction.writeCallback) {
34
- nextPendingAction.writeCallback(workerResponse.result.byteLength)
35
- } else if (nextPendingAction.finishCallback) {
36
- nextPendingAction.finishCallback()
28
+ var nextPendingAction = pendingWriteActions[0]
29
+ if (nextPendingAction) {
30
+ if (nextPendingAction.id === workerResponse.id) {
31
+ pendingWriteActions.shift()
32
+
33
+ rawBytesCount += workerResponse.additionalBytesCount
34
+ compressedData.push(workerResponse.result)
35
+ compressedDataTrailer = workerResponse.trailer
36
+
37
+ if (nextPendingAction.writeCallback) {
38
+ nextPendingAction.writeCallback(workerResponse.result.byteLength)
39
+ } else if (nextPendingAction.finishCallback) {
40
+ nextPendingAction.finishCallback()
41
+ }
42
+ } else if (nextPendingAction.id < workerResponse.id) {
43
+ removeMessageListener()
44
+ addTelemetryDebug('Worker responses received out of order.')
37
45
  }
38
- } else {
39
- removeMessageListener()
40
- addTelemetryDebug('Worker responses received out of order.')
41
46
  }
47
+ // rawBytesCount += workerResponse.additionalBytesCount
48
+ // compressedData.push(workerResponse.result)
49
+ // compressedDataTrailer = workerResponse.trailer
50
+ // var nextPendingAction = pendingWriteActions.shift()
51
+ // if (nextPendingAction && nextPendingAction.id === workerResponse.id) {
52
+ // if (nextPendingAction.writeCallback) {
53
+ // nextPendingAction.writeCallback(workerResponse.result.byteLength)
54
+ // } else if (nextPendingAction.finishCallback) {
55
+ // nextPendingAction.finishCallback()
56
+ // }
57
+ // } else {
58
+ // removeMessageListener()
59
+ // addTelemetryDebug('Worker responses received out of order.')
60
+ // }
42
61
  })
43
- function uint8ToBase64(uint8, start = 0, end = uint8.length) {
44
- // 截取需要的部分
45
- const sliced = uint8.slice(start, end)
46
62
 
47
- // 转成字符串
48
- const binary = Array.from(sliced, (byte) => String.fromCharCode(byte)).join(
49
- ''
50
- )
51
-
52
- // 编码成 base64
53
- return btoa(binary)
54
- }
55
- function uint8ToHex(uint8, start = 0, end = uint8.length) {
56
- const sliced = uint8.slice(start, end)
57
- return Array.from(sliced)
58
- .map((byte) => byte.toString(16).padStart(2, '0'))
59
- .join('')
60
- }
61
63
  var removeMessageListener = wokerListener.stop
62
64
 
63
65
  function consumeResult() {
@@ -78,18 +80,18 @@ export function createDeflateEncoder(worker, streamId) {
78
80
  }
79
81
 
80
82
  function sendResetIfNeeded() {
81
- if (nextWriteActionId > 0) {
83
+ if (!isEmpty) {
82
84
  worker.postMessage({
83
85
  action: 'reset',
84
86
  streamId: streamId
85
87
  })
86
- nextWriteActionId = 0
88
+ isEmpty = true
87
89
  }
88
90
  }
89
91
  return {
90
92
  isAsync: true,
91
93
  isEmpty: function () {
92
- return nextWriteActionId === 0
94
+ return isEmpty
93
95
  },
94
96
 
95
97
  write: function (data, callback) {
@@ -104,6 +106,7 @@ export function createDeflateEncoder(worker, streamId) {
104
106
  writeCallback: callback,
105
107
  data: data
106
108
  })
109
+ isEmpty = false
107
110
  nextWriteActionId += 1
108
111
  },
109
112
 
@@ -129,13 +132,12 @@ export function createDeflateEncoder(worker, streamId) {
129
132
  finishSync: function () {
130
133
  sendResetIfNeeded()
131
134
 
132
- var pendingData = pendingWriteActions.map(function (pendingWriteAction) {
133
- // Make sure we do not call any write or finish callback
134
- delete pendingWriteAction.writeCallback
135
- delete pendingWriteAction.finishCallback
136
- return pendingWriteAction.data
137
- })
138
-
135
+ var pendingData = pendingWriteActions
136
+ .map(function (pendingWriteAction) {
137
+ return pendingWriteAction.data
138
+ })
139
+ .join('')
140
+ pendingWriteActions.length = 0
139
141
  return assign(consumeResult(), {
140
142
  pendingData: pendingData
141
143
  })
@@ -32,7 +32,7 @@ export function createLocationChangeObservable(location) {
32
32
  function trackHistory(onHistoryChange) {
33
33
  // eslint-disable-next-line @typescript-eslint/unbound-method
34
34
  var pushState = instrumentMethod(
35
- History.prototype,
35
+ getHistoryInstrumentationTarget('pushState'),
36
36
  'pushState',
37
37
  function (params) {
38
38
  var onPostCall = params.onPostCall
@@ -40,7 +40,7 @@ function trackHistory(onHistoryChange) {
40
40
  }
41
41
  )
42
42
  var replaceState = instrumentMethod(
43
- History.prototype,
43
+ getHistoryInstrumentationTarget('replaceState'),
44
44
  'replaceState',
45
45
  function (params) {
46
46
  var onPostCall = params.onPostCall
@@ -61,3 +61,10 @@ function trackHistory(onHistoryChange) {
61
61
  function trackHash(onHashChange) {
62
62
  return addEventListener(window, DOM_EVENT.HASH_CHANGE, onHashChange)
63
63
  }
64
+ function getHistoryInstrumentationTarget(methodName) {
65
+ // Ideally we should always instument the method on the prototype, however some frameworks (e.g [Next.js](https://github.com/vercel/next.js/blob/d3f5532065f3e3bb84fb54bd2dfd1a16d0f03a21/packages/next/src/client/components/app-router.tsx#L429))
66
+ // are wrapping the instance method. In that case we should also wrap the instance method.
67
+ return Object.prototype.hasOwnProperty.call(history, methodName)
68
+ ? history
69
+ : History.prototype
70
+ }
package/types/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export interface InternalContext {
20
20
  path: string
21
21
  urlQuery: string
22
22
  pathGroup: string
23
+ pathname: string
23
24
  }
24
25
  userAction?: {
25
26
  id: string