admin管理员组

文章数量:1379611

I'm observing a series of redirects in chrome dev tools, "Networking" tab:

I need to be able to pause redirect chain after a request has appeared in the "Networking" (so that I can copy it as cURL) but before it is executed. Something like "Pause on any network activity". I have searched for this feature in Chrome dev tools, Firefox Web Developer, Firebug, Safari - but to no avail. The closest thing is "Pause on XHR" in firebug, but these redirects are not XHRs.

I will accept a non-browser solution (a script?) if it does the job, although I feel that this should be possible with browser dev tools.

I'm observing a series of redirects in chrome dev tools, "Networking" tab:

I need to be able to pause redirect chain after a request has appeared in the "Networking" (so that I can copy it as cURL) but before it is executed. Something like "Pause on any network activity". I have searched for this feature in Chrome dev tools, Firefox Web Developer, Firebug, Safari - but to no avail. The closest thing is "Pause on XHR" in firebug, but these redirects are not XHRs.

I will accept a non-browser solution (a script?) if it does the job, although I feel that this should be possible with browser dev tools.

Share Improve this question asked Oct 30, 2015 at 17:11 Denys Kniazhev-Support UkraineDenys Kniazhev-Support Ukraine 9,1228 gold badges48 silver badges64 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

I wasn't able to find a browser solution. As you're ok with non-browser solution, there is a python script (it also uses requests library) that follows redirects, until some suffix is found and prints request for the cURL.

#!/usr/bin/env python

import requests 
import sys

def formatRequestAscURL(request):
    mand = "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 mand.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)

Adding this because this was the first search result for me.

In firefox you can add a XHR request as explained here: https://firefox-source-docs.mozilla/devtools-user/debugger/set_an_xhr_breakpoint/index.html

本文标签: javascriptStop on a network request in browser dev toolsStack Overflow