What is @types/puppeteer-core?
@types/puppeteer-core provides TypeScript type definitions for the puppeteer-core library, which is a tool for controlling headless Chrome or Chromium browsers programmatically.
What are @types/puppeteer-core's main functionalities?
Launching a Browser
This feature allows you to launch a headless browser instance. The code sample demonstrates how to launch a headless browser and then close it.
const puppeteer = require('puppeteer-core');
(async () => {
const browser = await puppeteer.launch({ headless: true });
console.log('Browser launched');
await browser.close();
})();
Navigating to a Web Page
This feature allows you to navigate to a specific web page. The code sample demonstrates how to open a new page in the browser and navigate to 'https://example.com'.
const puppeteer = require('puppeteer-core');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
console.log('Page loaded');
await browser.close();
})();
Taking a Screenshot
This feature allows you to take a screenshot of a web page. The code sample demonstrates how to navigate to a web page and take a screenshot, saving it as 'example.png'.
const puppeteer = require('puppeteer-core');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'example.png' });
console.log('Screenshot taken');
await browser.close();
})();
Extracting Page Content
This feature allows you to extract the HTML content of a web page. The code sample demonstrates how to navigate to a web page and log its HTML content.
const puppeteer = require('puppeteer-core');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
const content = await page.content();
console.log(content);
await browser.close();
})();
Other packages similar to @types/puppeteer-core
puppeteer
puppeteer is a high-level API to control headless Chrome or Chromium over the DevTools Protocol. It includes everything needed to control the browser, whereas puppeteer-core is a lighter version that does not include the browser binaries.
playwright
playwright is a Node.js library to automate Chromium, Firefox, and WebKit with a single API. It offers more browser options compared to puppeteer-core, which is limited to Chrome/Chromium.
selenium-webdriver
selenium-webdriver is a library for automating web browsers. It supports multiple browsers and is widely used for web testing. Unlike puppeteer-core, it requires a WebDriver server to interact with the browser.