0

I've been trying to use socket.io for a chrome extension to implement multi userability but socket.io requires inline HTML scrips which chrome extensions don't take. Is there anyway to potentially get that to work.

EX:

<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io();

  var form = document.getElementById('form');
  var input = document.getElementById('input');

  form.addEventListener('submit', function(e) {
    e.preventDefault();
    if (input.value) {
      socket.emit('chat message', input.value);
      input.value = '';
    }
  });
</script>    

How could I use this without needing inline HTML. Along with not using require as that doesn't work to import in a chrome extension.

  • Download `socket.io.js` from that url, put it in the extension directory and load it just like you load other extension scripts. – wOxxOm Mar 02 '22 at 02:18
  • I did this and now I'm getting this error because I'm using require. Uncaught ReferenceError: require is not defined – studentOfTheCode Mar 04 '22 at 23:32
  • You need to browserify it, [more info](https://stackoverflow.com/questions/43684452/is-it-possible-to-require-npm-modules-in-a-chrome-extension). – wOxxOm Mar 04 '22 at 23:36

0 Answers0