Using Java/Python libraries in programming Firefox/Chrome Extensions

坚强是说给别人听的谎言 提交于 2019-12-05 02:51:05

问题


I have an idea of studying user behavior on the browser, for which I intend to make a Chrome/Firefox extension to study the behavior dynamically. I have some predefined libraries in Java and Python to analyze the results, which will be impossible to program in plain JavaScript.

Now for my question: is it possible to use third party libraries, especially those of Python or Java like plain function calls?

I have a vague idea about something like Java XPCOM or PyXPCOM for Firefox. However, for a beginner, it all looks so scary. I started making Add-On for Firefox, but got lost somewhere in the huge API.

I found Programming Chrome extensions easier than Firefox, but I couldn't come across something similar to XPCOM in Chrome.

How can I decide which one to go for?

  • Chrome - seems easy but I am not sure of its power.
  • Firefox - Seems powerful, but is it really possible to use any Java/Python Library?

Additionally, I came across this link that may be useful: How does someone use thirdparty libraries to be included in Firefox addons/extensions?

But seems like it mostly talks about C++ and XPCOM.


回答1:


I have a vague idea about something like Java XPCOM or PyXPCOM for Firefox. But for a beginner, it all looks so scary.

I am not a beginner and JavaXPCOM/PyXPCOM are very scary (in addition to being barely maintained). As Firefox goes, it should be much easier to wrap your Java/Python library in an application and run it as an external process: https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIProcess. Note that you cannot get data back (other than an exit code) so the application should write it to a file that you can then read in your Firefox extension. Not very elegant but it has the advantage of being doable.

As to Chrome, its extensions run in a sandbox and using Java or Python isn't possible. Only option is adding an NPAPI plugin to your extension. It is binary code meaning that it could do anything.




回答2:


When writing Chrome extensions, you're limited to JavaScript unless you choose to use an NPAPI plugin, which lets you do pretty much anything, but is not recommended.

The other approach you could take is to implement your Java or Python code on the server and make requests from the chrome extension's JavaScript.



来源:https://stackoverflow.com/questions/7366195/using-java-python-libraries-in-programming-firefox-chrome-extensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!