hrtools/content/inject.js
eson fa568b53c4 TODO:
1. 需要改为一个Chrome一个任务. 因为有全局的cookie.
如果开相同的网站会导致cookie混乱.
2021-05-08 18:15:29 +08:00

33 lines
606 B
JavaScript

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);
}
}