I'm using Firefox 48 which is supposed to be stable for WebExtensions. I've connected my test app with Socket.IO. As soon as I close the pop up, the socket.IO connection breaks. Here is the code:
manifest.json
{
"manifest_version": 2,
"name": "myapp",
"version": "1.0",
"browser_action": {
"default_icon": {
"96": "button/icon.png"
},
"default_title": "myapp",
"default_popup": "popup/main.html"
}
"background": {
"scripts": ["myclient.js"]
}
}
main.html
<body>
<script src="/scripts/socket.io.js"></script>
<script src="/scripts/jquery-2.2.4.min.js"></script>
<script src="/myclient.js"></script>
</body>
myclient.js
var address = "localhost";
var client = io("http://" + address + ":17001/");
client.on("message", function () {
$("#test").text("message");
});
My nodeJS server code
console.log("Server started");
var io = require("socket.io")(17001);
io.on("connection", function (socket) {
var address = socket.request.connection.remoteAddress;
console.log("Someone joined. Socket ID:", socket.id, address);
io.emit("message");
socket.on("disconnect", function () {
console.log("Someone disconnected!");
});
});
How can I stop the connection from getting disconnected? TIA
EDIT: Also tried the same extension with chrome because I read here that firefox doesn't support background
, yet the problem of connection breaking persists.
EDIT 2: Updated my code as per Andrew said, still doesn't work:
"background": {
"scripts": ["myclient.js", "/scripts/socket.io.js", "/scripts/jquery-2.2.4.min.js"],
"page": "bgp.html"
}
I also tried the above code by commenting the scripts
line, still doesn't work.
bgp.html
<!DOCTYPE html>
<html lang="en">
<body>
<script src="/scripts/socket.io.js"></script>
<script>
var address = "localhost";
var client = io("http://" + address + ":17001/");
</script>
</body>
</html>
If I remove the creation of connection from myclient.js
, the connection doesn't happen at all! Which means the bgp.html isn't working.