Skip to content

Instantly share code, notes, and snippets.

@pl12133
Created August 20, 2018 15:30
Show Gist options
  • Save pl12133/8d57d17544c3061a0283da675bf05c3f to your computer and use it in GitHub Desktop.
Save pl12133/8d57d17544c3061a0283da675bf05c3f to your computer and use it in GitHub Desktop.
function breakOnUrlMatch(str, callback) {
let nextOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function monkeypatchedOpen(...args) {
let url = args[1];
if (url && url.indexOf(str) >= 0) { if (callback()) { return; } }
// console.log('XHR for ', url);
return nextOpen(...args);
}
let nextFetch = window.fetch;
window.fetch = function monkeypatchedFetch(...args) {
let url = args[0];
if (url && url.indexOf(str) >= 0) { if (callback()) { return; } }
// console.log('Fetch for ', url);
return nextFetch(...args);
}
}
function eliminateCallsToUrlMatch(str) {
breakOnUrlMatch(str, () => true);
}
eliminateCallsToUrlMatch('/sockjs');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment