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.