@sentry/browser
Version:
Official Sentry SDK for browsers
31 lines (30 loc) • 1.45 kB
JavaScript
let _sentry_browser_utils = require("@sentry/browser-utils");
// src/normalizeStringifyValue.ts
const HTML_ELEMENT_CONSTRUCTOR_NAME_REGEX = /^HTML(\w*)Element$/;
/**
* Browser-specific contributions to `normalize()`'s `stringifyValue`. Plug into
* `setNormalizeStringifier` from the browser SDK so DOM values get a useful string
* representation without forcing core to carry the DOM-specific code.
*
* Handles:
* - `window` → `[Window]`
* - `document` → `[Document]`
* - `HTMLElement` subclasses → `[HTMLElement: <css-selector-path>]` (via `htmlTreeAsString`)
*
* Vue ViewModels and React SyntheticEvents are not handled here — the Vue and React
* SDKs wrap this function in their `init` and add their own checks on top.
*/
function normalizeStringifyValue(value) {
if (typeof window !== "undefined" && value === window) return "[Window]";
if (typeof document !== "undefined" && value === document) return "[Document]";
if ((0, _sentry_browser_utils.isElement)(value)) {
const objName = getConstructorName(value);
if (HTML_ELEMENT_CONSTRUCTOR_NAME_REGEX.test(objName)) return `[HTMLElement: ${(0, _sentry_browser_utils.htmlTreeAsString)(value)}]`;
}
}
function getConstructorName(value) {
const prototype = Object.getPrototypeOf(value);
return prototype?.constructor ? prototype.constructor.name : "null prototype";
}
exports.normalizeStringifyValue = normalizeStringifyValue;
//# sourceMappingURL=normalizeStringifyValue.js.map