41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
(() => {
|
|
if (window.__debugRedirectHooked) {
|
|
return;
|
|
}
|
|
window.__debugRedirectHooked = true;
|
|
|
|
const logRedirect = (label, value) => {
|
|
try {
|
|
console.trace('[redirect-debug]', label, value);
|
|
} catch (err) {
|
|
console.log('[redirect-debug]', label, value, err);
|
|
}
|
|
};
|
|
|
|
const locationProto = Object.getPrototypeOf(window.location);
|
|
const hrefDescriptor = Object.getOwnPropertyDescriptor(locationProto, 'href');
|
|
|
|
if (hrefDescriptor && hrefDescriptor.configurable) {
|
|
Object.defineProperty(locationProto, 'href', {
|
|
configurable: true,
|
|
enumerable: false,
|
|
get() {
|
|
return hrefDescriptor.get.call(this);
|
|
},
|
|
set(value) {
|
|
logRedirect('href =', value);
|
|
return hrefDescriptor.set.call(this, value);
|
|
},
|
|
});
|
|
}
|
|
|
|
['assign', 'replace'].forEach(method => {
|
|
if (typeof window.location[method] !== 'function') return;
|
|
const original = window.location[method].bind(window.location);
|
|
window.location[method] = function (value) {
|
|
logRedirect(`${method}()`, value);
|
|
return original(value);
|
|
};
|
|
});
|
|
})();
|