A library that delays async XHR and Fetch requests until an event is triggered.
npm install request-interceptor
Import the module into your application's entry point (EG main.js
)
ES6:
import RequestInterceptor from 'request-interceptor'
ES5:
var RequestInterceptor = require('request-interceptor');
Initilise the interceptor to start delaying requests:
RequestInterceptor({});
NOTE: Ensure you initialise the interceptor before any XHR or Fetch requests are triggered by your application code.
The interceptor accepts the following optional arguments:
readyEvent
The event it should listen for. Standard or custom events are supported.
default = DOMContentLoaded
whiteList
An array of strings. Any request url containing at least one of these strings will be passed through.
default = []
allowCurrentHost
A boolean value indicating whether or not requests from the current domain should be passed through.
default = false
RequestInterceptor({
readyEvent: 'readystatechange',
whiteList: ['customhost.com', 'analytics.google.com'],
allowCurrentHost: true
});
RequestInterceptor({
readyEvent: 'customReadyEvent',
});
const event = new CustomEvent("customReadyEvent");
window.dispatchEvent(event);
- Domain/URL Whitelisting
- Allow through requests on current host
- Add support for the Fetch API
- Add support for Custom Events
- Write tests
- Verify browser support