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

add target url as parameter to beforeCaptureJS #464

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

Conversation

Dahie
Copy link

@Dahie Dahie commented Sep 8, 2016

Hi,

If the website to be captured requires login, often it would redirect to a login-page. This redirect would change the value page.url available in the beforeCaptureJS function. The login could be handled through phantomjs or casperjs, but there is no way to get the original target url.
So this change adds the target url as parameter and makes it available in the beforeCaptureJS. It's added as a new parameter at the end so it preserves backwards-compatibility with existing configurations.

regards,
Daniel

If the website to be captured requires login, often it would redirect to a login-page. This redirect would change the value page.url available in the beforeCaptureJS function. The login could be handled through phantomjs or casperjs, but there is no way to get the original target url.
So this change adds the target url as parameter and makes it available in the beforeCaptureJS. It's added as a new parameter at the end so it preserveres backwards-compatibility.
@ChrisBAshton
Copy link
Contributor

Thanks for the PR @Dahie - but it is already possible to do this with Wraith, see instructions here:

#446 (comment)

You would apply something along the lines of:

module.exports = function (casper, ready) {
    var CURRENT_URL = casper.page.url;

    casper.open('/login.php');
    casper.evaluate(function () {
        // write your JS which fills in your login form and submits it here   
    });

    // at this point we're now at /dashboard - so need to redirect ourselves to the
    // page we wanted to test in the first place, e.g. /settings
    casper.thenOpen(CURRENT_URL);

    ready();
});

@Dahie
Copy link
Author

Dahie commented Sep 8, 2016

We did not get casperjs to work, but that's a different topic. With phantomjs, this is what happens for us:

In wraith /lib/javascripts/phantom.js:58 it opens the target url a first time. This target URL requires login, so it redirects to our login page and the callback function within this call already has page.url != url as page.url now contains the url of the login and not the target.
Now in the before-capture.js outside of wraith in our configuration, the phantom/page object already contains the wrong login-url and not the expected target-url.
Please enlighten me, how to handle this without changing the gem, if I can avoid that I'm all for it. :)

Thanks for taking the time.

@ChrisBAshton
Copy link
Contributor

Ahhh, I didn't realise you had a server-side redirect before the page loads. I don't think Wraith can handle that yet.

We will definitely consider merging this PR! Probably ought to write a guide in the GitHub Pages docs too, as login-only pages seem to be a fairly common requirement.

@Dahie
Copy link
Author

Dahie commented Sep 8, 2016

Yeah, we have server-side redirects. Thanks for considering! :)

@Dahie
Copy link
Author

Dahie commented Nov 2, 2016

Hi, any news on your considerations? We'd like to see this in wraith and mothball our forked. :)

@KaiHotz
Copy link

KaiHotz commented Jan 24, 2017

@ChrisBAshton Those are nice changes that Dahie proposes, when could we see this integated ?

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.

3 participants