Skip to content

Instantly share code, notes, and snippets.

@166MMX
Created August 13, 2021 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 166MMX/673273a91b8912cba7a1e8445a1df36e to your computer and use it in GitHub Desktop.
Save 166MMX/673273a91b8912cba7a1e8445a1df36e to your computer and use it in GitHub Desktop.
greasemonkey new relic unwrapper
(function (window) {
const m = new Map(Object.entries({
'window': new Map(Object.entries({
'clearTimeout': new Map(Object.entries({
'NREUM.o': 'CT',
})),
'setInterval': null,
'requestAnimationFrame': null,
'webkitRequestAnimationFrame': null,
'Event': new Map(Object.entries({
'NREUM.o': 'EV',
})),
'MutationObserver': new Map(Object.entries({
'NREUM.o': 'MO',
})),
'Promise': new Map(Object.entries({
'NREUM.o': 'PR',
'prototype': new Map(Object.entries({
'then': null,
'catch': null,
})),
})),
'Request': new Map(Object.entries({
'NREUM.o': 'REQ',
})),
'setTimeout': new Map(Object.entries({
'NREUM.o': 'ST',
})),
'XMLHttpRequest': new Map(Object.entries({
'NREUM.o': 'XHR',
'prototype': new Map(Object.entries({
'open': null,
'send': null,
})),
})),
'History': new Map(Object.entries({
'prototype': new Map(Object.entries({
'pushState': null,
'replaceState': null,
})),
})),
'EventTarget': new Map(Object.entries({
'prototype': new Map(Object.entries({
'addEventListener': null,
'removeEventListener': null,
})),
})),
'Node': new Map(Object.entries({
'prototype': new Map(Object.entries({
'appendChild': null,
'insertBefore': null,
'replaceChild': null,
})),
})),
})),
}));
const new_relic_original = (typeof window.NREUM === 'object' && typeof window.NREUM.o === 'object') ? window.NREUM.o : null;
const handle_map = function handle_map(scope, map) {
for (const [k, v] of map.entries()) {
if (k === 'NREUM.o') {
continue;
}
if (v instanceof Map) {
// constructor
if (v.has('NREUM.o') && new_relic_original !== null) {
const key = v.get('NREUM.o');
const original = new_relic_original[key];
// console.log('restore native NREUM.o.%s: "%s" %o %o', key, k, scope[k], original);
Object.defineProperty(scope, k, {writable: false, configurable: false, value: original});
}
const target_scope = scope[k];
handle_map(target_scope, v);
} else {
const fn = scope[k];
if ('nr@original' in fn) {
// function
const original = fn['nr@original'];
// console.log('restore native nr@original: "%s" %o %o', k, scope[k], original);
Object.defineProperty(scope, k, {writable: false, configurable: false, value: original});
} else if (fn.toString().includes('[native code]')) {
// non wrapped
// console.log('freeze native; "%s" %o', k, fn);
Object.defineProperty(scope, k, {writable: false, configurable: false});
}
}
}
};
handle_map(window, m);
}(unsafeWindow));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment