How to listen for run-time errors in the service worker?

126 views
Skip to first unread message

Getfree

unread,
Jul 4, 2024, 6:38:10 PMJul 4
to Chromium Extensions
In the MV2 background page it's possible to do this:

window.addEventListener("error", evt =>{ . . . })

This allows us receive automatic error reports after the extension has already been published in the CWS. Thanks to this we've been able to detect and fix many errors throughout the years.

However, in the MV3 service worker, this doesn't seem to do anything:

self.addEventListener("error", evt =>{ . . . })


Is there any other way of listening for run-time errors in the service worker?

woxxom

unread,
Jul 5, 2024, 3:10:00 AMJul 5
to Chromium Extensions, Getfree
It may be a bug generally, but there's one case when it's caused by the inherently flawed architecture of service workers in Chrome: if the error occurs during the first turn of the event loop during the first registration at install/update, the service worker won't be registered at all and the error won't be shown anywhere. The only way to see such error I found is to start Chrome with --enable-logging=stderr --v=1 2>log.text and then look at the id of the extension in the log file. Such a heartwarming reminder of how I debugged programs 30+ years ago.
Reply all
Reply to author
Forward
0 new messages