WWW-Mechanize-Chrome
view release on metacpan or search on metacpan
lib/WWW/Mechanize/Chrome.pm view on Meta::CPAN
package WWW::Mechanize::Chrome;
use 5.020;
use experimental 'signatures';
use stable 'postderef';
use feature 'current_sub';
use PerlX::Maybe;
use File::Spec;
use HTTP::Response;
use HTTP::Headers;
use Scalar::Util qw( blessed weaken);
use File::Basename;
use Carp qw(croak carp);
use WWW::Mechanize::Link;
use IO::Socket::INET;
use Chrome::DevToolsProtocol;
use Chrome::DevToolsProtocol::Target;
use WWW::Mechanize::Chrome::Node;
use JSON;
use MIME::Base64 'decode_base64';
use Data::Dumper;
use Storable 'dclone';
use HTML::Selector::XPath 'selector_to_xpath';
use HTTP::Cookies::ChromeDevTools;
use POSIX ':sys_wait_h';
#use Future::IO;
use Future::Utils 'repeat';
use Time::HiRes ();
use Encode 'encode';
use Text::ParseWords 'shellwords';
use File::Temp 'tempdir';
our $VERSION = '0.79';
our @CARP_NOT;
# We don't yet inherit from Moo 2, so patch up things manually
use parent 'MooX::Role::EventEmitter';
# add Browser.setPermission , .grantPermission for
# restricting/allowing recording, clipboard, idleDetection, ...
=encoding utf-8
=head1 NAME
WWW::Mechanize::Chrome - automate the Chrome browser
=head1 SYNOPSIS
use Log::Log4perl qw(:easy);
use WWW::Mechanize::Chrome;
Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR
my $mech = WWW::Mechanize::Chrome->new();
$mech->get('https://google.com');
$mech->eval_in_page('alert("Hello Chrome")');
my $png = $mech->content_as_png();
A collection of other L<Examples|WWW::Mechanize::Chrome::Examples> is available
to help you get started.
=head1 DESCRIPTION
Like L<WWW::Mechanize>, this module automates web browsing with a Perl object.
Fetching and rendering of web pages is delegated to the Chrome (or Chromium)
browser by starting an instance of the browser and controlling it with L<Chrome
DevTools|https://developers.google.com/web/tools/chrome-devtools/>.
=head2 Advantages Over L<WWW::Mechanize>
The Chrome browser provides advanced abilities useful for automating modern
web applications that are not (yet) possible with L<WWW::Mechanize> alone:
=over 4
=item *
Page content can be created or modified with JavaScript. You can also execute
custom JavaScript code on the page content.
=item *
Page content can be selected with CSS selectors.
=item *
Screenshots of the rendered page as an image or PDF file.
=back
=head2 Disadvantages
Installation of a Chrome compatible browser is required. There are some quirks
including sporadic, but harmless, error messages issued by the browser when
run with with DevTools.
=head2 A Brief Operational Overview
C<WWW::Mechanize::Chrome> (WMC) leverages developer tools built into Chrome and
( run in 2.514 seconds using v1.01-cache-2.11-cpan-84e82930d8c )