puppeteer/new-docs/puppeteer.page.md
Jack Franklin ace31d6f58
chore: pin TSDoc related dependencies (#6063)
Without the API-* dependencies pinned different versions may be
installed on local machines vs CI. One of the checks we do is to check
that the checked in docs matches what is generated on CI. Therefore we
need to ensure devs locally run the exact version that CI runs such that
they generate the same output. So in this case we pin to a particular
version of the dependencies.
2020-06-22 09:16:51 +01:00

7.1 KiB

Home > puppeteer > Page

Page class

Page provides methods to interact with a single tab or [extension background page](https://developer.chrome.com/extensions/background_pages) in Chromium. One [Browser] instance might have multiple [Page] instances.

Signature:

export declare class Page extends EventEmitter 

Extends: EventEmitter

Remarks

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the Page class.

Example 1

This example creates a page, navigates it to a URL, and then * saves a screenshot:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({path: 'screenshot.png'});
  await browser.close();
})();

The Page class extends from Puppeteer's EventEmitter class and will emit various events which are documented in the PageEmittedEvents enum.

Example 2

This example logs a message for a single page load event:

page.once('load', () => console.log('Page loaded!'));

To unsubscribe from events use the off method:

function logRequest(interceptedRequest) {
  console.log('A request was made:', interceptedRequest.url());
}
page.on('request', logRequest);
// Sometime later...
page.off('request', logRequest);

Properties

Property Modifiers Type Description
accessibility Accessibility
coverage Coverage
keyboard Keyboard
mouse Mouse
touchscreen Touchscreen
tracing Tracing

Methods

Method Modifiers Description
$(selector)
$$(selector)
$$eval(selector, pageFunction, args)
$eval(selector, pageFunction, args)
$x(expression)
addScriptTag(options)
addStyleTag(options)
authenticate(credentials)
bringToFront()
browser()
browserContext()
click(selector, options)
close(options)
content()
cookies(urls)
deleteCookie(cookies)
emulate(options)
emulateMediaFeatures(features)
emulateMediaType(type)
emulateTimezone(timezoneId)
emulateVisionDeficiency(type)
evaluate(pageFunction, args)
evaluateHandle(pageFunction, args)
evaluateOnNewDocument(pageFunction, args)
exposeFunction(name, puppeteerFunction)
focus(selector)
frames()
goBack(options)
goForward(options)
goto(url, options)
hover(selector)
isClosed()
isJavaScriptEnabled()
mainFrame()
metrics()
pdf(options)
queryObjects(prototypeHandle)
reload(options)
screenshot(options)
select(selector, values)
setBypassCSP(enabled)
setCacheEnabled(enabled)
setContent(html, options)
setCookie(cookies)
setDefaultNavigationTimeout(timeout)
setDefaultTimeout(timeout)
setExtraHTTPHeaders(headers)
setGeolocation(options)
setJavaScriptEnabled(enabled)
setOfflineMode(enabled)
setRequestInterception(value)
setUserAgent(userAgent)
setViewport(viewport)
tap(selector)
target()
title()
type(selector, text, options)
url()
viewport()
waitFor(selectorOrFunctionOrTimeout, options, args)
waitForFileChooser(options)
waitForFunction(pageFunction, options, args)
waitForNavigation(options)
waitForRequest(urlOrPredicate, options)
waitForResponse(urlOrPredicate, options)
waitForSelector(selector, options)
waitForXPath(xpath, options)
workers()