问题描述
我想为符合我的模式的网址添加前缀。当我在Firefox中打开一个新选项卡并输入一个匹配的URL时,页面不应该正常加载,首先应该修改URL,然后加载页面才能开始。
在页面开始加载前,是否可以通过Mozilla Firefox Addon修改URL?
浏览插件提供以下步骤:- 为 .mozilla.org / en / Observer_Notifications#HTTP_requestsrel =noreferrer>http-on-modify-request观察者话题 如果观察者通知的主题是和
- 创建新的
- 创建一个新的
nsIHttpChannel
- 用新的替换旧的频道。在HTTPS Everywhere中执行此操作的代码非常密集,可能比您需要的要多得多。我建议从。
subject.URI.spec
(网址)符合您的标准 你应该为你的整个应用程序注册一个http-on-modify-request观察者,这意味着你应该把它放在一个XPCOM组件中(例如见例子中的HTTPS Everywhere)。$ b
$ b
以下文章不直接解决您的问题,但它们包含大量可能有用的示例代码:
I want to prefix URLs which match my patterns. When I open a new tab in Firefox and enter a matching URL the page should not be loaded normally, the URL should first be modified and then loading the page should start.
Is it possible to modify an URL through a Mozilla Firefox Addon before the page starts loading?
Browsing the HTTPS Everywhere add-on suggests the following steps:
- Register an observer for the "http-on-modify-request" observer topic with nsIObserverService
- Proceed if the subject of your observer notification is an instance of nsIHttpChannel and
subject.URI.spec
(the URL) matches your criteria - Create a new nsIStandardURL
- Create a new
nsIHttpChannel
- Replace the old channel with the new. The code for doing this in HTTPS Everywhere is quite dense and probably much more than you need. I'd suggest starting with
chrome/content/IOUtils.js
.
Note that you should register a single "http-on-modify-request" observer for your entire application, which means you should put it in an XPCOM component (see HTTPS Everywhere for an example).
The following articles do not solve your problem directly, but they do contain a lot of sample code that you might find helpful:
- https://developer.mozilla.org/en/Setting_HTTP_request_headers
- https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads
这篇关于在Firefox中加载页面之前修改URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!