I am trying to use WWW::Mechanize::Chrome to fill in fields in the currently active tab in Chrome. The general goal is to automate some of the typing involved in making bank transfers so opening a new session and navigation to pages are no-go.
This is where I am at - to test a minimal level of control on the current tab:
use Log::Log4perl qw(:easy);
use WWW::Mechanize::Chrome;
Log::Log4perl->easy_init($ERROR);
my $mech = WWW::Mechanize::Chrome->new(
launch_exe => '/usr/bin/google-chrome',
launch_arg => [ "--remote-debugging-port=9223" ],
autoclose => 0,
port => 9223,
tab => 'current',
);
$mech->get('https://www.reddit.com/r/perl');
$mech->eval_in_page('alert("Hello Chrome")');
my $png = $mech->content_as_png();
with Chrome started like this:
/usr/bin/google-chrome --remote-debugging-port=9223
However what this actually does (on the browser side) is:
- open a new tab
- no navigation to reddit
- no alert
and on the command line it outputs this:
Can't connect without knowing the port?! 0 at ~/perl5/perlbrew/perls/perl-5.30.2/lib/site_perl/5.30.2/Chrome/DevToolsProtocol.pm line 317.
If Chromium is not running, the code works well (opens Chromium, navigates to reddit, alerts).
The docs say "Setting tab to current
will use the current, active tab instead - but it does not seem to work.
What is it that I'm doing wrong?