├── .gitignore ├── LICENSE ├── README.md ├── main.js ├── markdown-images └── README_images │ ├── 02986e81.png │ ├── 4ca71531.png │ └── c2f268cf.png └── test_case ├── by-location.html ├── submit-form-by-js.html └── submit-form.html /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 CC11001100 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 页面跳转JS代码定位通杀方案 2 | 3 | ## 一、原理概述 4 | 5 | 1. 通过`window.onbeforeunload`事件下一个断点,阻断跳转使其留在当前页面 6 | 2. 追栈,上一个栈帧就是跳转逻辑,秒定位。 7 | 8 | ## 二、案例 https://www.agefans.cc 9 | 10 | 这个网站在播放页面打开开发者工具会跳转到首页,来定位一下它,先打开一个空白的标签页,然后粘贴网址: 11 | [https://www.agefans.cc/play/20190169?playid=2_1](https://www.agefans.cc/play/20190169?playid=2_1) 12 | ![](markdown-images/README_images/c2f268cf.png) 13 | 然后按F12打开开发者工具,页面在跳转之前进入了断点: 14 | ![](markdown-images/README_images/02986e81.png) 15 | 然后追调用栈,上一个栈帧就是跳转逻辑: 16 | ![](markdown-images/README_images/4ca71531.png) 17 | 18 | ## 三、注意 19 | 20 | 检测开发者工具是否打开的方式有很多,检测到打开之后重定向到某个页面只是一个应对行为,此工具只是用来解决一个很窄的情况。 21 | 22 | 检测到之后重定向并不是一个好的应对行为,因为笔者注意到之前收藏的几个检测到后重定向的网站都改为了检测之后不再重定向而是其他应对策略。 23 | 24 | 25 | ## 四、其它 26 | 本项目自项目[https://github.com/CC11001100/crawler-js-hook-framework-public](https://github.com/CC11001100/crawler-js-hook-framework-public)迁移至此,原项目太多内容放在一个项目里,因此分发为多个小项目。 27 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name 页面跳转JS代码定位通杀方案 3 | // @namespace https://github.com/JSREI/page-redirect-code-location-hook 4 | // @version 0.2 5 | // @description 阻断页面跳转,留在当前页面分析 6 | // @author CC11001100 7 | // @match *://*/* 8 | // @run-at document-start 9 | // @grant none 10 | // @license MIT 11 | // ==/UserScript== 12 | (() => { 13 | 14 | // 使用说明: https://github.com/JSREI/page-redirect-code-location-hook 15 | 16 | window.onbeforeunload = () => { 17 | debugger; 18 | return false; 19 | } 20 | 21 | })(); 22 | -------------------------------------------------------------------------------- /markdown-images/README_images/02986e81.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JSREI/page-redirect-code-location-hook/670ceb87759c3e0f685093572dfc24e9b8ed509b/markdown-images/README_images/02986e81.png -------------------------------------------------------------------------------- /markdown-images/README_images/4ca71531.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JSREI/page-redirect-code-location-hook/670ceb87759c3e0f685093572dfc24e9b8ed509b/markdown-images/README_images/4ca71531.png -------------------------------------------------------------------------------- /markdown-images/README_images/c2f268cf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JSREI/page-redirect-code-location-hook/670ceb87759c3e0f685093572dfc24e9b8ed509b/markdown-images/README_images/c2f268cf.png -------------------------------------------------------------------------------- /test_case/by-location.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Open DevTool Auto Redirection 6 | 7 | 8 | 9 |

Hello

10 | 11 | 12 | 65 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /test_case/submit-form-by-js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 使用JS提交表单的例子 6 | 7 | 8 | 9 |
10 | 11 |
15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /test_case/submit-form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 提交表单的例子 6 | 7 | 8 | 9 |
10 | 11 |
15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 32 | 33 | 34 | --------------------------------------------------------------------------------