Mojo-Phantom

 view release on metacpan or  search on metacpan

lib/Mojo/Phantom.pm  view on Meta::CPAN

has sep     => '--MOJO_PHANTOM_MSG--';
has no_exit => 0;
has note_console => 0;
has 'exe';

has template => <<'TEMPLATE';
  % my ($self, $url, $js) = @_;

  // Setup perl function
  function perl() {
    var system = require('system');
    var args = Array.prototype.slice.call(arguments);
    system.stdout.writeLine(JSON.stringify(args));
    system.stdout.writeLine('<%== $self->sep %>');
    system.stdout.flush();
  }

  // Setup error handling
  var onError = function(msg, trace) {
    var msgStack = ['PHANTOM ERROR: ' + msg];
    if (trace && trace.length) {

lib/Mojo/Phantom.pm  view on Meta::CPAN

  % foreach my $cookie (@{ $self->cookies }) {
    % my $name = $cookie->name;
    phantom.addCookie({
      name: '<%== $name %>',
      value: '<%== $cookie->value %>',
      domain: '<%== $cookie->domain || $self->base->host %>',
    }) || perl.diag('Failed to import cookie <%== $name %>');
  % }

  // Requst page and inject user-provided javascript
  var page = require('webpage').create();
  page.onError = onError;

  % if($self->note_console) {

    // redirect browser console log to TAP
    page.onConsoleMessage = function(msg) {
      perl.note('js console: ' + msg);
    };

    // redirect console log to TAP



( run in 0.414 second using v1.01-cache-2.11-cpan-0d8aa00de5b )