JML 发表于 2024-1-9 15:54:38

xhr/fetch劫持失败问题

本帖最后由 JML 于 2024-1-9 15:58 编辑

终于找到两个测试网站
1. https://app.grammarly.com/
2. https://www.kdocs.cn/l/cvz6BJpAdbHV

使用油猴脚本或者抓包工具修改响应数据都不成功,要么网页部分内容显示不全,要么网页显示网络链接失败
有大佬帮忙看看使用油猴脚本有实现劫持修改响应数据的可能吗?

admin 发表于 2024-1-9 16:17:15

给个失败的脚本例子

JML 发表于 2024-1-9 21:21:17

本帖最后由 JML 于 2024-1-9 21:23 编辑

admin 发表于 2024-1-9 16:17
给个失败的脚本例子// ==UserScript==
// @name         测试
// @namespace    no
// @version      1.0
// @description测试
// @author       1skiwen
// @match      https://www.kdocs.cn/l/*
// @match      https://www.kdocs.cn/view/l/*
// @icon         https://v.flomoapp.com/favicon.ico
// @run-at                   document-start
// @grant      none
// ==/UserScript==

const origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function () {
const xhr = this;
const getter = Object.getOwnPropertyDescriptor(
    XMLHttpRequest.prototype,
    "response"
).get;
Object.defineProperty(xhr, "responseText", {
    get: () => {
      let result = getter.call(xhr);
      if (arguments.includes('/metadata?with_link=true') || arguments.includes('/metadata?from=preview') || arguments.includes('/metadata?include=group') || arguments.includes('?review=true')) {
      console.log("测试测试。");
      let json = JSON.parse(result);
      json.user_acl = { "comment": 1, "copy": 1, "delete": 1, "download": 1, "history": 1, "manage_perm": 1, "move": 1, "new_empty": 1, "read": 1, "rename": 1, "saveas": 1, "secret": 0, "share": 1, "update": 1, "upload": 1 };
      result = JSON.stringify(json);
      }
      return result;
    },
});
return origOpen.apply(xhr, arguments);
};

李恒道 发表于 2024-1-9 21:46:21

JML 发表于 2024-1-9 21:21


怎么才能触发xhr的请求

JML 发表于 2024-1-9 21:53:52

李恒道 发表于 2024-1-9 21:46
怎么才能触发xhr的请求

https://www.kdocs.cn/l/cvz6BJpAdbHV

JML 发表于 2024-1-9 21:59:27

本帖最后由 JML 于 2024-1-9 22:57 编辑

李恒道 发表于 2024-1-9 21:46
怎么才能触发xhr的请求
****64:

李恒道 发表于 2024-1-10 01:33:16

JML 发表于 2024-1-9 21:53
https://www.kdocs.cn/l/cvz6BJpAdbHV

貌似都正常执行了
网页显示失败是指什么
![图片.png](data/attachment/forum/202401/10/013310nu58prgk5dvt88iz.png)
页: [1]
查看完整版本: xhr/fetch劫持失败问题