小编Tom*_*mmy的帖子

试图在firefox中跟踪未完成的AJAX请求的数量

我正在使用Selenium来测试Web应用程序,不允许修改应用程序的javascript代码.我试图通过使用GreaseMonkey来覆盖XMLHttpRequest.send来跟踪未完成的AJAX请求的数量.新的send()将基本上包装设置为onreadystatechange回调的内容,检查readyState,根据需要递增或递减计数器,并调用原始回调函数.

我遇到的问题似乎是一个特权问题,因为如果我只是浏览到普通firefox浏览器中的页面,打开firebug并粘贴以下代码,它似乎工作正常:

document.ajax_outstanding = 0;
if (typeof XMLHttpRequest.prototype.oldsend != 'function') {
    XMLHttpRequest.prototype.oldsend = XMLHttpRequest.prototype.send;
    XMLHttpRequest.prototype.send = function() {
        console.log('in new send');
        console.log('this.onreadystatechange = ' + this.onreadystatechange);
        this.oldonreadystatechange = this.onreadystatechange;
        this.onreadystatechange = function() {
            if (this.readyState == 2) {
                /* LOADED */
                document.ajax_outstanding++;
                console.log('set ajax_outstanding to ' + document.ajax_outstanding);
            }
            this.oldonreadystatechange.handleEvent.apply(this, arguments);
            if (this.readyState == 4) {
                /* COMPLETED */
                document.ajax_outstanding--;
                console.log('set ajax_outstanding to ' + document.ajax_outstanding);
            }
        };
        this.oldsend.apply(this, arguments);
    };
}
Run Code Online (Sandbox Code Playgroud)

现在,如果我在GreaseMonkey用户脚本中使用该片段的略微修改版本,如下所示:

unsafeWindow.document.ajax_outstanding = 0;
if (typeof unsafeWindow.XMLHttpRequest.prototype.oldsend != …
Run Code Online (Sandbox Code Playgroud)

javascript firefox greasemonkey sandbox xmlhttprequest

6
推荐指数
1
解决办法
2427
查看次数

如何查询特定邻居的IPv6 NDP(邻居发现协议)表

我正在使用Linux并试图弄清楚如何查询(通过API)特定条目的NDP表.到目前为止,我发现的唯一示例(在iproute2的源代码中)使用Netlink并获取整个表.有没有办法在特定接口上查询Netlink以获取特定的IPv6地址?还是有一种不同于使用Netlink的方式我应该去做呢?

linux ipv6 arp netlink

5
推荐指数
1
解决办法
1948
查看次数

postgresql触发函数死锁

使用postgres 9.3,我有一个名为regression_runs 的表来存储一些计数器。当更新、插入或删除此表中的行时,将调用触发器函数来更新 nightly_runs 表中的行,以保留具有给定 ID 的所有回归_运行的这些计数器的运行总计。我所采用的方法已被广泛记录。然而,我的问题是,当多个进程尝试同时在具有相同 nightly_run_id 的 regression_runs 表中插入新行时,我遇到了死锁。

regression_runs 表如下所示:

regression=> \d regression_runs
                                      Table "public.regression_runs"
     Column      |           Type           |                          Modifiers                           
-----------------+--------------------------+--------------------------------------------------------------
 id              | integer                  | not null default nextval('regression_runs_id_seq'::regclass)
 username        | character varying(16)    | not null
 nightly_run_id  | integer                  | 
 nightly_run_pid | integer                  | 
 passes          | integer                  | not null default 0
 failures        | integer                  | not null default 0
 errors          | integer                  | not null default 0
 skips           | integer                  | not null default 0
Indexes: …
Run Code Online (Sandbox Code Playgroud)

postgresql triggers deadlock

4
推荐指数
1
解决办法
3452
查看次数