上一主题 下一主题
ScriptCat,新一代的脚本管理器脚本站,与全世界分享你的用户脚本油猴脚本开发指南教程目录
返回列表 发新帖

ajax劫持库ajaxHooker怎么取fetch得响应

[复制链接]
  • TA的每日心情
    开心
    2024-4-6 10:52
  • 签到天数: 4 天

    [LV.2]偶尔看看I

    4

    主题

    4

    回帖

    15

    积分

    助理工程师

    积分
    15
    发表于 2024-3-31 15:10:21 | 显示全部楼层 | 阅读模式
    悬赏2油猫币已解决

    {type: 'fetch', url: '/upload_json', method: 'GET', async: true}
    请问 ajax劫持库ajaxHooker怎么取fetch得响应,注意是fetch的响应,
    request.response不能得到响应

    已知xhr可以通过 modifyResponse达到修改。
    {type: 'xhr', url: '/upload_json', method: 'POST', async: true}
    request.response = async res => {
    res.responseText = await modifyResponse(res.responseText);
    }

    最佳答案

    查看完整内容

    [md]是可以的吧 提问最好给一个自己能复现问题的样例页面和脚本代码 ```html Document setTimeout(() => { fetch("https://api.github.com/users/ruanyf") .then((response) => response.json()) .then((json) => console.log(json)) .catch((err) => console.log("Request Failed", err)); }, 1000); ``` ```js // ==UserScript== // ...
  • TA的每日心情
    开心
    2023-2-28 23:59
  • 签到天数: 191 天

    [LV.7]常住居民III

    637

    主题

    5213

    回帖

    6089

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6089

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2024-3-31 15:10:22 | 显示全部楼层

    是可以的吧

    提问最好给一个自己能复现问题的样例页面和脚本代码

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <script>
          setTimeout(() => {
            fetch("https://api.github.com/users/ruanyf")
              .then((response) => response.json())
              .then((json) => console.log(json))
              .catch((err) => console.log("Request Failed", err));
          }, 1000);
        </script>
      </head>
      <body></body>
    </html>
    
    // ==UserScript==
    // @name         New Userscript
    // @namespace    http://tampermonkey.net/
    // @version      2024-03-31
    // @description  try to take over the world!
    // @author       You
    // @match        http://127.0.0.1:5500/index.html
    // @icon         https://www.google.com/s2/favicons?sz=64&domain=0.1
    // @require https://scriptcat.org/lib/637/1.3.3/ajaxHooker.js
    // @grant        none
    // ==/UserScript==
    
    ajaxHooker.hook(request => {
        console.log(request);
        request.response = res => {
            console.log(res.json);
        };
    });
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

    发表回复

    本版积分规则

    快速回复 返回顶部 返回列表