Skip to content

Instantly share code, notes, and snippets.

View ErrorxCode's full-sized avatar
👋
Open for freelancing

Rahil ErrorxCode

👋
Open for freelancing
View GitHub Profile
@ErrorxCode
ErrorxCode / Interceptor.js
Last active July 2, 2025 19:17
Proxying and modifying response of network API calls made using fetch API or XMLHttpRequest API using external javascript
function createMatcher(pattern) {
// escape regex chars, then replace * with .*
const esc = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&');
const regex = new RegExp('^' + esc.replace(/\*/g, '.*') + '$');
return url => regex.test(url);
}
// ------------------------------
// Core Interceptor Object
// ------------------------------