最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Combining Python and Javascript in a chrome plugin - Stack Overflow

programmeradmin4浏览0评论

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 puter 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?

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 puter 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?

Share Improve this question asked Feb 11, 2016 at 17:46 asdfguyasdfguy 973 silver badges7 bronze badges 1
  • use an interpreter! google./… – Marc Commented Feb 11, 2016 at 19:11
Add a ment  | 

2 Answers 2

Reset to default 3

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.

The only way to get the output of a Python script inside a content script built with Javascript is to call the file with XMLHttpRequest. As you noted, you will have to use an HTTPS connection if the page is served over HTTPS. A workaround for this is to make a call to your background script, which can then fetch the data in whichever protocol it likes, and return it to your content script.

发布评论

评论列表(0)

  1. 暂无评论