Follow meta-refresh redirect
I was using screenshot-stream and found that it is not able to follow http-equivs refresh URL.
This "issue" can be delegated to phantom itself, but I though that it easier and more appropiate to fix it here.
My changes in short does this:
- on page load, detect all meta http-equivs=refresh tags
- for each meta, parse the content
- use the earliest meta refresh (heuristics here :) )
- if anything is found, prevent render and do a location replace;
- after redirect if an loop is found, exit with error.
Note that I'm a newbie of phantom and not a javascript ninja, so here the thing that I think can be improved:
- use library https://www.npmjs.com/package/http-equiv-refresh instead of almost copy-pasted code (I tried, but got error on library "require", probably because of node version mismatch);
- export options for
redirCountandmetaRefreshThreshold; - re-enable
window.location.reload()if it make sense.
Digging deeper. I tested with other URLs and seems that when http-equivs have 0 seconds refresh, the request is triggered by phanthom but after the onLoadFinished (this seems obvious, now that I know it :) ).
I changed the code accordingly (and as a consequence, window.location.reload is triggered when needed)
I see that travis is complaining about my code style. I will fix everything after your feedback.