Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug chrome extension service worker for manifest v3?

I am experimenting with chrome extension manifest v3 (on chrome canary) and I can't find any way to debug the service worker script defined in the manifest.json. For manifest v2 there was a link on the chrome://extensions/ page that would open a background page console. Is there any way to view logs in the manifest v3 service worker script?

I am testing with this minimal working example of a manifest v3 service worker extension: https://gist.github.com/dotproto/3a328d6b187621b445499ba503599dc0.

There is nothing mentioned on this debugging page: https://developer.chrome.com/apps/tut_debugging

There is also nothing mentioned on either of the migration guides: https://developer.chrome.com/extensions/migrating_to_manifest_v3 https://developer.chrome.com/extensions/migrating_to_service_workers

like image 959
samuelstarbuck Avatar asked Jul 21 '20 22:07

samuelstarbuck


People also ask

How do you debug a service worker?

Q: How do I debug? A: From a page on the same origin, go to Developer Tools > Application > Service Workers. You can also use chrome://inspect/#service-workers to find all running service workers.

How do I debug Chrome extensions?

# Background scriptNavigate to the chrome extensions management page at chrome://extensions and ensure developer mode is on. Click the Load Unpacked button and select the broken extension directory. After the extension is loaded, it should have three buttons: Details, Remove and Errors in red letters.

What is manifest V3?

Manifest V3 is an application programming interface (API) that Google will use in its popular browser, Chrome. It currently employs an API called Manifest V2. These Manifest APIs are the systems that govern how Chrome extensions interact with your browser.

What is a manifest file Chrome extension?

The manifest file uses JSON format to describe the important information about the extension. It contains fields that are required and recommended while others are optional depending on the extension you are building. name refers to the name of the extension and should be up to 45 characters.


1 Answers

I guess you are looking for the internal ServiceWorker (backend page) of your extension and their connections.

enter image description here

There are two URLs you should be aware of:

  1. chrome://inspect/#service-workers
  2. chrome://serviceworker-internals/?devtools
  3. You might also want to "debug the debugger" e.g. for breakpoints inside your extension page.

1. Registered ServiceWorker list (normal + internal)

chrome://inspect/#service-workers

enter image description here


2. ServiceWorker activity (active connections/clients, console logs, … )

chrome://serviceworker-internals/?devtools

enter image description here


3. Inspect DevTools extension

  • Option A: From contextmenu

    1. Open your extension panel

    2. Open contextmenu and select inspect

    3. 2nd DevTools instance opens

      enter image description here

  • Option B: From extensions page

    1. Open chrome://extensions

    2. Find your extension click "Details"

      enter image description here

like image 121
Exodus 4D Avatar answered Oct 01 '22 01:10

Exodus 4D