screenshot-stream icon indicating copy to clipboard operation
screenshot-stream copied to clipboard

Follow meta-refresh redirect

Open giosh94mhz opened this issue 8 years ago • 1 comments

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:

  1. on page load, detect all meta http-equivs=refresh tags
  2. for each meta, parse the content
  3. use the earliest meta refresh (heuristics here :) )
  4. if anything is found, prevent render and do a location replace;
  5. 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 redirCount and metaRefreshThreshold;
  • re-enable window.location.reload() if it make sense.

giosh94mhz avatar Jul 31 '17 07:07 giosh94mhz

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.

giosh94mhz avatar Jul 31 '17 15:07 giosh94mhz