小书签如何访问 Firefox 扩展(反之亦然)

发布于 2024-08-02 09:49:53 字数 646 浏览 7 评论 0原文

我编写了一个 Firefox 扩展,可以在输入特定 URL 时捕获并执行一些操作。我的主应用程序使用此 URL 启动 Firefox。该 URL 包含敏感信息,因此我不希望将其存储在历史记录中。

我担心未安装扩展的情况。如果它没有安装并且 Firefox 使用敏感 URL 启动,它将被存储在历史记录中,我对此无能为力。所以我的想法是使用书签。

我将使用“javascript:window.location.href='pleaseinstallthisplugin.html';sensitiveinfo='blahblah'”启动 Firefox。

如果未安装扩展程序,他们将被重定向到一个页面,告诉他们安装它,并且敏感信息不会存储在历史记录中。如果安装了扩展IS,它将获取sensitiveinfo 变量中的信息并执行其操作。

我的问题是,小书签是否可以调用扩展程序中的方法来传递敏感信息(如果可以,如何传递),或者扩展程序可以在小书签中调用 javascript 时捕获吗?

小书签和 Firefox 扩展如何进行通信?

ps 解决这种情况的另一种方法是让我的主应用程序启动 Firefox 并使用套接字与扩展进行通信,但我不愿意这样做,因为多年来我遇到了太多问题,用户被疯狂的防火墙阻止套接字通信。如果可能的话,我想在没有套接字的情况下完成所有事情。

I have written a Firefox extension that catches when a particular URL is entered and does some stuff. My main app launches Firefox with this URL. The URL contains sensitive information so I don't want it being stored in the history.

I'm concerned about the case where the extension is not installed. If its not installed and Firefox gets launched with the sensitive URL, it will get stored in history and there's nothing I can do about it. So my idea is to use a bookmarklet.

I will launch Firefox with "javascript:window.location.href='pleaseinstallthisplugin.html'; sensitiveinfo='blahblah'".

If the extension is not installed they will get redirected to a page that tells them to install it and the sensitive info won't get stored in the history. If the extension IS installed it will grab the information in the sensitiveinfo variable and do its thing.

My question is, can the bookmarklet call a method in the extension to pass the sensitive info (and if so, how) or can the extension catch when javascript is being called in the bookmarklet?

How can a bookmarklet and Firefox extension communicate?

p.s. The alternative means of getting around this situation would be for my main app to launch Firefox and communicate with the extension using sockets but I am loath to do that because I've run into too many issues over the years with users with crazy firewalls blocking socket communication. I'd like to do everything without sockets if possible.

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

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

发布评论

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

评论(3

浮生面具三千个 2024-08-09 09:49:53

据我所知,小书签永远无法访问 chrome 文件(扩展名)。

As far as I know, bookmarklets can never access chrome files (extensions).

傾城如夢未必闌珊 2024-08-09 09:49:53

小书签在当前文档的范围内执行,当前文档几乎总是内容文档。但是,如果您通过命令行传递它,它似乎可以工作:

/Applications/Namoroka.app/Contents/MacOS/firefox-bin javascript:alert\(Components\)

访问Components 将抛出异常,但警报会显示正确的对象。

Bookmarklets are executed in the scope of the current document, which is almost always a content document. However, if you are passing it in via the command line, it seems to work:

/Applications/Namoroka.app/Contents/MacOS/firefox-bin javascript:alert\(Components\)

Accessing Components would throw if it was not allowed, but the alert displays the proper object.

心如荒岛 2024-08-09 09:49:53

您可以使用 unsafeWindow 来注入全局变量。您可以添加一个纯粹的属性,以便您的小书签只需要检测全局是否已定义,但您应该知道,据我所知,没有办法禁止非小书签上下文中的站点也嗅探对于同一个全局(因为对于某些人来说,网站可以检测他们是否正在使用该扩展可能是一个隐私问题)。我已经在我自己的附加组件中确认,它以类似于下面的方式注入全局,它确实可以在书签和常规站点上下文中工作。

如果您注册 nsIObserver,例如,其中 content-document-global-created 是主题,然后解开主题,您可以注入全局(请参阅this 如果你需要注入更复杂的东西,比如带有方法的对象)。

这是一些(未经测试的)代码,应该可以解决这个问题:

var observerService = Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService);
observerService.addObserver({observe: function (subject, topic, data) {

    var unsafeWindow = XPCNativeWrapper.unwrap(subject);
    unsafeWindow.myGlobal = true;

}}, 'content-document-global-created', false);

请参阅 这个这个如果你想在 SDK 插件中使用一种明显更简单的方法(不确定 SDK 是否postMessage 通信可以作为替代方案,但显然同样担心这会暴露给非小书签上下文(即,常规网站)也是如此)。

You could use unsafeWindow to inject a global. You can add a mere property so that your bookmarklet only needs to detect whether the global is defined or not, but you should know that, as far as I know, there is no way to prohibit sites in a non-bookmarklet context from also sniffing for this same global (since it may be a privacy concern to some that sites can detect whether they are using the extension). I have confirmed in my own add-on which injects a global in a manner similar to that below that it does work in a bookmarklet as well as regular site context.

If you register an nsIObserver, e.g., where content-document-global-created is the topic, and then unwrap the subject, you can inject your global (see this if you need to inject something more sophisticated like an object with methods).

Here is some (untested) code which should do the trick:

var observerService = Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService);
observerService.addObserver({observe: function (subject, topic, data) {

    var unsafeWindow = XPCNativeWrapper.unwrap(subject);
    unsafeWindow.myGlobal = true;

}}, 'content-document-global-created', false);

See this and this if you want an apparently easier way in an SDK add-on (not sure whether SDK postMessage communication would work as an alternative but with the apparently same concern that this would be exposed to non-bookmarklet contexts (i.e., regular websites) as well).

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