Service worker registration failed. Chrome extension

Please find below the cause for your specific issue and the cause for not getting the details of failure in the console log.

  • Before Chrome 93, the service worker file must be in the root path
    where manifest.json is.

    This is a limitation of Service Worker specification, relaxed for extensions since Chrome 93.

    If, for whatever reason, you want to allow your extension to be used in older Chrome, the correct manifest.json should look like this:

    "background": {
      "service_worker": "background.js"
    },
    

    Conversely, to use an arbitrary path you need to prevent installation in older Chrome:

    "minimum_chrome_version": "93",
    "background": {
      "service_worker": "js/bg/worker-loader.js",
      "type": "module"
    },
    

    Type module is optional and is supported since Chrome 92. You can import ES modules statically for now. The support for dynamic imports is in development.

    In any Chrome version you can use importScripts('/path/foo.js', '/path/bar.js'); to import scripts from other directories.

  • If the worker script throws an error at installation, the worker won’t be registered and you will not be getting the error information triggered by your service worker in the console, but only get “Service worker registration failed”. This behavior is due to a bug bug in Chrome versions earlier than Chrome 93.

    Solution:

    • use Chrome 93 or newer.

    Limited workaround:

    Typical causes:

    • accessing an undeclared variable
    • syntax error like an unclosed parenthesis
    • accessing a chrome API without declaring it in manifest.json’s permissions field
    • a crash in the worker process

Leave a Comment