@cloudcare/browser-rum 3.0.18 → 3.0.20

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.
@@ -124,7 +124,16 @@ export function makeUrlAbsolute(url, baseUrl) {
124
124
  return url
125
125
  }
126
126
  }
127
+ export function validateStringifiedCssRule(cssStringified) {
128
+ // Safari does not escape selectors with : properly
129
+ if (cssStringified.includes(':')) {
130
+ // Replace e.g. [aa:bb] with [aa\\:bb]
131
+ const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm
132
+ return cssStringified.replace(regex, '$1\\$2')
133
+ }
127
134
 
135
+ return cssStringified
136
+ }
128
137
  export function serializeStyleSheets(cssStyleSheets) {
129
138
  if (cssStyleSheets === undefined || cssStyleSheets.length === 0) {
130
139
  return undefined
@@ -132,7 +141,7 @@ export function serializeStyleSheets(cssStyleSheets) {
132
141
  return cssStyleSheets.map(function (cssStyleSheet) {
133
142
  var rules = cssStyleSheet.cssRules || cssStyleSheet.rules
134
143
  var cssRules = Array.from(rules, function (cssRule) {
135
- return cssRule.cssText
144
+ return cssRule.cssText ? validateStringifiedCssRule(rule.cssText) : ''
136
145
  })
137
146
 
138
147
  var styleSheet = {
@@ -28,7 +28,8 @@ import {
28
28
  switchToAbsoluteUrl,
29
29
  serializeStyleSheets,
30
30
  absoluteToDoc,
31
- getAbsoluteSrcsetString
31
+ getAbsoluteSrcsetString,
32
+ validateStringifiedCssRule
32
33
  } from './serializationUtils'
33
34
 
34
35
  // Those values are the only one that can be used when inheriting privacy levels from parent to
@@ -337,6 +338,29 @@ function getValidTagName(tagName) {
337
338
 
338
339
  return processedTagName
339
340
  }
341
+ /**
342
+ * Browsers sometimes destructively modify the css rules they receive.
343
+ * This function tries to rectify the modifications the browser made to make it more cross platform compatible.
344
+ * @param cssText - output of `CSSStyleRule.cssText`
345
+ * @returns `cssText` with browser inconsistencies fixed.
346
+ */
347
+ function fixBrowserCompatibilityIssuesInCSS(cssText) {
348
+ /**
349
+ * Chrome outputs `-webkit-background-clip` as `background-clip` in `CSSStyleRule.cssText`.
350
+ * But then Chrome ignores `background-clip` as css input.
351
+ * Re-introduce `-webkit-background-clip` to fix this issue.
352
+ */
353
+ if (
354
+ cssText.includes(' background-clip: text;') &&
355
+ !cssText.includes(' -webkit-background-clip: text;')
356
+ ) {
357
+ cssText = cssText.replace(
358
+ ' background-clip: text;',
359
+ ' -webkit-background-clip: text; background-clip: text;'
360
+ )
361
+ }
362
+ return cssText
363
+ }
340
364
 
341
365
  function getCssRulesString(cssStyleSheet) {
342
366
  if (!cssStyleSheet) {
@@ -351,14 +375,22 @@ function getCssRulesString(cssStyleSheet) {
351
375
  if (!rules) {
352
376
  return null
353
377
  }
354
- var styleSheetCssText = Array.from(rules, getCssRuleString).join('')
378
+ var styleSheetCssText = fixBrowserCompatibilityIssuesInCSS(
379
+ Array.from(rules, getCssRuleString).join('')
380
+ )
355
381
  return switchToAbsoluteUrl(styleSheetCssText, cssStyleSheet.href)
356
382
  }
357
383
 
358
384
  function getCssRuleString(rule) {
359
- return isCSSImportRule(rule)
360
- ? getCssRulesString(rule.styleSheet) || ''
361
- : rule.cssText
385
+ var cssStringified = rule.cssText
386
+ if (isCSSImportRule(rule)) {
387
+ try {
388
+ cssStringified = getCssRulesString(rule.styleSheet) || cssStringified
389
+ } catch {
390
+ // ignore
391
+ }
392
+ }
393
+ return validateStringifiedCssRule(cssStringified)
362
394
  }
363
395
 
364
396
  function isCSSImportRule(rule) {
@@ -1,7 +1,9 @@
1
1
  import {
2
2
  performDraw,
3
3
  startSessionManager,
4
- LifeCycleEventType
4
+ LifeCycleEventType,
5
+ noop,
6
+ Observable
5
7
  } from '@cloudcare/browser-core'
6
8
 
7
9
  export var RUM_SESSION_KEY = 'rum'
@@ -64,12 +66,16 @@ export function startRumSessionManager(configuration, lifeCycle) {
64
66
  */
65
67
  export function startRumSessionManagerStub() {
66
68
  var session = {
67
- id: '00000000-aaaa-0000-aaaa-000000000000'
69
+ id: '00000000-aaaa-0000-aaaa-000000000000',
70
+ plan: RumSessionPlan.WITHOUT_SESSION_REPLAY, // plan value should not be taken into account for mobile
71
+ sessionReplayAllowed: false
68
72
  }
69
73
  return {
70
74
  findTrackedSession: function () {
71
75
  return session
72
- }
76
+ },
77
+ expire: noop,
78
+ expireObservable: new Observable()
73
79
  }
74
80
  }
75
81
 
@@ -29,9 +29,9 @@ export function isTracingOption(item) {
29
29
  }
30
30
  export function clearTracingIfNeeded(context) {
31
31
  if (context.status === 0 && !context.isAborted) {
32
- // context.traceId = undefined
33
- // context.spanId = undefined
34
- // context.traceSampled = undefined
32
+ context.traceId = undefined
33
+ context.spanId = undefined
34
+ context.traceSampled = undefined
35
35
  }
36
36
  }
37
37
 
@@ -1,5 +1,5 @@
1
1
  import { TraceIdentifier, getCrypto } from './traceIdentifier'
2
-
2
+ import { assign } from '@cloudcare/browser-core'
3
3
  /**
4
4
  *
5
5
  * @param {*} traceSampled
@@ -37,8 +37,15 @@ W3cTraceParentTracer.prototype = {
37
37
  )
38
38
  },
39
39
  makeTracingHeaders: function () {
40
- return {
40
+ var baseHeaders = {
41
41
  traceparent: this.getTraceParent()
42
42
  }
43
+ if (this.isHexTraceId) {
44
+ return assign(baseHeaders, {
45
+ 'x-gc-trace-id': this.getTraceId(),
46
+ 'x-gc-span-id': this.getSpanId()
47
+ })
48
+ }
49
+ return baseHeaders
43
50
  }
44
51
  }
@@ -0,0 +1,17 @@
1
+ import {
2
+ getEventBridge,
3
+ LifeCycleEventType,
4
+ processedMessageByDataMap
5
+ } from '@cloudcare/browser-core'
6
+
7
+ export function startRumEventBridge(lifeCycle) {
8
+ var bridge = getEventBridge()
9
+
10
+ lifeCycle.subscribe(
11
+ LifeCycleEventType.RUM_EVENT_COLLECTED,
12
+ function (serverRumEvent) {
13
+ var data = processedMessageByDataMap(serverRumEvent).rowData
14
+ bridge.send('rum', data)
15
+ }
16
+ )
17
+ }