if( window.location.href === "http://localhost:12203/start") { var ws = new WebSocket("ws://localhost:12203/task"); ws.onopen = function(evt) { console.log("Connection open ...", evt); ws.send("Hello WebSockets!"); }; ws.onmessage = function(evt) { console.log("Received Message: ", JSON.parse(evt.data)); chrome.runtime.sendMessage(JSON.parse(evt.data)) }; ws.onclose = function(evt) { console.log("Connection closed."); }; ws.onerror = function(evt) { console.log(evt); } }