Created
August 20, 2018 15:30
-
-
Save pl12133/8d57d17544c3061a0283da675bf05c3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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