在 Firefox 中加载页面之前修改 URL
我想为与我的模式匹配的 URL 添加前缀。当我在 Firefox 中打开新选项卡并输入匹配的 URL 时,页面不应正常加载,应首先修改 URL,然后开始加载页面。
是否可以在页面开始加载之前通过 Mozilla Firefox 插件修改 URL?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
浏览 HTTPS Everywhere 插件建议执行以下步骤:
subject 的实例,请继续。 URI.spec
(URL)符合您的条件chrome/content/IOUtils.js
。请注意,您应该为整个应用程序注册一个“http-on-modify-request”观察器,这意味着您应该将其放在 XPCOM 组件中(有关示例,请参阅 HTTPS Everywhere)。
以下文章不能直接解决您的问题,但它们确实包含许多可能对您有用的示例代码:
Browsing the HTTPS Everywhere add-on suggests the following steps:
subject.URI.spec
(the URL) matches your criteriansIHttpChannel
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:
感谢 Iwburk,我才能够做到这一点。
我们可以用一个新的覆盖
nsiHttpChannel
来实现这一点,这样做有点复杂,但幸运的是,附加组件https-everywhere
实现了这一点以强制建立 https 连接。https-everywhere
的源代码可用 这里所需的大部分代码都在文件中
IO Util.js
ChannelReplacement.js
只要我们设置了 Cc、Ci 等基本变量和函数
xpcom_generateQI
已定义。该代码将替换请求而不是重定向。
虽然我已经很好地测试了上面的代码,但我不确定它的实现。据我所知,它复制了所请求通道的所有属性并将它们设置为要覆盖的通道。之后,以某种方式使用新通道提供原始请求所请求的输出。
PS 我看过一篇 SO 帖子,其中建议了这种方法。
Thanks to Iwburk, I have been able to do this.
We can do this my overriding the
nsiHttpChannel
with a new one, doing this is slightly complicated but luckily the add-onhttps-everywhere
implements this to force a https connection.https-everywhere
's source code is available hereMost of the code needed for this is in the files
IO Util.js
ChannelReplacement.js
We can work with the above files alone provided we have the basic variables like Cc,Ci set up and the function
xpcom_generateQI
defined.The code will replace the request not redirect.
While I have tested the above code well enough, I am not sure about its implementation. As far I can make out, it copies all the attributes of the requested channel and sets them to the channel to be overridden. After which somehow the output requested by original request is supplied using the new channel.
P.S. I had seen a SO post in which this approach was suggested.
您可以监听 页面加载事件 或者
DOMContentLoaded
事件代替。或者你可以制作一个nsIURIContentListener
但这是可能更复杂。You could listen for the page load event or maybe the
DOMContentLoaded
event instead. Or you can make annsIURIContentListener
but that's probably more complicated.是的,这是可能的。
通过设置
contentScriptWhen: "start"
使用 Addon-SDK 的 page-mod然后在完全阻止文档被解析后,您可以
document.URL
处理后,执行location.replace()
调用以下是执行 1 的示例。 https://stackoverflow.com/a/36097573/6085033
YES it is possible.
Use page-mod of the Addon-SDK by setting
contentScriptWhen: "start"
Then after completely preventing the document from getting parsed you can either
document.URL
processing do alocation.replace()
callHere is an example of doing 1. https://stackoverflow.com/a/36097573/6085033