Chrome::DevToolsProtocol::Target - wrapper for talking to a page in a Target


    # Usually, WWW::Mechanize::Chrome automatically creates a driver for you
    my $driver = Chrome::DevToolsProtocol::Target->new(
        transport => $target,
    $driver->connect( new_tab => 1 )->get


->new( %args )

    my $driver = Chrome::DevToolsProtocol::Target->new(
        transport => $target,
        auto_close => 0,
        error_handler => sub {
            # Reraise the error
            croak $_[1]

These members can mostly be set through the constructor arguments:


The JSON decoder used


Which tab to reuse (if any)


Close the tab when the object goes out of scope


A premade Log::Log4perl object to act as logger


A callback invoked for every message


The event-loop specific transport backend


    my $f = $driver->future();

Returns a backend-specific generic future


    my $url = $driver->endpoint();

Returns the URL endpoint to talk to for the connected tab


    my $l = $driver->add_listener(
        sub {
            warn "The DOMContent event was fired";

    # ...

    undef $l; # stop listening

Adds a callback for the given event name. The callback will be removed once the return value goes out of scope.



Explicitly remove a listener.


    $driver->log('debug', "Warbling doodads", { doodad => 'this' } );

Log a message


    my $f = $driver->connect()->get;

Asynchronously connect to the Chrome browser, returning a Future.



Shut down the connection to our tab and close it.



Sleep for the amount of seconds in an event-loop compatible way


    my $f = $driver->one_shot('Page.domContentEventFired')->get;

Returns a future that resolves when the event is received


    my $data = $driver->json_get( 'version' )->get;

Requests an URL and returns decoded JSON from the future


    print $chrome->version_info->get->{"protocolVersion"};


    print $chrome->protocol_version->get;


      accept => JSON::true,

Sends a JSON packet to the remote end


  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.






  my @tabs = $chrome->list_tabs->get();


    my $new_tab = $chrome->new_tab('')->get;


    $chrome->activate_tab( $tab )->get

Brings the tab to the foreground of the application


Returns information about the current target


Returns information about the current target


Returns the title of the current target


Returns information about the Chrome instance we are connected to.


    my $info = $chrome->createTarget(
        url => 'about:blank',
        width => 1280,
        height => 800,
        newWindow => JSON::false,
        background => JSON::false,
    print $info->{targetId};

Creates a new target



Attaches to the target set up in targetId and sessionId. If a targetId is given, attaches to it and remembers the value.


The inofficial Chrome debugger API documentation at

Chrome DevTools at


The public repository of this module is


The public support forum of this module is


Please report bugs in this module via the RT CPAN bug queue at or via mail to


Max Maischein


Copyright 2010-2020 by Max Maischein


This module is released under the same terms as Perl itself.