Chrome:...rotocol(3)

πŸ“¦
version 0.78 Β· 3 versions
, in fedora 43, fedora 44

✨ 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 to
  • json β€” the JSON decoder used
  • ua β€” the Future::HTTP instance to talk to the Chrome DevTools
  • tab β€” which tab to reuse (if any)
  • log β€” a premade Log::Log4perl object to act as logger
  • transport β€” 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 🌈


🧚 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 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