如何通过 Firefox 扩展阻止 Firefox 下载和应用 CSS?
提前感谢大家——
所以我已经研究这个问题很长一段时间了,并且已经考虑了我所有的选择。我当前取消CSS请求的方法是在nsIWebProgressListener.onStateChange内部使用nsIRequest.cancel。这在大多数情况下都有效,除非事情有点滞后,在我到达它们之前,有一些会滑过并跳出负载组。这显然是一个肮脏的解决方案。
我已阅读以下链接,尝试更好地了解如何在创建 nsIRequest 之前禁用 css...没有骰子。
https://developer.mozilla.org/en/Document_Loading_-_From_Load_Start_to_Finding_a_Handler https://developer.mozilla.org/en/The_life_of_an_HTML_HTTP_request https://developer.mozilla.org/en/Bird's_Eye_View_of_the_Mozilla_Framework
如何禁用 CSS通过演示对象/接口?这可能吗? nsIDocShell 内部有一些属性,暗示您可以通过浏览器 docshell 禁用 css -allowPlugins、allowJavascript、allowMetaRedirects、allowSubframes、allowImages。
有什么建议吗?
谢谢,
萨姆
Thanks to everyone in advance -
So I have been banging on this issue for quite a while now and have burned through all my options. My current approach to canceling css requests is with nsIRequest.cancel inside of nsIWebProgressListener.onStateChange. This works most of the time, except when things are a little laggy a few will slip through and jump out of the loadgroup before I can get to them. This is obviously a dirty solution.
I have read through the following links to try and get a better idea of how to disable css before a nsIRequest is created...no dice.
https://developer.mozilla.org/en/Document_Loading_-_From_Load_Start_to_Finding_a_Handler
https://developer.mozilla.org/en/The_life_of_an_HTML_HTTP_request
https://developer.mozilla.org/en/Bird's_Eye_View_of_the_Mozilla_Framework
How do I disable css via presentation objects/interfaces? Is this possible? Inside of nsIDocShell there are a few attributes that kind of imply you can disable css via the browsers docshell - allowPlugins, allowJavascript, allowMetaRedirects, allowSubframes, allowImages.
Any suggestions?
Thanks,
Sam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
禁用样式表的菜单选项使用一个函数
,因此您可以在创建新的浏览器选项卡时调用此函数。样式表仍然从服务器请求,但不应用。这个函数不是很复杂,不会与 nsIRequest 混淆,来源:
挖掘 Web 开发工具栏源代码我注意到他们的“禁用样式表”函数循环遍历所有
document.styleSheets
并设置 < code>disabled 属性设置为true
,例如:因此,如果关键是不将 CSS 应用到页面,则上述解决方案之一应该有效。但如果您确实需要阻止从服务器下载样式表,我担心 nsIRequest 拦截是您唯一的选择。
The menu option that disables style sheets uses a function
so you probably can just call this function whenever new browser tab is created. Style sheets are still requested from server, but not applied. This function is not very sophisticated and doesn't mess with nsIRequest, source:
Digging in Web Developer Toolbar source code I have noticed that their "disable stylesheets" function loops trough all
document.styleSheets
and sets thedisabled
property totrue
, like:So if the key is to not apply CSS to pages, one of the above solutions should work. But if you really need to stop style sheets from being downloaded from servers, I'm affraid
nsIRequest
interception is your only option.将 requests.default.stylesheet 设置为 2,瞧!
实际上,您可以使用权限管理器在逐个主机的基础上阻止或允许样式表。
Set permissions.default.stylesheet to 2 and voilà!
You can actually use the permissions manager to block or allow stylesheets on a host-by-host basis.
不幸的是,似乎没有像allowImages 这样的简单标志。为此添加的 bugzilla 是 https://bugzilla.mozilla.org/show_bug.cgi?id =340746。您现在可以使用新的 bugzilla 投票功能为其投票。您还可以将自己添加到 CC 列表中,以便在有人使用该列表时收到通知。
一个相关的请求是为我们提供基本的 HTML 解析支持,这可能就是您想要做的。不幸的是,这还不支持,但您可以在 https 上投票/跟踪 bugzilla ://bugzilla.mozilla.org/show_bug.cgi?id=102699。
因此,唯一可行的解决方案似乎是@pawal 建议的某种拦截。这是一个讨论拦截基础知识的链接,至少可以让您/我们开始https:// developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads。它列出了我在下面列出的几个选项。
前几个似乎只是在页面/文档级别,所以我认为它们没有帮助:
这使得另外两个我还没有尝试过。它们在全球范围内工作,因此您需要将它们过滤到您关心的浏览器/页面。
Unfortunately there doesn't seem to be a simple flag like allowImages. The bugzilla adding for that is https://bugzilla.mozilla.org/show_bug.cgi?id=340746. You can now vote for it using the new bugzilla voting functionality. You can also add yourself to the CC list to be notified if anyone ever works on it.
A related request is to just give us basic HTML parsing support, which may be what you are trying to do. Unfortunately that isn't supported yet either, but you can vote/track the bugzilla for that at https://bugzilla.mozilla.org/show_bug.cgi?id=102699.
So the only workable solution seems to be some sort of interception as @pawal suggests. Here is a link that talks about the basics of interception to at least get you/us started https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads. It lists several options that I list below.
These first few seem to just be at the page/document level so I don't think they help:
That leaves two others I have not tried yet. They work globally so you would need to filter them to just the browser/pages you care about.