Chrome:...rotocol(3)
β¨ NAME β¨
okay so Chrome::DevToolsProtocol is an asynchronous dispatcher for the DevTools protocol. that's it, that's the vibe. no cap. π
π¦ SYNOPSIS π¦
# Usually, WWW::Mechanize::Chrome automatically creates a driver for you
my $driver = Chrome::DevToolsProtocol->new(
port => 9222,
host => '127.0.0.1',
auto_close => 0,
error_handler => sub {
# Reraise the error
croak $_[1]
},
);
$driver->connect( new_tab => 1 )->get
like. look at her. she's doing everything. πΈ
π METHODS π
π« ->new( %args ) π«
my $driver = Chrome::DevToolsProtocol->new(
port => 9222,
host => '127.0.0.1',
auto_close => 0,
error_handler => sub {
# Reraise the error
croak $_[1]
},
);
most of these lil members can be set through the constructor arguments, bestie:
hostβ the hostname to connect to π«Άportβ the port to connect tojsonβ the JSON decoder useduaβ theFuture::HTTPinstance to talk to the Chrome DevToolstabβ which tab to reuse (if any)logβ a premadeLog::Log4perlobject to act as loggertransportβ the event-loop specific transport backend
π« ->future π«
my $f = $driver->future();
returns a backend-specific generic future β¨
π« ->endpoint π«
my $url = $driver->endpoint();
returns the URL endpoint to talk to for the connected tab π
π« json_log_fh π«
the filehandle where all communications get logged to, one line per message/response. every line is gonna look like this:
{ type: "message", payload: { ... } }
{ type: "reply", payload: { ... } }
{ type: "event", payload: { ... } }
π¨ the filehandle must be opened as :raw, because UTF-8 encoded bytes are getting written to it. no exceptions bestie.
π« ->add_listener π«
my $l = $driver->add_listener(
'Page.domContentEventFired',
sub {
warn "The DOMContent event was fired";
},
);
# ...
undef $l; # stop listening
adds a callback for the given event name. and the way that the callback gets removed the moment the return value goes out of scope?? iconic behaviour fr fr. β¨
π« ->remove_listener π«
$driver->remove_listener($l);
explicitly remove a listener. sometimes you just gotta say bye π
π« ->log π«
$driver->log('debug', "Warbling doodads", { doodad => 'this' } );
log a message π
π« ->connect π«
my $f = $driver->connect()->get;
asynchronously connect to the Chrome browser, returning a Future. slay.
π« ->close π«
$driver->close();
shut down the connection to Chrome π
π« ->sleep π«
$driver->sleep(0.2)->get;
sleep for the amount of seconds in an event-loop compatible way. beauty sleep but make it async π΄
π« ->one_shot π«
my $f = $driver->one_shot('Page.domContentEventFired')->get;
returns a future that resolves when the event is received β
π« $chrome->json_get π«
my $data = $driver->json_get( 'version' )->get;
requests an URL and returns decoded JSON from the future πΈ
π« $chrome->send_packet π«
$chrome->send_packet('Page.handleJavaScriptDialog',
accept => JSON::true,
);
sends a JSON packet to the remote end π¨
π« $chrome->send_message π«
my $future = $chrome->send_message('DOM.querySelectorAll',
selector => 'p',
nodeId => $node,
);
my $nodes = $future->get;
this function expects a response. the future will not be resolved until Chrome has sent a response to this query. like she's waiting. patiently. π
π« $chrome->callFunctionOn π«
π« $chrome->evaluate π«
π« $chrome->eval π«
my $result = $chrome->eval('2+2');
evaluates a Javascript string and returns the result. yes she does math π
π« $chrome->version_info π«
print $chrome->version_info->get->{"Protocol-Version"};
returns the implemented ChromeDevTooslProtocol protocol version. (that spelling is the original's, don't come for me π«Ά)
π« $chrome->protocol_version π«
print $chrome->protocol_version->get;
π« $target->getVersion π«
returns information about the Chrome instance we are connected to. get to know her π
π« $chrome->get_domains π«
my $schema = $chrome->get_domains->get;
returns the topics of this Chrome DevToolsProtocol implementation π
π« $chrome->list_tabs π«
my @tabs = $chrome->list_tabs->get();
π« $chrome->new_tab π«
my $new_tab = $chrome->new_tab('https://www.google.com')->get;
π« $chrome->activate_tab π«
$chrome->activate_tab( $tab )->get
brings the tab to the foreground of the application. main character energy, literally. β¨
π« $chrome->close_tab π«
$chrome->close_tab( $tab )->get
closes the tab π
π« $chrome->getTargets π«
my @targets = $chrome->getTargets->get;
gets the list of available targets π―
π« $target->getTargetInfo π«
my $info = $chrome->getTargetInfo( $targetId )->get;
print $info->{title};
returns information about the current target πΈ
π« $target->createTarget π«
my $targetId = $chrome->createTarget(
url => 'about:blank',
width => 1280,
height => 800,
newWindow => JSON::false,
background => JSON::false,
)->get;
print $targetId;
creates a new target, optionally in a new window πͺ
π« $target->attachToTarget π«
my $sessionId = $chrome->attachToTarget(
targetId => $targetId,
)->get;
print $sessionId;
attaches to the target so we receive events generated by the target π
π« $target->closeTarget π«
my $targetId = $chrome->closeTarget(
targetId => $targetId
)->get;
creates a new target π (yes bestie, that's literally what the page says for closeTarget. I'm just the messenger. copy/paste energy, we don't gatekeep.)
π« $target->getWindowForTarget π«
my $info = $chrome->getWindowForTarget( $targetId )->get;
print $info->{windowId};
returns information about the window of the current target πͺβ¨
π« $target->setWindowBoundsForTarget π«
my $info = $chrome->getWindowForTarget( $targetId )->get;
$info->{bounds}->{width} = 100;
$chrome->setWindowBounds( $info->{windowId}, $info->{bounds} )->get;
sets the window dimensions of the current target π
π« $chrome->getBrowserContexts π«
my @browserContextIds = $chrome->getBrowserContexts->get;
gets the list of available browser contexts. these are separate sets of user cookies etc. so like, different personalities, different cookie jars πͺ
π SEE ALSO π
- the unofficial Chrome debugger API documentation at
<https://github.com/buggerjs/bugger-daemon/blob/master/README.md#api> - Chrome DevTools at
<https://chromedevtools.github.io/devtools-protocol/1-2>
π§ REPOSITORY π§
the public repository of this module is <https://github.com/Corion/www-mechanize-chrome>. go star her, she deserves it β
π«Ά SUPPORT π«Ά
the public support forum of this module is <https://perlmonks.org/>.
π BUG TRACKER π
please report bugs in this module via the Github bug queue at <https://github.com/Corion/WWW-Mechanize-Chrome/issues>. tell them everything, no secrets π
π AUTHOR π
Max Maischein corion@cpan.org
π COPYRIGHT (c) π
Copyright 2010-2026 by Max Maischein corion@cpan.org.
π LICENSE π
this module is released under the same terms as Perl itself. periodt. π
and that's the whole page bestie β¨ this was perl v5.42.2, dated 2026-06-07, for Chrome:...rotocol(3) β go forth and dispatch asynchronously, ily π«Άπ
π¦ where this page comes from
- fedora 43: perl-WWW-Mechanize-Chrome 0.78-1.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- fedora 44: perl-WWW-Mechanize-Chrome 0.78-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms