@mtdt.temp/browser-core
Version:
Datadog browser core utilities.
29 lines • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getZoneJsOriginalValue = getZoneJsOriginalValue;
const getGlobalObject_1 = require("./getGlobalObject");
/**
* Gets the original value for a DOM API that was potentially patched by Zone.js.
*
* Zone.js[1] is a library that patches a bunch of JS and DOM APIs. It usually stores the original
* value of the patched functions/constructors/methods in a hidden property prefixed by
* __zone_symbol__.
*
* In multiple occasions, we observed that Zone.js is the culprit of important issues leading to
* browser resource exhaustion (memory leak, high CPU usage). This method is used as a workaround to
* use the original DOM API instead of the one patched by Zone.js.
*
* [1]: https://github.com/angular/angular/tree/main/packages/zone.js
*/
function getZoneJsOriginalValue(target, name) {
const browserWindow = (0, getGlobalObject_1.getGlobalObject)();
let original;
if (browserWindow.Zone && typeof browserWindow.Zone.__symbol__ === 'function') {
original = target[browserWindow.Zone.__symbol__(name)];
}
if (!original) {
original = target[name];
}
return original;
}
//# sourceMappingURL=getZoneJsOriginalValue.js.map