Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow meta-refresh redirect #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

giosh94mhz
Copy link

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant