I am doing usercript for the Chrome TamperMonkey extension (this is the same as doing usercript for GreaseMonkey).
In my script, I repeat some external document resources (img, css, links, scripts) through document.getElementsByTagName() , and I change their src or href attributes to a different URL.
In most cases, the new URL loads properly, but in some cases it ends with a 404 or 403 error from my proxy.
Could you give me some guidance on how to handle (if possible) correctly, "the resource cannot be loaded with the new URL"? In addition, in the case where the requested resource leads to a redirected URL, can I be informed that the resource has been redirected (how to check 302)?
I am using bare javascript, without jquery. But if jQuery can help me, I am ready to accept it.
I considered testing the headers from the XMLHttpRequest result for each resource URL, but it seems to me that I'm using an artillery gun to kill a fly. I would prefer to use the correct handler, which can only be run in case of an unavailable resource.
Edit : as an alternative, I would be fine if chrome had a status property for every loaded object that I could check ...
source share