javascriptgoogle-chromefirefoxsafarifirebug

Stop on a network request in browser dev tools


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

enter image description here

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.


Solution

  • 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):
        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)