Chrome:...:Target(3)
π NAME π
Chrome::DevToolsProtocol::Target β bestie, it's a wrapper for talking to a page in a Target. That's the whole job. It's the little liaison that holds the conversation with one Chrome tab so you don't have to rawdog the protocol yourself. π¦
Quick housekeeping so you know where you are: this page comes from the User Contributed Perl Documentation manual, and you got here by pulling up Chrome:...:Target(3). Iconic.
β¨ SYNOPSIS β¨
# Usually, WWW::Mechanize::Chrome automatically creates a driver for you
my $driver = Chrome::DevToolsProtocol::Target->new(
transport => $target,
);
$driver->connect( new_tab => 1 )->get
πΈ METHODS πΈ
->new( %args )
my $driver = Chrome::DevToolsProtocol::Target->new(
transport => $target,
auto_close => 0,
error_handler => sub {
# Reraise the error
croak $_[1]
},
);
Okay so these members can mostly be set through the constructor arguments, and here's the lineup:
jsonβ the JSON decoder it's gonna use πtabβ which tab to reuse, if anyautocloseβ close the tab when the object goes out of scope (bye bestie π)logβ a premadeLog::Log4perlobject to act as loggerappβ if you're launching Chrome in app mode, connect to this page
π EVENTS π
messageβ a callback that gets invoked for every single message. every. one.transportβ the event-loop specific transport backend
->future
my $f = $driver->future();
Returns a backend-specific generic future. Lowkey the building block of everything here.
->endpoint
my $url = $driver->endpoint();
Returns the URL endpoint to talk to for the connected tab. That's your address, 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 here's the cute part β the callback gets removed once the return value goes out of scope. So hold onto that $l or the whole thing just β¨evaporatesβ¨.
->remove_listener
$driver->remove_listener($l);
Explicitly remove a listener. For when you're done and you're not waiting around for scope magic.
->log
$driver->log('debug', "Warbling doodads", { doodad => 'this' } );
Log a message. Go off, warbling doodads. π₯
->connect
my $f = $driver->connect()->get;
Asynchronously connect to the Chrome browser, returning a Future. Not blocking, no waiting around, we love her for that.
->close
$driver->close();
Shut down the connection to our tab and close it. It's over, it's done, no notes.
->sleep
$driver->sleep(0.2)->get;
Sleep for the amount of seconds β in an event-loop compatible way. A nap that doesn't ruin the whole vibe. π΄
->one_shot
my $f = $driver->one_shot('Page.domContentEventFired')->get;
Returns a future that resolves when the event is received. One event, one shot, one future.
$chrome->json_get
my $data = $driver->json_get( 'version' )->get;
Requests an URL and returns decoded JSON from the future. π
$chrome->version_info
print $chrome->version_info->get->{"protocolVersion"};
$chrome->protocol_version
print $chrome->protocol_version->get;
$chrome->send_packet
$chrome->send_packet('Page.handleJavaScriptDialog',
accept => JSON::true,
);
Sends a JSON packet to the remote end. Fire and forget energy.
$chrome->send_message
my $future = $chrome->send_message('DOM.querySelectorAll',
selector => 'p',
nodeId => $node,
);
my $nodes = $future->get;
This function expects a response. So the future will not be resolved until Chrome has sent a response to this query. Not a one-way text, it's a full convo. ππ·
$chrome->callFunctionOn
$chrome->evaluate
$chrome->eval
$chrome->get_domains
$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.
$target->getTargetInfo
Returns information about the current target. π§
$target->info
Returns information about the current target.
$target->title
Returns the title of the current target.
$target->getVersion
Returns information about the Chrome instance we are connected to.
$target->createTarget
my $info = $chrome->createTarget(
url => 'about:blank',
width => 1280,
height => 800,
newWindow => JSON::false,
background => JSON::false,
)->get;
print $info->{targetId};
Creates a new target. A whole new tab, built to order. π
$target->attach
$target->attach();
Attaches to the target set up in targetId and sessionId. And if a targetId is given, it attaches to it and remembers the value. She's not gonna forget, don't worry.
π 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.
π«Ά 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
Fr fr, if something's cursed, tell them. They wanna know.
π 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.
And that's the whole page, bestie β courtesy of perl v5.42.2, dated 2026-06-07, filed under Chrome:...:Target(3). Now go talk to that tab. Slay. πβ¨
π¦ 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