Block Service Workers

Blocks Service Worker's registration.

Ekde 2023/10/03. Vidu La ĝisdata versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Block Service Workers
// @name:zh-CN  禁用Service Workers
// @namespace   Violentmonkey Scripts
// @match       *://*/*
// @unwrap
// @version     0.2
// @author      axototl
// @inject-into page
// @sandbox     JavaScript
// @license     AGPL-3.0-or-later
// @description Blocks Service Worker's registration.
// @description:zh-CN 阻止Service Worker,并移除现有的Service Worker,杜绝网上垃圾。
// @run-at      document-start
// ==/UserScript==

(() => {
    'use strict';
    if (!('serviceWorker' in navigator)) return;
    console.log("Removing Service Workers API, please wait...");
    navigator.serviceWorker.register = () => new Promise((res, rej) => rej("This method is not allowed!"));
    console.log("Deregistering Installed Service Workers, please wait...");
    (async () => {
        let arrs = await navigator.serviceWorker.getRegistrations();
        for (const it of arrs) it.unregister();
    })();
    console.log("All done!");
    // GM_registerMenuCommand("注销Service Workers", logout);
})();