Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining Python and Javascript in a chrome plugin

I'm writing a chrome extension that injects a content script into every page the user goes to. What i want to do is to get the output of a python function for some use in the content script (can't write it in javascript, since it requires raw sockets to connect to my remote SSL server).

I've read that one might use CGI and Ajax or the like, to get output from the python code into the javascript code, but i ran into 3 problems:

  1. I cannot allow hosting the python code on a local server, since it is security sensitive data that only the local computer should be able to know.

  2. Chrome demands that HTTP and HTTPS can not mix- if the user goes to an HTTPS website, i can't host the python code on a HTTP server.

  3. I don't think Chrome even supports CGI on extensions-when i try to access a local file, all it does is print out the text (the python code itself) instead of what i defined to be its output (I tried to do so using Flask). As I said in 1, I shouldn't even try this anyway, but this is just a side note.

So my question is, how do i get the output of my python functions inside a Content Script, built with javascript?

like image 370
asdfguy Avatar asked Feb 11 '16 17:02

asdfguy


1 Answers

Native Messaging may be your answer here.

You can designate a Native Host application that an extension or app will be able to invoke (probably through a background page in case of an extension), and that can be a Python script.

In fact, the sample app for it uses a Python script.

like image 157
Xan Avatar answered Sep 26 '22 02:09

Xan