Movatterモバイル変換


[0]ホーム

URL:


Google Git
Sign in
chromium /chromium /src /refs/heads/main /. /headless
tree: 18ac11b1c015e6aeb665d0aaa5ec01b979ffa29d [path history][tgz]
  1. app/
  2. lib/
  3. public/
  4. test/
  5. BUILD.gn
  6. COMMON_METADATA
  7. DEPS
  8. DIR_METADATA
  9. headless.gni
  10. OWNERS
  11. protocol_config.json
  12. README.md
headless/README.md

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, precompiledheadless_shell binaries are available for download under the namechrome-headless-shell viaChrome for Testing infrastructure.

As of M132, headless shell functionality is no longer part of the Chrome binary, so --headless=old has no effect. If you are using old Headless functionality you should now migrate tochrome-headless-shell.Read more.

There are two ways to use Headless Chromium:

Usage via the DevTools remote debugging protocol

  1. Start Chrome in headless mode using the--headless command line flag:
$ chrome--headless--remote-debugging-port=9222 https://chromium.org/
  1. Navigate tochrome://inspect/ in another instance of Chrome.

Usage from Node.js

For example, thechrome-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.    awaitPage.enable();    awaitPage.navigate({url:'https://example.com'});    awaitPage.loadEventFired();// Evaluate outerHTML after page has loaded.const expression={expression:'document.body.outerHTML'};const{ result}= awaitRuntime.evaluate(expression);    console.log(result.value);}catch(err){    console.error('Cannot connect to browser:', err);} finally{if(client){      await client.close();}}})();

Alternatvely, thePuppeteer 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)


[8]ページ先頭

©2009-2025 Movatter.jp