title: Sending a string from a Javascript client to a Python server(without the use of a Web Framework)?
body: <p>I want to send a url from a chrome extension to a python server. I am currently working with the websockets and asyncio modules on python and the WebSocket for Javascript but whenever my python server receives anything it just says 'undefined.' Anyways, I do not want to use a Web Framework, a lot of the answers to this kind of question I have seen use Web Frameworks which I would like to avoid as much as possible. Here is my current Python code:</p>
  
  <pre><code>import asyncio
  import websockets
  
  async def hello(websocket, path):
      name = await websocket.recv()
      print(f"&lt; {name}")
  start_server = websockets.serve(hello, 'localhost', 12345)
  
  asyncio.get_event_loop().run_until_complete(start_server)
  asyncio.get_event_loop().run_forever()
  </code></pre>
  
  <p>And here is my Javascript code:</p>
  
  <pre><code>var websocket;
  var url;
  var data;
  websocket = new WebSocket("ws://127.0.0.1:12345");
  websocket.addEventListener("DOMContentLoaded", sendUrl());
  
  function encode_utf8(s) {
    return unescape(encodeURIComponent(s));
  }
  
  function sendUrl() {
    chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
      url = tabs[0].url;
      data = encode_utf8(url)
      console.log(url);
    });
  
    websocket.onopen = () =&gt; websocket.send(data);
  }
  </code></pre>