|
| 1 | +diff --git a/node_modules/@sentry/core/build/cjs/utils/browser.js b/node_modules/@sentry/core/build/cjs/utils/browser.js |
| 2 | +index 3169c25..19acc49 100644 |
| 3 | +--- a/node_modules/@sentry/core/build/cjs/utils/browser.js |
| 4 | ++++ b/node_modules/@sentry/core/build/cjs/utils/browser.js |
| 5 | +@@ -9,8 +9,8 @@ const DEFAULT_MAX_STRING_LENGTH = 80; |
| 6 | + |
| 7 | + /** |
| 8 | + * Given a child DOM element, returns a query-selector statement describing that |
| 9 | +- * and its ancestors |
| 10 | +- * e.g. [HTMLElement] => body > div > input#foo.btn[name=baz] |
| 11 | ++ * and its ancestors, prefixed with data-sentry-label if found on ancestor |
| 12 | ++ * e.g. [HTMLElement] => [data-sentry-label="MyLabel"] div.css-146c3p1.r-1udh08x.r-1udbk01.r-1iln25a > svg |
| 13 | + * @returns generated DOM path |
| 14 | + */ |
| 15 | + function htmlTreeAsString( |
| 16 | +@@ -53,7 +53,30 @@ function htmlTreeAsString( |
| 17 | + currentElem = currentElem.parentNode; |
| 18 | + } |
| 19 | + |
| 20 | +- return out.reverse().join(separator); |
| 21 | ++ const cssSelector = out.reverse().join(separator); |
| 22 | ++ |
| 23 | ++ // If cssSelector already contains data-sentry-label, return as is |
| 24 | ++ if (cssSelector.includes('[data-sentry-label="')) { |
| 25 | ++ return cssSelector; |
| 26 | ++ } |
| 27 | ++ |
| 28 | ++ // Search for data-sentry-label up to 15 levels (beyond the 5 levels of cssSelector) |
| 29 | ++ let labelElem = elem; |
| 30 | ++ let dataLabel = null; |
| 31 | ++ for (let i = 0; i < 15 && labelElem; i++) { |
| 32 | ++ // @ts-expect-error WINDOW has HTMLElement |
| 33 | ++ if (WINDOW.HTMLElement && labelElem instanceof HTMLElement && labelElem.dataset && labelElem.dataset['sentryLabel']) { |
| 34 | ++ dataLabel = labelElem.dataset['sentryLabel']; |
| 35 | ++ break; |
| 36 | ++ } |
| 37 | ++ labelElem = labelElem.parentNode; |
| 38 | ++ } |
| 39 | ++ |
| 40 | ++ if (dataLabel) { |
| 41 | ++ return `[data-sentry-label="${dataLabel}"] ${cssSelector}`; |
| 42 | ++ } |
| 43 | ++ |
| 44 | ++ return cssSelector; |
| 45 | + } catch { |
| 46 | + return '<unknown>'; |
| 47 | + } |
| 48 | +@@ -77,8 +100,12 @@ function _htmlElementAsString(el, keyAttrs) { |
| 49 | + |
| 50 | + // @ts-expect-error WINDOW has HTMLElement |
| 51 | + if (WINDOW.HTMLElement) { |
| 52 | +- // If using the component name annotation plugin, this value may be available on the DOM node |
| 53 | + if (elem instanceof HTMLElement && elem.dataset) { |
| 54 | ++ // Check for data-sentry-label first - return in attribute format [data-sentry-label="value"] |
| 55 | ++ if (elem.dataset['sentryLabel']) { |
| 56 | ++ return `[data-sentry-label="${elem.dataset['sentryLabel']}"]`; |
| 57 | ++ } |
| 58 | ++ // If using the component name annotation plugin, this value may be available on the DOM node |
| 59 | + if (elem.dataset['sentryComponent']) { |
| 60 | + return elem.dataset['sentryComponent']; |
| 61 | + } |
| 62 | +diff --git a/node_modules/@sentry/core/build/esm/utils/browser.js b/node_modules/@sentry/core/build/esm/utils/browser.js |
| 63 | +index 2ad52b0..fd184fb 100644 |
| 64 | +--- a/node_modules/@sentry/core/build/esm/utils/browser.js |
| 65 | ++++ b/node_modules/@sentry/core/build/esm/utils/browser.js |
| 66 | +@@ -7,8 +7,8 @@ const DEFAULT_MAX_STRING_LENGTH = 80; |
| 67 | + |
| 68 | + /** |
| 69 | + * Given a child DOM element, returns a query-selector statement describing that |
| 70 | +- * and its ancestors |
| 71 | +- * e.g. [HTMLElement] => body > div > input#foo.btn[name=baz] |
| 72 | ++ * and its ancestors, prefixed with data-sentry-label if found on ancestor |
| 73 | ++ * e.g. [HTMLElement] => [data-sentry-label="MyLabel"] div.css-146c3p1.r-1udh08x.r-1udbk01.r-1iln25a > svg |
| 74 | + * @returns generated DOM path |
| 75 | + */ |
| 76 | + function htmlTreeAsString( |
| 77 | +@@ -51,7 +51,30 @@ function htmlTreeAsString( |
| 78 | + currentElem = currentElem.parentNode; |
| 79 | + } |
| 80 | + |
| 81 | +- return out.reverse().join(separator); |
| 82 | ++ const cssSelector = out.reverse().join(separator); |
| 83 | ++ |
| 84 | ++ // If cssSelector already contains data-sentry-label, return as is |
| 85 | ++ if (cssSelector.includes('[data-sentry-label="')) { |
| 86 | ++ return cssSelector; |
| 87 | ++ } |
| 88 | ++ |
| 89 | ++ // Search for data-sentry-label up to 15 levels (beyond the 5 levels of cssSelector) |
| 90 | ++ let labelElem = elem; |
| 91 | ++ let dataLabel = null; |
| 92 | ++ for (let i = 0; i < 15 && labelElem; i++) { |
| 93 | ++ // @ts-expect-error WINDOW has HTMLElement |
| 94 | ++ if (WINDOW.HTMLElement && labelElem instanceof HTMLElement && labelElem.dataset && labelElem.dataset['sentryLabel']) { |
| 95 | ++ dataLabel = labelElem.dataset['sentryLabel']; |
| 96 | ++ break; |
| 97 | ++ } |
| 98 | ++ labelElem = labelElem.parentNode; |
| 99 | ++ } |
| 100 | ++ |
| 101 | ++ if (dataLabel) { |
| 102 | ++ return `[data-sentry-label="${dataLabel}"] ${cssSelector}`; |
| 103 | ++ } |
| 104 | ++ |
| 105 | ++ return cssSelector; |
| 106 | + } catch { |
| 107 | + return '<unknown>'; |
| 108 | + } |
| 109 | +@@ -75,8 +98,12 @@ function _htmlElementAsString(el, keyAttrs) { |
| 110 | + |
| 111 | + // @ts-expect-error WINDOW has HTMLElement |
| 112 | + if (WINDOW.HTMLElement) { |
| 113 | +- // If using the component name annotation plugin, this value may be available on the DOM node |
| 114 | + if (elem instanceof HTMLElement && elem.dataset) { |
| 115 | ++ // Check for data-sentry-label first - return in attribute format [data-sentry-label="value"] |
| 116 | ++ if (elem.dataset['sentryLabel']) { |
| 117 | ++ return `[data-sentry-label="${elem.dataset['sentryLabel']}"]`; |
| 118 | ++ } |
| 119 | ++ // If using the component name annotation plugin, this value may be available on the DOM node |
| 120 | + if (elem.dataset['sentryComponent']) { |
| 121 | + return elem.dataset['sentryComponent']; |
| 122 | + } |
0 commit comments