简体   繁体   中英

Is it possible to get all the urls in a chain of redirects for a given link on the client-side using JavaScript?

I am currently working on a JavaScript chrome extension and would like to be able to send all the redirects for a given link that matches a certain criteria. I would like to do this client side invisibly and send the data back to an endpoint. There are several ways to do this in other server-side languages (I would like to basically have the functionality of the following python script)

import requests
response = requests.get(domain)
redirects = list()
for r in response.history:
    redirects.append(r.url)

Is there anyway to extract this sort of information invisibly on the client-side, preferably using JavaScript/some JS library?

Thanks in advance for your time!

This is not possible from the client side using JavaScript. You can send a HTTP request to a certain URL using XMLHttpRequest , but it will automatically follow redirects down to the final destination. There is not way to retrieve the redirection history. Also, browsers prevent sending requests to different origins as per the Same-origin policy .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM