Prasanth Prasanth - 1 month ago 7
Node.js Question

casperjs empy POST data when large values are submitted

I have a form that is loaded and I just simply submit the form. In the form there is input type=hidden field that has some long string stored in it. This works fine on a regular browser and does not work with casper. On analyzing this with, apache itself is getting empty POST data from casper. If I reduce the data on the hidden input it works fine. Is there a size limit or something defined in casper?

Below is the code:

var casper = require('casper').create();

casper.start('http://localhost/loadForm', function() {
// Wait for the page to be loaded
this.waitForSelector('form[action="/saveConfig"]');
});

casper.then(function() {
this.evaluate(function() {
$('#form').submit();
});
});

casper.run();

Answer

The below bug report is what that helped me. I think this is a phantomjs bug. One of the hidden fields was storing a base64 png image and in my html page it was filled by canvas.toDataURL("image/png"). This in casperjs produces a different base64 compared to actual browers. This resulted in $_POST being empty in php. But when I tried file_get_contents("php://input") the data was all present. I solved it by using canvas.toDataURL("image/png", 0). The second argument produces consistent output in both browers and casperjs.

https://github.com/ariya/phantomjs/issues/10455