chrome-extensions-samples icon indicating copy to clipboard operation
chrome-extensions-samples copied to clipboard

```getBackgroundPage``` is still usable?

Open fxqy opened this issue 2 years ago • 3 comments

chrome.extension.getBackgroundPage() is this api still usable? How to get the page of 'Service_Worker '

fxqy avatar Apr 07 '22 11:04 fxqy

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?

service_worker api in MDN jietu_mingzi_2022-4-9_11-14-12

fxqy avatar Apr 09 '22 03:04 fxqy

You can use "externally_connectable" to communicate with ServiceWorker.

guest271314 avatar Apr 13 '22 13:04 guest271314

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.

Ambushfall avatar Aug 20 '22 15:08 Ambushfall

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.

M-SAI-SOORYA avatar Mar 29 '23 08:03 M-SAI-SOORYA

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.

jpmedley avatar Mar 30 '23 16:03 jpmedley

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.

oliverdunk avatar May 17 '23 08:05 oliverdunk