How can I programmatically access Chrome's Console to do something with 404 responses?
My ultimate goal is to provide a working copy of an existing website.
I have used httrack
which is pretty good, however it's not smart enough to detect deeply nested dependent resources, eg resources that are dynamic and come from js/flash, etc.
I want to basically write a script that looks for all 404 responses in the Console
tab in Chrome and with the URI, download the files from an external website locally.
For instance, let's say I get this:
404 http://site.localhost/media/images/blah.png 404 http://site.localhost/media/xml/file.xml
I would want my script to loop through all 404s, and detect if the HOST is 'site.localhost', then run a bash command that WGETs the resource from http://actualsite.com/media/images/blah.png.
If anyone can provide insight into how I can programmatically access this po开发者_运维百科rtion of the Console, and how I can run bash commands with that then I'm set.
I don't know a way of dumping Console content just with regular javascript on a page (and would be very surprised if there is one).
You can write an extension that monitors all resources on a page and logs if it is 404. Downloading them using javascript is out of question of course.
To log bad requests you would need to use an experimental API, something like this:
background.html:
chrome.experimental.webRequest.onCompleted.addListener(function(details) {
if(details.statusCode == 404) {
console.log("Broken resource:", details.url);
}
}, null, ["statusLine", "responseHeaders"]);
精彩评论