Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
casperjs loadImage breaks session cookies
/**
* Login into website.
*/
exports.login = function(url,username,password) {
/**
* Start casper and option the login page.
*/
casper.open(url);
/**
* Wait for login form to appear.
*/
casper.waitForSelector('form#loginForm',
function() {
casper.log('Login form found.', 'info');
},
function(){
casper.log('Login form not found.', 'error');
},
15000
);
/**
* Fill in the login form.
*/
casper.then(function() {
casper.fillSelectors('form#loginForm', {
'input[name=username]': username,
'input[name=password]': password
}, false);
casper.log('Set username and password in login form.', 'info');
}
);
/**
* Click the submit button after the form has been filled in.
*/
casper.thenClick('input#submit');
/**
* We should now be logged in and now you can perform other tasks.
*/
casper.then(function(){
// presume all good
});
}

Running Windows 7 x64

casperjs --version

1.1.0-beta3 Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///C:/Users/James/AppData/Roaming/npm/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.

phantomjs --version 1.9.8

###The test.js script failes with pageSettings.loadImages set to true.

# casperjs --cookies-file=output/cookies.txt --ignore-ssl-errors=yes --verbose --log-level=debug bug-report.js

>[info] [phantom] Starting...
[debug] [phantom] opening url: https://address:port/admin, HTTP GET
[debug] [phantom] Navigation requested: url=https://address:port/admin, type=Other, willNavigate=true, isMainFrame=true
[info] [phantom] Running suite: 5 steps
[debug] [phantom] Navigation requested: url=https://address:port/admin/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://address:port/login, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://address:port/login"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step _step 1/5 https://address:port/login (HTTP 200)
[info] [phantom] Step _step 1/5: done in 1032ms.
[info] [phantom] waitFor() finished in 40ms.
[info] [phantom] Step anonymous 2/6 https://address:port/login (HTTP 200)
[info] [phantom] Login form found.
[info] [phantom] Step anonymous 2/6: done in 1090ms.
[info] [phantom] Step anonymous 3/6 https://address:port/login (HTTP 200)
[info] [remote] attempting to fetch form element from selector: 'form#loginForm'
[debug] [remote] Set "username" field value to testuser
[debug] [remote] Set "password" field value to ******************************
[info] [phantom] Set username and password in login form.
[info] [phantom] Step anonymous 3/6: done in 1139ms.
[info] [phantom] Step _step 4/6 https://address:port/login (HTTP 200)
[debug] [phantom] Mouse event 'mousedown' on selector: input#submit
[debug] [phantom] Mouse event 'mouseup' on selector: input#submit
[debug] [phantom] Mouse event 'click' on selector: input#submit
[info] [phantom] Step _step 4/6: done in 1167ms.
[info] [phantom] Step anonymous 5/6 https://address:port/login (HTTP 200)
[info] [phantom] Step anonymous 5/6: done in 1177ms.
[debug] [phantom] Navigation requested: url=https://address:port/login, type=FormSubmitted, willNavigate=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://address:port/error/csrfForbidden, type=FormSubmitted, willNavigate=true, isMainFrame=true
Resource https://address:port/error/csrfForbidden failed to load (403)
[debug] [phantom] url changed to "https://address:port/error/csrfForbidden"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step _step 6/6 https://address:port/error/csrfForbidden (HTTP 403)
[info] [phantom] Step _step 6/6: done in 1433ms.
[warning] [phantom] Casper.waitFor() timeout
[error] [phantom] Wait timeout of 5000ms expired, exiting.
Wait timeout of 5000ms expired, exiting.
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///C:/Users/James/AppData/Roaming/npm/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///C:/Users/James/AppData/Roaming/npm/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///C:/Users/James/AppData/Roaming/npm/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.

###The test.js script works with pageSettings.loadImages set to false.

>[info] [phantom] Starting...
[debug] [phantom] opening url: https://address:port/admin, HTTP GET
[debug] [phantom] Navigation requested: url=https://address:port/admin, type=Other, willNavigate=true, isMainFrame=true
[info] [phantom] Running suite: 5 steps
[debug] [phantom] Navigation requested: url=https://address:port/admin/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://address:port/login, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://address:port/login"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step _step 1/5 https://address:port/login (HTTP 200)
[info] [phantom] Step _step 1/5: done in 786ms.
[info] [phantom] waitFor() finished in 40ms.
[info] [phantom] Step anonymous 2/6 https://address:port/login (HTTP 200)
[info] [phantom] Login form found.
[info] [phantom] Step anonymous 2/6: done in 854ms.
[info] [phantom] Step anonymous 3/6 https://address:port/login (HTTP 200)
[info] [remote] attempting to fetch form element from selector: 'form#loginForm'
[debug] [remote] Set "username" field value to testuser
[debug] [remote] Set "password" field value to ******************************
[info] [phantom] Set username and password in login form.
[info] [phantom] Step anonymous 3/6: done in 905ms.
[info] [phantom] Step _step 4/6 https://address:port/login (HTTP 200)
[debug] [phantom] Mouse event 'mousedown' on selector: input#submit
[debug] [phantom] Mouse event 'mouseup' on selector: input#submit
[debug] [phantom] Mouse event 'click' on selector: input#submit
[info] [phantom] Step _step 4/6: done in 938ms.
[info] [phantom] Step anonymous 5/6 https://address:port/login (HTTP 200)
[info] [phantom] Step anonymous 5/6: done in 950ms.
[debug] [phantom] Navigation requested: url=https://address:port/login, type=FormSubmitted, willNavigate=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://address:port/admin/, type=FormSubmitted, willNavigate=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://address:port/survey/list, type=FormSubmitted, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://address:port/survey/list"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step _step 6/6 https://address:port/survey/list (HTTP 200)
[info] [phantom] Step _step 6/6: done in 2526ms.
[info] [phantom] waitFor() finished in 41ms.
[info] [phantom] Done 6 steps in 2578ms
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///C:/Users/James/AppData/Roaming/npm/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///C:/Users/James/AppData/Roaming/npm/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///C:/Users/James/AppData/Roaming/npm/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.
var casper = require('casper').create({
pageSettings: {
loadImages: true
}
});
var loginModule = require('lib-login.js');
var errors = [];
var resourceErrors = [];
var baseUrl = 'https://address:port';
var loginUrl= baseUrl + '/login';
var username='user';
var password='password';
casper.on('remote.message', function(msg) {
this.echo('remote message caught: ' + msg);
});
casper.on('error', function(msg,trace) {
this.echo("ERROR:" + msg + trace);
});
casper.on("page.error", function(msg, trace) {
this.echo("URL: " + this.getCurrentUrl(), "error");
this.echo("Error: " + msg, "error");
this.echo("file: " + trace[0].file, "warning");
this.echo("line: " + trace[0].line, "warning");
this.echo("function: " + trace[0]["function"], "warning");
errors.push(msg);
});
casper.on('page.resource.received', function(resource) {
var status = resource.status;
if(status >= 400) {
this.echo('Resource ' + resource.url + ' failed to load (' + status + ')', 'error');
resourceErrors.push({
url: resource.url,
status: resource.status
});
}
});
/**
* Start casper.
*/
casper.start();
/**
* Login to website.
*/
loginModule.login(loginUrl,username,password);
/**
* After login user gets redirected to main page.
*/
casper.waitForSelector('#content');
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.