@datadome/service-worker-plugin
v1.0.1
Published
Plugin for service workers to intercept block responses from DataDome Bot Protect
Downloads
22
Maintainers
Keywords
Readme
DataDome Service Worker Plugin
Overview
This package overrides the global fetch function to hook requests and display challenges for blocked requests.
Installation
Prerequisites
- Have the JS Tag set up on your app
Step 1: Install the Package
Install the package using the command:
npm i @datadome/service-worker-pluginStep 2: Import the Plugin in Your Service Worker
Import the package into your service worker script.
For ES Modules
import '@datadome/service-worker-plugin';For CommonJS
require('@datadome/service-worker-plugin');Step 3: Configure the JS Tag
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>How it works
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.
