I'm using node.js request library which can follow HTTP redirects but is there a way to follow Javascript redirect such as this?
<html>
<head>
<meta http-equiv="refresh" content="0; /subpage"/>
<script type="text/javascript">
window.location.href = '/subpage/';
</script>
</head>
<body></body>
</html>
window.location.href
Using window.location.href
is not the only way to do a javascript redirect, so the hack you suggest would not work in every case.
Also, if the new url is a variable (eg: window.location.url = some_variable
) you will not catch it.
The most elegant way to be sure to follow any javascript redirect is to use a webdriver such as Selenium.
The advantage of this solution is that it will follow any html/javascript redirect. The disadvantage is it requires setup, and the execution of the webdriver can be slow.