Firefox Addon观察者http-on-modify-request无法正常工作(Firefox Addon observer http-on-modify-request not working properly)
我的插件中有一个奇怪的错误,插件本身需要为特定域添加一个请求头参数,它一切正常,但是错误是,观察者http-on-modify-request在启动时没有被调用,只是如果我重新加载页面,那么它正在工作。
我的意思是:
- 我去mysite.com/ - 没有标题修改 ,
- 我重新加载页面 - 标题模式
- 重新加载 - 标题修改
- mysite.com/上的新标签 - 未修改标题
- 重新加载标签 - 标题已修改
我的代码,我正在使用插件sdk:
exports.main = function(options,callbacks) { // Create observer httpRequestObserver = { observe: function(subject, topic, data) { if (topic == "http-on-modify-request") { //only identify to specific preference domain var windowsService = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator); var uri = windowsService.getMostRecentWindow('navigator:browser').getBrowser().currentURI; var domainloc = uri.host; if (domainloc=="mysite.com"){ var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel); httpChannel.setRequestHeader("x-test", "test", false); } } }, register: function() { var observerService = Cc["@mozilla.org/observer-service;1"] .getService(Ci.nsIObserverService); observerService.addObserver(this, "http-on-modify-request", false); }, unregister: function() { var observerService = Cc["@mozilla.org/observer-service;1"] .getService(Ci.nsIObserverService); observerService.removeObserver(this, "http-on-modify-request"); } }; //register observer httpRequestObserver.register(); }; exports.onUnload = function(reason) { httpRequestObserver.unregister(); };
请帮助我,我搜索了几个小时没有结果。 代码正在运行,但不是在第一次加载页面时,只有在我重新加载时。
目标是只有在mysite.com上,才会有一个
x-text=test
header请求,但只能在mysite.com上。I have a weird bug in my addon, the addon itself needs to add a request header parameters for a specific domain, it's all working, but the bug is, that the observer http-on-modify-request is not called at start, only if I reload the page, then it's working.
I mean:
- I go to mysite.com/ - no header modified,
- I reload page - header modefied
- reload again - header modefied
- new tab at mysite.com/ - no header modified
- reload tab - header modefied
My code, I'm using the addon sdk:
exports.main = function(options,callbacks) { // Create observer httpRequestObserver = { observe: function(subject, topic, data) { if (topic == "http-on-modify-request") { //only identify to specific preference domain var windowsService = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator); var uri = windowsService.getMostRecentWindow('navigator:browser').getBrowser().currentURI; var domainloc = uri.host; if (domainloc=="mysite.com"){ var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel); httpChannel.setRequestHeader("x-test", "test", false); } } }, register: function() { var observerService = Cc["@mozilla.org/observer-service;1"] .getService(Ci.nsIObserverService); observerService.addObserver(this, "http-on-modify-request", false); }, unregister: function() { var observerService = Cc["@mozilla.org/observer-service;1"] .getService(Ci.nsIObserverService); observerService.removeObserver(this, "http-on-modify-request"); } }; //register observer httpRequestObserver.register(); }; exports.onUnload = function(reason) { httpRequestObserver.unregister(); };
Please help me, I searched for hours with no results. The code is working, but not at first time of page loading, only if I reload.
The goal is that only on mysite.com, there will be a
x-text=test
header request, all the time, but only on mysite.com.
原文:https://stackoverflow.com/questions/21222873
最满意答案
解决了!
通过正在进行的研究,搜索论坛和源代码库,我只用libwebkit和标准compiz桌面(任何带有合成的Xorg桌面都应该这样做)来完成这些必要步骤。
对于当前的libwebkit(1.1.10-SVN),有一个Ubuntu PPA:
deb http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main deb-src http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main
就代码而言,关键是调用
webkit_web_view_set_transparent
。当然,你运行它的系统应该有一个有能力的图形卡(intel,radeon或nvidia),并运行合成窗口管理器(如Compiz)。
最后,为了真正看到透明度,您查看的内容必须使用CSS3设置透明背景,否则它仍然是完全不透明的。
这很简单:
BODY { background-color: rgba(0,0,0,0); }
这里是最简单的webkit浏览器应用程序的完整示例,支持透明度:
#include <gtk/gtk.h> #include <webkit/webkit.h> static void destroy_cb(GtkWidget* widget, gpointer data) { gtk_main_quit(); } int main(int argc, char* argv[]) { gtk_init(&argc, &argv); if(!g_thread_supported()) g_thread_init(NULL); // Create a Window, set colormap to RGBA GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); GdkScreen *screen = gtk_widget_get_screen(window); GdkColormap *rgba = gdk_screen_get_rgba_colormap (screen); if (rgba && gdk_screen_is_composited (screen)) { gtk_widget_set_default_colormap(rgba); gtk_widget_set_colormap(GTK_WIDGET(window), rgba); } gtk_window_set_default_size(GTK_WINDOW(window), 800, 800); g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL); // Optional: for dashboard style borderless windows gtk_window_set_decorated(GTK_WINDOW(window), FALSE); // Create a WebView, set it transparent, add it to the window WebKitWebView* web_view = web_view = WEBKIT_WEB_VIEW(webkit_web_view_new()); webkit_web_view_set_transparent(web_view, TRUE); gtk_container_add (GTK_CONTAINER(window), GTK_WIDGET(web_view)); // Load a default page webkit_web_view_load_uri(web_view, "http://stackoverflow.com/"); // Show it and continue running until the window closes gtk_widget_grab_focus(GTK_WIDGET(web_view)); gtk_widget_show_all(window); gtk_main(); return 0; }
Solved!
Through ongoing research, scouring forums and source code repositories, I peiced together the necessary steps to accomplish this using only libwebkit and a standard compiz desktop (any Xorg desktop with compositing should do).
For a current libwebkit (1.1.10-SVN), there is an Ubuntu PPA:
deb http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main deb-src http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main
As far as the code goes, the key is calling
webkit_web_view_set_transparent
.And of course the system you're running it on should have a capable graphics card (intel, radeon, or nvidia) and be running a compositing window manager (like Compiz).
And finally, to actually see transparency, the content you're viewing must set a transparent background using CSS3, otherwise it's still completely opaque.
It's as simple as:
BODY { background-color: rgba(0,0,0,0); }
Here' is the full sample for the simplest possible webkit browser app, with transparency support:
#include <gtk/gtk.h> #include <webkit/webkit.h> static void destroy_cb(GtkWidget* widget, gpointer data) { gtk_main_quit(); } int main(int argc, char* argv[]) { gtk_init(&argc, &argv); if(!g_thread_supported()) g_thread_init(NULL); // Create a Window, set colormap to RGBA GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); GdkScreen *screen = gtk_widget_get_screen(window); GdkColormap *rgba = gdk_screen_get_rgba_colormap (screen); if (rgba && gdk_screen_is_composited (screen)) { gtk_widget_set_default_colormap(rgba); gtk_widget_set_colormap(GTK_WIDGET(window), rgba); } gtk_window_set_default_size(GTK_WINDOW(window), 800, 800); g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL); // Optional: for dashboard style borderless windows gtk_window_set_decorated(GTK_WINDOW(window), FALSE); // Create a WebView, set it transparent, add it to the window WebKitWebView* web_view = web_view = WEBKIT_WEB_VIEW(webkit_web_view_new()); webkit_web_view_set_transparent(web_view, TRUE); gtk_container_add (GTK_CONTAINER(window), GTK_WIDGET(web_view)); // Load a default page webkit_web_view_load_uri(web_view, "http://stackoverflow.com/"); // Show it and continue running until the window closes gtk_widget_grab_focus(GTK_WIDGET(web_view)); gtk_widget_show_all(window); gtk_main(); return 0; }
相关问答
更多-
使用WebKit可以在清晰的背景上呈现网页内容吗?(Is it possible to render web content over a clear background using WebKit?)[2023-09-04]
解决了! 通过正在进行的研究,搜索论坛和源代码库,我只用libwebkit和标准compiz桌面(任何带有合成的Xorg桌面都应该这样做)来完成这些必要步骤。 对于当前的libwebkit(1.1.10-SVN),有一个Ubuntu PPA: deb http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main deb-src http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main 就 ... -
使用清晰的背景颜色使UIButton内容完全可插拔(Making UIButton content fully tappable with clear background color)[2023-07-22]
应用UIColor(white:0.000, alpha:0.020)的backgroundColor UIColor(white:0.000, alpha:0.020) 。 人眼无法看到这种颜色 - 它在今日小部件中看起来完全透明 - 但按钮背景现在可以点亮。 Apply a backgroundColor of UIColor(white:0.000, alpha:0.020). The human eye cannot see this color — it appears completely tr ... -
不支持图层支持的WebView。 从Leopard发行说明: AppKit和Mac OS X的其他Cocoa框架提供的大多数标准视图和控件都能够在Leopard中以层支持模式运行,但某些专用视图除外,例如WebKit WebViews和Quartz Composer QCViews,它们在层中的使用 - 目前不支持支持模式。 ( http://developer.apple.com/mac/library/releasenotes/cocoa/AppKitOlderNotes.html#Animation ...
-
Android Webkit在后台(Android Webkit in background)[2020-01-06]
让它隐形。 Make it invisible. -
webkit能做什么?(What can webkit do?)[2022-05-12]
WebKit已经实现了很多很酷的基于标准的功能: HTML5网络套接字 HTML5视频和音频 HTML5网络工作者 HTML5地理位置 客户端数据库存储 应用程序缓存 CSS 3动画 CSS 3渐变 CSS 3 3d转换 WebKit has implemented a lot of cool standards-based features: HTML5 web sockets HTML5 video and audio HTML5 web workers HTML5 geolocation Client ... -
无需JavaScript即可在WebKit2 Web Extension中清除选择(Clear selection in WebKit2 Web Extension without JavaScript)[2021-12-27]
WebKit2似乎有一个不稳定的API,不会出现在文档中。 我能够使用webkit_dom_dom_window_get_selection获取当前选择并使用webkit_dom_dom_window_get_selection清除它 WebKit2 seems to have an unstable API that does not appear in the documentation. I was able to get the current selection with the webkit_d ... -
为什么Qt Webkit与Chromium webkit的呈现方式不同(why does Qt Webkit render differently to Chromium webkit)[2022-05-24]
看起来你对哪个浏览器布局引擎有些困惑。 澄清: QtWebKit基于Apple的WebKit(反过来又是KDE的KHTML的一个分支) 最近版本的谷歌Chrome / Chromium基于谷歌的Blink (这是Apple的WebKit的一个分支。)旧版本基于WebKit。 虽然WebKit和Blink非常相似,但它们并不完全相同。 根据MDN WebKit,flex的实现仍然以供应商前缀-webkit-flex命名,因为Apple还没有更新到最新的W3C规范。 另请注意, 即将推出的QtWebEngine ... -
WebKit Transitions JQuery AddClass什么都不做(WebKit Transitions JQuery AddClass does nothing)[2021-11-10]
你忘了在你的风格中添加!important标志,但你在小提琴的前半部分使用了它。 这就是它与第一个元素一起工作的原因。 默认情况下,CSS规则按特定顺序应用 。 更具体的选择器会覆盖更常规的选择器,因此如果向类添加类(常规),则项目ID(特定)的CSS规则集将优先。 .slideback { opacity:1.0 !important;filter:alpha(opacity=100) !important; -webkit-transition-property:opacity !imp ... -
::-webkit-slider-thumb无法接受content属性。 请尝试设置背景图像。 ::-webkit-slider-thumb cannot accept the content property. Try setting a background image, instead.