在 Firefox/Chrome 扩展程序中使用 Java/Python 库

发布于 2024-12-03 23:56:56 字数 716 浏览 1 评论 0原文

我有一个研究浏览器上用户行为的想法,为此我打算制作一个 Chrome/Firefox 扩展来动态研究行为。我有一些 Java 和 Python 中的预定义库来分析结果,这不可能用纯 JavaScript 进行编程。

现在我的问题是:是否可以使用第三方库,尤其是 Python 或 Java 的库,例如普通函数调用?

我对 Java XPCOM 或 PyXPCOM for Firefox 之类的东西有一个模糊的想法。然而,对于初学者来说,这一切看起来都是那么可怕。我开始为 Firefox 制作附加组件,但在庞大的 API 中迷失了方向。

我发现对 Chrome 扩展进行编程比 Firefox 更容易,但我在 Chrome 中找不到类似 XPCOM 的东西。

我如何决定选择哪一个?

  • Chrome - 看起来很简单,但我不确定它的功能。
  • Firefox - 看起来很强大,但是真的可以使用任何 Java/Python 库吗?

此外,我发现了这个可能有用的链接:如何使用第三方库包含在 Firefox 插件/扩展中?

但似乎主要讨论 C++ 和 XPCOM。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

狼性发作 2024-12-10 23:56:56

我对 Java XPCOM 或 PyXPCOM for Firefox 之类的东西有一个模糊的想法。但对于初学者来说,这一切看起来都很可怕。

我不是初学者,JavaXPCOM/PyXPCOM非常令人恐惧(而且几乎没有维护)。随着 Firefox 的发展,将 Java/Python 库包装在应用程序中并将其作为外部进程运行应该更容易: https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIProcess。请注意,您无法取回数据(退出代码除外),因此应用程序应将其写入一个文件,然后您可以在您的 Firefox 扩展中读取。不是很优雅,但它的优点是可行。

至于 Chrome,它的扩展在沙箱中运行,并且不可能使用 Java 或 Python。唯一的选择是向您的扩展程序添加 NPAPI 插件。它是二进制代码,意味着它可以做任何事情。

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.

反话 2024-12-10 23:56:56

编写 Chrome 扩展程序时,除非您选择使用 NPAPI 插件,它可以让你做几乎任何事情,但不推荐。

您可以采取的另一种方法是在服务器上实现 Java 或 Python 代码,并从 chrome 扩展的 JavaScript 发出请求。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文