Node.js API for Chrome
Go to file
Nikolay Vitkov d3f0e6ca09
feat(webdriver): support Network interception (#12272)
The provides support for Network interception for the WebDriver
protocol.
More information on current state of WebDriver support can be found
[here](https://pptr.dev/webdriver-bidi).
This is a Puppteer side implementation for the Network interception
feature,
some vendors may not support all properties that you can send through
Puppeteer, please be aware.

You should try to display the error in your event handler as so:
```ts
page.on('request', request => {
  void request
    .continue({
      // Your overrides
    })
    .catch(error => {
      // The error will not propagate to the process
      console.error(error);
      // If you want to stop the process in NodeJS also use
      process.exit(1);
    });
});
const response = await page.goto('<URL>');
```

The following issues track state of vendor implementation, that
Puppeteer relies on:
Chrome: https://github.com/GoogleChromeLabs/chromium-bidi/issues/2035
Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1853882 and
https://bugzilla.mozilla.org/show_bug.cgi?id=1850680

Release Notes:
feat(webdriver): support page.setExtraHTTPHeaders
Source-Link:
140f012b51

feat(webdriver): support priority for request interception
Source-Link:
08bc8542ea
  
feat(webdriver): basic support for HTTPRequest.respond()
Source-Link:
cd88110456
2024-04-15 11:20:26 +02:00
.devcontainer chore: update devcontainer.json to Node 18 (#11986) 2024-02-23 10:06:12 +01:00
.github chore(deps): Bump peter-evans/create-pull-request from 6.0.2 to 6.0.3 in the all group (#12273) 2024-04-15 09:41:39 +02:00
.vscode refactor!: enable the new-headless mode by default (#11815) 2024-02-02 13:25:43 +01:00
docker test: fix the headless flag in the smoke test (#11894) 2024-02-12 12:03:51 +00:00
docs feat(webdriver): support Network interception (#12272) 2024-04-15 11:20:26 +02:00
examples docs: add plugin to format package manager scripts (#12254) 2024-04-11 15:47:14 +00:00
packages chore: release main (#12274) 2024-04-15 07:06:55 +00:00
test feat(webdriver): support Network interception (#12272) 2024-04-15 11:20:26 +02:00
test-d build: fix EsLint rule and add fixer (#11826) 2024-02-05 10:26:37 +01:00
tools chore: let TypeScript infer type (#12256) 2024-04-11 16:55:49 +00:00
website chore: release main (#12274) 2024-04-15 07:06:55 +00:00
.editorconfig EditorConfig: 2 space indent (#195) 2017-08-03 09:50:08 -07:00
.eslintignore chore: fix EsLint for .mjs (#11629) 2024-01-08 10:02:56 +01:00
.eslintrc.js chore: enable license header rule (#11855) 2024-02-06 18:07:30 +01:00
.eslintrc.types.cjs fix: remove unused imports (#8613) 2022-07-01 16:00:03 +02:00
.gitattributes chore(git): Fix line endings in text files (#4320) 2019-04-22 09:03:42 -07:00
.gitignore chore: fix EsLint for .mjs (#11629) 2024-01-08 10:02:56 +01:00
.mocharc.cjs chore: update license headers (#11563) 2024-01-03 10:11:33 +00:00
.npmrc chore(deps): Bump the dependencies group with 2 updates (#11939) 2024-02-22 11:09:12 +01:00
.nvmrc ci: test node-version-file (#11737) 2024-01-24 11:27:35 +01:00
.prettierignore chore: fix EsLint for .mjs (#11629) 2024-01-08 10:02:56 +01:00
.prettierrc.cjs docs: improve docs (#9179) 2022-10-28 08:49:28 +02:00
.release-please-manifest.json chore: release main (#12274) 2024-04-15 07:06:55 +00:00
Herebyfile.mjs docs: remove TOC in main page (#12270) 2024-04-15 06:23:56 +00:00
LICENSE chore: use https URL for license info (#6279) 2020-08-10 10:35:07 +02:00
package-lock.json chore: release main (#12274) 2024-04-15 07:06:55 +00:00
package.json chore(deps-dev): Bump the dev-dependencies group with 5 updates (#12250) 2024-04-11 13:28:49 +02:00
README.md docs: tweak redirects and the main page (#12265) 2024-04-12 13:24:30 +02:00
release-please-config.json chore: manual bump of config (#10772) 2023-08-22 13:25:42 +00:00
SECURITY.md chore: Add a security policy (#9547) 2023-01-19 17:03:59 +01:00
tsconfig.base.json chore: update dependencies (#10785) 2023-08-28 13:01:52 +02:00
tsdoc.json chore: update license headers (#11563) 2024-01-03 10:11:33 +00:00
versions.js chore: release main (#12252) 2024-04-11 16:51:07 +00:00

Puppeteer

build npm puppeteer package

Puppeteer is a Node.js library which provides a high-level API to control Chrome/Chromium over the DevTools Protocol. Puppeteer runs in headless mode by default, but can be configured to run in full ("headful") Chrome/Chromium.

Get started | API | FAQ | Contributing | Troubleshooting

Example

import puppeteer from 'puppeteer';

(async () => {
  // Launch the browser and open a new blank page
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  // Navigate the page to a URL
  await page.goto('https://developer.chrome.com/');

  // Set screen size
  await page.setViewport({width: 1080, height: 1024});

  // Type into search box
  await page.type('.devsite-search-field', 'automate beyond recorder');

  // Wait and click on first result
  const searchResultSelector = '.devsite-result-item-link';
  await page.waitForSelector(searchResultSelector);
  await page.click(searchResultSelector);

  // Locate the full title with a unique string
  const textSelector = await page.waitForSelector(
    'text/Customize and automate'
  );
  const fullTitle = await textSelector?.evaluate(el => el.textContent);

  // Print the full title
  console.log('The title of this blog post is "%s".', fullTitle);

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