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

Manifest V3 Websocket

Open WyattSanders opened this issue 3 years ago • 3 comments

I could open a socket.io websocket in Manifest V2 to communicate with an external webserver but V2 no longer works and I'm forced to use V3. V3 appears to be way more locked down is there no way to communicate with an external server from my chrome extension anymore?

I and others have been asking about how to migrate this functionality for the last year: https://groups.google.com/a/chromium.org/g/chromium-extensions/c/23pCzk69Ueo?pli=1

WyattSanders avatar Aug 16 '22 03:08 WyattSanders

Can you post manifest.json and the code you tried here?

It should be possible to communicate with external Web server using MV3.

guest271314 avatar Aug 20 '22 14:08 guest271314

Can you post manifest.json and the code you tried here?

It should be possible to communicate with external Web server using MV3.

I think I figured it out, I made an example on my github there's very little documentation anywhere: ChromeMV3WebsocketExample

WyattSanders avatar Aug 21 '22 02:08 WyattSanders

Can you post manifest.json and the code you tried here? It should be possible to communicate with external Web server using MV3.

I think I figured it out, I made an example on my github there's very little documentation anywhere: ChromeMV3WebsocketExample It's a native Websocket, but it means that every time a new page is opened, it connects, which doesn't seem to be what we want. I expect it to be a Background connection, and then distribute it to the page

zhangLeLer avatar Sep 01 '22 06:09 zhangLeLer

With the new Manifest V3, the ability to open a WebSocket using the chrome.socket API has been removed. This means that you can no longer communicate with an external server using this method.

However, there are alternative ways to achieve similar functionality in Manifest V3. One approach is to use the WebSockets API provided by the browser, which allows you to open a WebSocket connection to an external server directly from your extension's content scripts.

To use the WebSockets API, you would first need to request permission to access the external server's domain in your extension's manifest file. This can be done using the permissions key

M-SAI-SOORYA avatar Mar 27 '23 14:03 M-SAI-SOORYA

I'm going to close this one since I don't think there's anything to do in the samples repo. As mentioned, the web WebSocket API is available in Service Workers and this would be the best approach. Currently, it doesn't extend the service worker lifetime, but we have plans to change that. It's documented here: https://developer.chrome.com/docs/extensions/migrating/known-issues/ :)

oliverdunk avatar May 17 '23 08:05 oliverdunk