asdsad
This commit is contained in:
40
public/assets/js/debug-location.js
Normal file
40
public/assets/js/debug-location.js
Normal file
@@ -0,0 +1,40 @@
|
||||
(() => {
|
||||
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);
|
||||
};
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user