How to establish communication between service-worker and main in Manifest V3

I am trying to build continuous communication between service-worker.js and main.js in order to post what data is received from an API to Google Documents, but I can’t figure out how to do it using Manifest V3. The first problem I’ve encountered is registering the service-worker like this:

if ('serviceWorker' in navigator) {
    window.addEventListener('load', () => {
        navigator.serviceWorker
            .register('/sw.js')
            .then((registration) => {
                console.log('Service worker registered:', registration);
            })
            .catch((error) => {
                console.error('Error registering service worker:', error);
            });
    });
}

but it always catches the error. From what I’ve understood, Manifest V3 registers the SW-s internally so I don’t need to worry about registration.

I’ve tried using Workbox but I can’t simply import it with importScripts and working with workbox-cli is too complex and in the end, I think is unnecessary.