This package overrides the global fetch
function to hook requests and display challenges for blocked requests.
- Have the JS Tag set up on your app
Install the package using the command:
npm i @datadome/service-worker-plugin
Import the package into your service worker script.
import '@datadome/service-worker-plugin';
require('@datadome/service-worker-plugin');
To enable the JS Tag to listen to the service worker, update its configuration to include the enableServiceWorkerPlugin
option:
<script>
window.ddjskey = 'YOUR_DATADOME_JS_KEY';
window.ddoptions = {
enableServiceWorkerPlugin: true,
};
</script>
The fetch
override is applied when the service worker is activated.
The interception of requests and responses will be enabled as soon as the service worker is installed and ready to handle fetch events.