Pcore-WebDriver
view release on metacpan or search on metacpan
lib/Pcore/WebDriver/Session.pm view on Meta::CPAN
}
# unlink chrome scoped_dir
P->file->rmtree( $self->{_chrome_scoped_dir} ) if $self->{_chrome_scoped_dir};
return;
}
# https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
#
# https://sites.google.com/a/chromium.org/chromedriver/capabilities
#
# http://phantomjs.org/api/webpage/property/settings.html
# https://github.com/detro/ghostdriver
# phantomjs.page.customHeaders.HEADER = VALUE - Add extra HTTP Headers when loading a URL (see reference)
# phantomjs.page.whitelist - an array of regex expressions of urls to accept. eg. ['my-awesome-website.com']
# phantomjs.page.blacklist - array of regex expressions of urls to ignore. The blacklist overrides the whitelist. eg. ['google.com', 'github.com']
# unhandledPromptBehavior - set to dismiss to automatically dismiss all user prompts or set to accept to automatically accept all user prompts
# loggingPrefs - ghostdriver has two logs browser and har. The logs default to "OFF". follow the DesiredCapabilities documentation to enable the logs.
sub _get_desired_caps ( $self, $args ) {
# common options
my $caps = {
# javascriptEnabled => $self->{disable_javascript} ? \0 : \1,
# acceptSslCerts => \1,
# takesScreenshot => \1,
# handlesAlerts => \1,
};
my $useragent = !exists $args->{useragent} ? $DEFAULT_USERAGENT : $args->{useragent};
# chrome options
if ( $self->{wdh}->{is_chrome} ) {
$caps->{chromeOptions} = {
args => [ #
# https://bugs.chromium.org/p/chromium/issues/detail?id=721739
# NOTE headless chrome ignoring --ignore-certificate-errors
$args->{proxy} ? ( "--proxy-server=$args->{proxy}", '--ignore-certificate-errors', '--allow-insecure-localhost' ) : (),
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=878
# NOTE remote debuggind not works with chromedriver
# '--remote-debugging-address=192.168.175.10',
# '--remote-debugging-port=9222',
'--disable-background-networking',
'--disable-client-side-phishing-detection',
'--disable-component-update',
'--disable-hang-monitor',
'--disable-prompt-on-repost',
'--disable-sync',
'--disable-web-resources',
'--start-maximized',
'--window-size=1280x720',
'--disable-default-apps',
'--no-first-run',
'--disable-infobars',
'--disable-popup-blocking',
'--disable-default-apps',
'--disable-web-security',
'--allow-running-insecure-content',
# logging
# '--disable-logging',
# '--log-level=0',
# set user profile dir
qq[--user-data-dir=$ENV->{TEMP_DIR}chrome-wds-@{[P->uuid->str]}],
# required for run under docker
'--no-sandbox',
# user agent
defined $useragent ? qq[--user-agent=$useragent] : (),
# headless mode
( $args->{headless} || !$MSWIN ) && !$self->{wdh}->{xvfb} ? ( '--headless', '--disable-gpu' ) : (),
# user args
$args->{args} ? $args->{args}->@* : (),
# open "about:blank" by default
'about:blank',
],
binary => $args->{bin} // q[],
prefs => {
# ( $self->disable_images ? ( 'profile.default_content_setting_values.images' => 2 ) : () ),
# ( $self->enable_notifications ? () : ( 'profile.default_content_setting_values.notifications' => 2 ) ),
# ( $self->enable_flash ? () : ( 'profile.default_content_setting_values.plugins' => 2 ) ),
}
};
}
# phantomjs options
elsif ( $self->{wdh}->{is_phantomjs} ) {
if ( $args->{proxy} ) {
$caps->{proxy} = {
proxyType => 'manual',
httpProxy => $args->{proxy},
sslProxy => $args->{proxy},
};
}
$caps->{'phantomjs.page.settings.userAgent'} = $useragent if defined $useragent;
}
return { desiredCapabilities => $caps };
}
around new => sub ( $orig, $self, @args ) {
my $cb = is_plain_coderef $args[-1] ? pop @args : undef;
P->http->request(
method => 'POST',
url => "http://$self->{wdh}->{host}:$self->{wdh}->{port}/session",
timeout => 0,
body => to_json( $self->_get_desired_caps( {@args} ) ),
( run in 0.913 second using v1.01-cache-2.11-cpan-364913b4093 )