I am working on updating an old Manifest V2 browser extension that was developed by my employer to Manifest V3. The browser extension is meant to extend the functionality of one of our products.
The product is written in C#. It has two components that are used to communicate with the browser extension.
- A WebServerForExtension object that receives messages from the browser extension. This object makes use of the SimpleHttpServer class.
- A BrowserSystemWebSocket object that is used to send replies back to the browser extension.
The background scripts of the browser extension connect to the WebServerForExtension object using the fetch() global function and the BrowserSystemWebSocket object using a WebSocket object.
The C# application does not currently support HTTPS, it only supports HTTP.
The problem I am having is that the browser extension cannot connect to the BrowserSystemWebSocket object using a WebSocket object.
The following lines of code demonstrate how I am attempting to connect to the BrowserSystemWebSocket object.
static #InitializeWebSocket() {
try {
const url = `ws://127.0.0.1:42042/browser/system/connect`;
Background.#socket = new WebSocket(url, 'pipes');
Background.#socket.onclose = Background.#WebSocketOnClose;
Background.#socket.onerror = Background.#WebSocketOnError;
Background.#socket.onmessage = Background.#WebSocketOnMessage;
Background.#socket.onopen = Background.#WebSocketOnOpen;
/* Code that is called when the connection succeeds. */
}
catch (error) {
/* Code that is called when the connection fails. */
}
}
The #InitializeWebSocket method is failing with the following error.
Content-Security-Policy: Upgrading insecure request ‘ws://127.0.0.1:42042/browser/system/connect’ to use ‘wss’
Firefox can’t establish a connection to the server at wss://127.0.0.1:42042/browser/system/connect.
Is there a way to tell Firefox not to try to upgrade the request to use ‘wss’?