在浏览器开发工具中停止网络请求

问题描述 投票:0回答:2

我正在 chrome 开发工具的“网络”选项卡中观察到一系列重定向:

enter image description here

我需要能够在请求出现在“网络”中之后(以便我可以将其复制为 cURL)但在执行之前暂停重定向链。类似“暂停任何网络活动”之类的内容。我在 Chrome 开发工具、Firefox Web Developer、Firebug、Safari 中搜索过此功能 - 但没有结果。最接近的是 firebug 中的“Pause on XHR”,但这些重定向不是 XHR。

如果非浏览器解决方案(脚本?)能完成工作,我会接受它,尽管我觉得这应该可以通过浏览器开发工具实现。

javascript google-chrome firefox safari firebug
2个回答
1
投票

我无法找到浏览器解决方案。由于您可以使用非浏览器解决方案,所以有一个 python 脚本(它也使用

requests
库)遵循重定向,直到找到某个后缀并打印 cURL 的请求。

#!/usr/bin/env python

import requests 
import sys

def formatRequestAscURL(request):
    command = "curl -X {method} -H {headers} -d '{data}' '{url}'"
    method = request.method
    url = request.url
    data = request.body
    headers = ["{0}: {1}".format(k, v) for k, v in request.headers.items()]
    headers = " -H ".join(headers)
    return command.format(method=method, headers=headers, data=data, url=url)


def followUntilSuffix(startURL, suffix):
    response = requests.get(startURL, allow_redirects=False)
    session = requests.Session()
    requests_iter = session.resolve_redirects(response, response.request)

    for r in requests_iter:
        if r.request.path_url.endswith(suffix):
             print formatRequestAscURL(r.request)
             return

    print 'Required redirect isn\'t found'


if len(sys.argv) < 3:
    print 'This script requires two parameters:\n 1) start url \n 2) url suffix for stop criteria'
    sys.exit()

startURL = sys.argv[1]
stopSuffix = sys.argv[2]

followUntilSuffix(startURL, stopSuffix)

0
投票

添加此内容是因为这是我的第一个搜索结果。

在 Firefox 中,您可以添加 XHR 请求,如下所述: https://firefox-source-docs.mozilla.org/devtools-user/debugger/set_an_xhr_breakpoint/index.html

© www.soinside.com 2019 - 2024. All rights reserved.