0
Files
src/headless
Sida Zhu 01cacf8a1c Video: Add decoder prefix for IsSupported{Audio|Video}Type related functions
There will be a new function `IsEncoderSupportedVideoType()`
soon, so rename the existing functions first
to make it more clear.

This CL has no actual logic changes, just renaming.

Bug: 40276507
Change-Id: I419647037c57aff0f08636d4ca1cb4b2988dc92f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5952551
Reviewed-by: Zijie He <zijiehe@google.com>
Commit-Queue: Sida Zhu <zhusida@bytedance.com>
Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: Vigen Issahhanjan <vigeni@google.com>
Reviewed-by: Peter Kvitek <kvitekp@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1374246}
2024-10-26 03:11:20 +00:00
..

Headless Chromium

Headless Chromium allows running Chromium in a headless/server environment. Expected use cases include loading web pages, extracting metadata (e.g., the DOM) and generating bitmaps from page contents -- using all the modern web platform features provided by Chromium and Blink.

As of M118, precompiled headless_shell binaries are available for download under the name chrome-headless-shell via Chrome for Testing infrastructure.

There are two ways to use Headless Chromium:

Usage via the DevTools remote debugging protocol

  1. Start a normal Chrome binary with the --headless=old command line flag:
$ chrome --headless=old --remote-debugging-port=9222 https://chromium.org/
  1. Navigate to chrome://inspect/ in another instance of Chrome.

Usage from Node.js

For example, the chrome-remote-interface Node.js package can be used to extract a page's DOM like this:

const CDP = require('chrome-remote-interface');

(async () => {
  let client;
  try {
    // Connect to browser
    client = await CDP();

    // Extract used DevTools domains.
    const {Page, Runtime} = client;

    // Enable events on domains we are interested in.
    await Page.enable();
    await Page.navigate({url: 'https://example.com'});
    await Page.loadEventFired();

    // Evaluate outerHTML after page has loaded.
    const expression = {expression: 'document.body.outerHTML'};
    const { result } = await Runtime.evaluate(expression);
    console.log(result.value);

  } catch (err) {
    console.error('Cannot connect to browser:', err);

  } finally {
    if (client) {
      await client.close();
    }
  }
})();

Alternatvely, the Puppeteer Node.js package can be used to communicate with headless, for example:

import puppeteer from 'puppeteer';

(async () => {
  const browser = await puppeteer.launch({headless: 'shell'});

  const page = await browser.newPage();
  await page.goto('https://example.com');

  const title = await page.evaluate(() => document.title);
  console.log(title);

  await browser.close();
})();

Resources and Documentation

Mailing list: headless-dev@chromium.org

Bug tracker: Internals>Headless

File a new bug (bit.ly/2pP6SBb)