It's definitely possible with Firefox but the same code is not working on Thunderbird.
Here is an example of what I am trying to do:
In my background.js:
console.log("a");
let ws = new WebSocket("wss://echo.websocket.org");
console.log("b");
But I only get this result in the debugging console:
Webconsole context has changed
a background.js:1:9
Webconsole context has changed
: background.js:3
<anonyme> moz-extension://e908747f-c410-4427-8868-1336f813f1cd/background.js:3
I am testing on Thunderbird v68.6.0.
When I posted this issue, it was not possible to use WebSocket in Thunderbird.
The bug is, at the moment I am typing this message, being resolved.
You can follow it here : https://bugzilla.mozilla.org/show_bug.cgi?id=1627649
Edit: The bug has been resolved since and WebSockets are available since Thunderbirg 77.0beta3