const TARGET_SITE = "google.com";
const REDIRECT_TO = "https://website-b.com";

self.addEventListener('fetch', (event) => {
    // Check if the user is trying to visit website-a.com
    if (event.request.url.includes(TARGET_SITE)) {
        
        // Intercept the request and force a redirect
        event.respondWith(
            new Response('', {
                status: 302,
                headers: {
                    'Location': REDIRECT_TO
                }
            })
        );
    }
});

// Force the Service Worker to activate immediately
self.addEventListener('activate', (event) => {
    event.waitUntil(clients.claim());
});