Search code examples
node.jspython-3.xgoogle-chrome-extensiongoogle-api-nodejs-client

make chrome extension using nodejs


Question Background

We are building Chrome Extension. and we need to get the python code in the process.

What i know

  1. I know that python code can be imported using Node JS.
  2. Node JS is used to create servers
  3. Chrome extension is not building server, but making programs(maybe client?)

is it right?

Question

To achieve our goal

  1. Do We need to create server with node js and communicate with chrome extension(using socket.io)?
  2. Is there another way to apply node js in chrome extension?
  3. Is there another way to get the python code into the extension?

Solution

  • Your Chromium web extension code necessarily must be pure client-side Javascript structured to run in the browser's extension environment. There's no support for nodejs or python in that environment; it's very constrained. Because cybercreeps.

    You can use XmlHttpRequest or fetch operations in your extension code to access web services. Your extension manifest will need to grant permission to access your server.

    You can meet your requirement by building and hosting a server for your extension to use. You can use nodejs and a framework like express and/or socket.io, or you can use python, python-socketio, and a framework like Flask or Django. If you build your server with python, it probably will perform better than a nodejs serves that spawns child processes to run python. It will definitely be easier to install, debug and maintain.