0
Files
src/headless
Cristian Lopez fe35bf7c24 Create client-configured field trial for using new seed file.
Create a client-configured field trial, SeedFileTrial, with two
possible groups, a treatment group that will use the seed files group
and a control group which will continue with status quo behavior.

This CL also does the following:

* Involved considering multiple different options for where to have the
field trial setup take place with the following options considered:

  - In the SeedReaderWriter, rejected because, since both the safe
    seed store and the latest seed store have a corresponding
    SeedReaderWriter, we would be doing the setup twice.

  - In the VariationService, rejected because, by wanting to
    consolidate logic, it did not feel as correct of a spot as the
    seed store.

* Removes plumbing channel to the SeedReaderWriter as well as the
logic related to the channel in SeedReaderWriter. This is because
behavior will now be determined by the field trial group instead of
the release channel of a client.

* Renames kDefaultGroup to kTestDefaultGroup in unittest to avoid
naming collision

Bug: 371181951
Change-Id: Ia870df79d4e00bd0fe272441a196e0ee75064c0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5907254
Reviewed-by: Caitlin Fischer <caitlinfischer@google.com>
Reviewed-by: Nate Fischer <ntfschr@chromium.org>
Commit-Queue: Cristian Lopez <cristiandlopez@google.com>
Cr-Commit-Position: refs/heads/main@{#1379240}
2024-11-06 21:17:43 +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)