I’m looking for a way to detect/record 404’s or redirects after visiting a link - is that possible?
1 Like
Can you describe the task in more details? So you want to get an error if the link is broken?
Yea, so I want the script to read a csv of links, visit each one, and record via !csvLine if the link is 404’ed or redirected (and to what new website if redirected). Does that make sense?
{
"Name": "XXXXX",
"CreationDate": "2022-12-14",
"Commands": [
{
"Command": "csvReadArray",
"Target": "test",
"Value": "CSV",
"Description": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "return ${CSV}.length",
"Value": "LEN_ARR",
"Description": ""
},
{
"Command": "times",
"Target": "${LEN_ARR}",
"Value": "",
"Description": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "var index = ${!times} - 1\n\nreturn ${CSV}[index]",
"Value": "item",
"Description": ""
},
{
"Command": "executeScript",
"Target": "async function status(url){\n var res = await fetch(url)\n var status = res.status\n \n if(res.redirected){\n return \"Redirect to \" + res.url\n }\n \n if(status === 404){\n return \"Not Found\"\n }\n \n if(status === 200){\n return \"OK\"\n }\n \n return status\n}\n\nreturn status(${item})",
"Value": "status",
"Description": ""
},
{
"Command": "echo",
"Target": "${item} status: ${status}",
"Value": "green",
"Description": ""
},
{
"Command": "end",
"Target": "",
"Value": "",
"Description": ""
}
]
}
1 Like
Thank you! I copied your script and your CSV file, but when I run it the console says
* [error]
[Line 5](chrome-extension://gcbalfbdmfieckjlnblleoemohcganoc/popup.html#): Error in executeScript code: Failed to fetch
Do you know what might be causing this problem? Thanks again!
CORS error you need install this extension https://chrome.google.com/webstore/detail/cors-unblock/lfhmikememgdcahcdlaciloancbhjino?hl=en
1 Like