chrome-extensions-samples
chrome-extensions-samples copied to clipboard
```getBackgroundPage``` is still usable?
chrome.extension.getBackgroundPage()
is this api still usable? How to get the page of 'Service_Worker '
mv2 will expire next year. I want to upgrade my extension to mv3, but I can't get the backgroundpage. I found the relevant api of ‘serviceWorker’ in mdn. Can I only communicate through message in the future?
You can use "externally_connectable"
to communicate with ServiceWorker
.
Service workers and Content Scripts are supposed to only communicate with messages.
You can although define a service worker as a module and import stuff into it.
Make sure you define, type module in manifest.
The chrome.extension.getBackgroundPage() API is still available in Chrome extensions, but it is not supported in the latest Manifest v3 (mv3) for Chrome extensions. Instead, you can use the chrome.runtime.getBackgroundPage() API, which is supported in mv3.
To communicate with a Service Worker in an extension, you can use the chrome.runtime.sendMessage and chrome.runtime.onMessage APIs. These APIs allow you to send and receive messages between different parts of your extension, including between content scripts, background scripts, and Service Workers.
chrome.runtime.getBackgroundPage()
is not supposed to work either. If it works for you, it's a bug. Can you share your use case? We can help you find another code path.
Closing this one since this is no longer a supported API. Messaging is definitely the way to go if you need communication between the service worker and another context.