Search code examples
google-chromegoogle-chrome-devtoolschromiumpuppeteer

What's a browser Target in chrome DevTools protocol?


In the main website of chrome DevTools protocol, there's a section for Target Domain.

In puppeteer library, there's a JS class for that, And it has got just a few methods.

What's Target and What's for?


Solution

  • A target, as described in your question, can be a page, background page, service worker, browser, and more.

    In other words, a target is essentially the current frame or environment that is in focus.


    The Chrome DevTools Protocol Documentation describes the Target Domain as:

    Target Domain

    Supports additional targets discovery and allows to attach to them.


    Puppeteer, a Node.js library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol, has a Target class which is documented as the following:

    class: Target

    target.browser()

    Get the browser the target belongs to.

    target.browserContext()

    The browser context the target belongs to.

    target.createCDPSession()

    Creates a Chrome Devtools Protocol session attached to the target.

    target.opener()

    Get the target that opened this target. Top-level targets return null.

    target.page()

    If the target is not of type "page" or "background_page", returns null.

    target.type()

    Identifies what kind of target this is. Can be "page", "background_page", "service_worker", "browser" or "other".

    target.url()