Chrome:...:Target(3)

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

πŸ’– 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 any
  • autoclose β€” close the tab when the object goes out of scope (bye bestie πŸ‘‹)
  • log β€” a premade Log::Log4perl object to act as logger
  • app β€” 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 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