908517142 发表于 2023-2-7 16:38:08

908517142 发表于 2023-2-7 09:24
谢谢 终于拿到了,这个引用的脚本真厉害

这个油猴不知道为什么总是出现一些特别的问题,还是太不熟悉了
我在对自己的服务发送小心的时候,无论写什么参数都是收到一个
请问大神哥哥知道这是为什么吗
我前端是这么发送的
GM_xmlhttpRequest({
                url:"http://localhost:8092/api/parseJson/parseContacts",
                method :"POST",
                crossDomain: true,
                async: true,
                data :{'res': ''},
                dataType: 'json',
                headers: {
                  "contentType": "application/json;utf-8"
                },
                onload:function(xhr){
                  console.log('contacts');
                }
            });

cxxjackie 发表于 2023-2-7 20:43:09

908517142 发表于 2023-2-7 16:38
这个油猴不知道为什么总是出现一些特别的问题,还是太不熟悉了
我在对自己的服务发送小心的时候,无论写 ...

data: JSON.stringify({'res': ''})
application/json接收的是一个json字符串,而你发送的是一个json对象。另外你GM_xmlhttpRequest的参数写的也不太对,GM_xhr本身就是跨域的,没有crossDomain,默认异步也没有async,dataType是jQuery写法,GM_xhr里叫responseType。建议多看看官方文档:
https://www.tampermonkey.net/documentation.php#api:GM_xmlhttpRequest
也可以试试我写的另一个库:
https://bbs.tampermonkey.net.cn/thread-2793-1-1.html

Major 发表于 2023-2-23 16:52:06

1.2.2 版本能给一个完整一点的示例吗

cxxjackie 发表于 2023-2-23 20:30:22

Major 发表于 2023-2-23 16:52
1.2.2 版本能给一个完整一点的示例吗

用法没有变化啊,是指filter的示例吗?比如只想捕获所有xhr的get请求和fetch的post请求:
ajaxHooker.filter([
    {type: 'xhr', method: 'get'}.
    {type: 'fetch', method: 'post'}
]);
xhr的过滤就相当于把你代码里对url的判断放到这里来了,具体是哪里看不懂呢?

Major 发表于 2023-2-24 09:35:43

cxxjackie 发表于 2023-2-23 20:30
用法没有变化啊,是指filter的示例吗?比如只想捕获所有xhr的get请求和fetch的post请求:

xhr的过滤就相 ...

我用1.2.0的库写的代码,然后换成1.2.2库然后发现运行不了了。

然后我用1.2.2的这个库,想hook一个请求,不知道怎么操作了

let a = {

    hook_send_severs:function(){
      let hookurl = /omni\/inventory\/itemInv\/query$/
      ajaxHooker.filter([
            {type: 'xhr', url:hookurl , method: 'GET'},
            {url: hookurl},
            // ajaxHooker.hook(function(request){
            //   console.log("url:",request.url);
            //   console.log("data:",request.data);
            //   console.log("response:",request.response);
            // }),
      ]);

    },
};

cxxjackie 发表于 2023-2-24 20:34:06

Major 发表于 2023-2-24 09:35
我用1.2.0的库写的代码,然后换成1.2.2库然后发现运行不了了。

然后我用1.2.2的这个库,想hook一个请求 ...

不是,你别把hook写进filter里啊,这两个是独立的函数,只是说filter应在hook之前执行:
ajaxHooker.filter(...);
ajaxHooker.hook(...);
hook的用法跟之前是一样的,加不加filter都能执行,filter是对所有hook生效的过滤器,主要是提升性能用的。

Major 发表于 2023-2-27 14:38:25

cxxjackie 发表于 2023-2-24 20:34
不是,你别把hook写进filter里啊,这两个是独立的函数,只是说filter应在hook之前执行:

hook的用法跟之 ...

是这样吗,好像没有过滤 例如捕获这个网址的请求数据https://g.cainiao.com/omni/inventory/itemInv/query


let a = {
    hook_send_severs:function(){
      // let hookurl = /omni\/inventory\/itemInv\/query$/

      ajaxHooker.filter(
            {type: 'xhr',   url:'https://g.cainiao.com/omni/inventory/itemInv/query' , method: 'POST'},
            // {type: 'fetch', url:'https://g.cainiao.com/omni/inventory/itemInv/query' , method: 'POST'},
      );

      ajaxHooker.hook(function(request){
            console.log("汉 →   url:",request.url);
            console.log("汉 →   data:",request.data);
            console.log("汉 →   respons:",request.response);
      });

    },
};

(function(){
    if(document.location.href.match(/warehouse-inventory-query-v2/)){
      a.hook_send_severs();
    };
})()

cxxjackie 发表于 2023-2-27 22:13:21

Major 发表于 2023-2-27 14:38
是这样吗,好像没有过滤 例如捕获这个网址的请求数据https://g.cainiao.com/omni/inventory/itemInv/quer ...

对象数组,你没加方括号。

Major 发表于 2023-2-28 09:43:03

cxxjackie 发表于 2023-2-27 22:13
对象数组,你没加方括号。

还是不行啊,例如下面的代码 加上filter 之后,一直停留在hook 上转圈圈,一个网址都都hook不到了
let a = {
    hook_send_severs:function(){
      // let hookurl = /omni\/inventory\/itemInv\/query$/

      ajaxHooker.filter([
            {url:'https://g.cainiao.com/omni/inventory/itemInv/query' ,method: 'POST'},
            // {type: 'xhr',   url:'https://g.cainiao.com/omni/inventory/itemInv/query' , method: 'POST'},
            // {type: 'fetch', url:'https://g.cainiao.com/omni/inventory/itemInv/query' , method: 'POST'},
            // {url: /^http/},
      ]);

      ajaxHooker.hook(function(request){
            console.log("汉 →   url:",request.url);
            // console.log("汉 →   data:",request.data);
            // console.log("汉 →   respons:",request.response);
      });

    },
};

(function(){
    if(document.location.href.match(/warehouse-inventory-query-v2/)){
      a.hook_send_severs();
    };
})()

cxxjackie 发表于 2023-2-28 22:18:16

Major 发表于 2023-2-28 09:43
还是不行啊,例如下面的代码 加上filter 之后,一直停留在hook 上转圈圈,一个网址都都hook不到了
...

不加filter能否hook到?这个过滤是白名单机制,hook不到可能规则有问题,url是否写多了?有些请求url是相对路径,你先不加filter抓一下看看,可能不是http开头的。
页: 1 2 3 4 5 6 7 8 9 [10] 11 12 13 14 15 16 17
查看完整版本: ajax劫持库ajaxHooker