问题
I am trying to develop a chrome extension in which i have coded all my logic in 'python' . Now on browser action i want to pass parameters and execute that .py file and return results to popup which will open on browser action. To call a .py file from JavaScript i know i will need to code a NPAPI plugin. But am confused between which approach i should take. I have come across few options and am trying to choose the easiest way to do it ..
Pyjamas Python Javascript Compiler : is a Python-to-Javascript compiler which works as a language translator but on FAQ's of there site last question suggest it will not run on Chrome. ( http://pyjs.org/)
FireBreath : FireBreath is a framework that allows easy creation of powerful browser plugins. ( http://www.firebreath.org )
pyplugin - Python NPAPI plugin for XULRunner : It allows you to build cross-platform graphical user interfaces using XUL and Python. ( http://pyplugin.com )
Plz Guide me to easiest way which will allow me to pass parameters and execute that .py file and receive returned results from .py.
Thanx
回答1:
Well, Pyjamas Python Javascript Compiler will not be complete -- not all python features are available in javascript, so it's impossible to convert all python to javascript. This may or may not do what you want, but I don't think it happens "on the fly", I think you have to write things on the desktop and run it through the "compiler" to get javascript out the other side.
FireBreath is the most awesomely amazing thing to ever hit the Internet -- I should know since I wrote it -- and it will absolutely allow you to do what you want, but you'll have to know how to tie into Python with C++ in order to do what you want. That said, you could probably use boost.python, which is included in the subset of boost that comes with FireBreath, but I've never used it so I don't know. You can pretty much do anything you want with an NPAPI plugin but you'll want to be real careful of security concerns.
A quick glance at pyplugin makes it look like pyplugin is basically what you'd be writing in FireBreath, but just a raw npapi plugin. If this will do what you want, it's probably the easiest way to go. It's designed to be used with XUL, which may be a problem since Chrome doesn't support XUL. You might also be able to modify it (since it's GPL) to do what you want. Of course, if you weren't planning to release your source, that could also be a problem.
The quickest way to solve your problem? Well, you'll have to decide; it'll take some more research, but I hope this is enough to at least get you started. Good luck!
来源:https://stackoverflow.com/questions/5062444/npapi-for-python-chrome-extension