Skip to main content

Class: PuppeteerAdapter

@mugshot/puppeteer.PuppeteerAdapter

Webdriver adapter over Puppeteer to be used with WebdriverScreenshotter.

example

import { Mugshot } from 'mugshot';
import { PuppeteerAdapter } from '@mugshot/puppeteer';
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
const page = await browser.newPage();
const mugshot = new Mugshot(
new PuppeteerAdapter(page),
'./screenshots'
);

Implements#

Constructors#

constructor#

+ new PuppeteerAdapter(page: Page): PuppeteerAdapter

Parameters:#

NameTypeDescription
pagePageThe return value of newPage().

Returns: PuppeteerAdapter

Defined in: packages/puppeteer/src/index.ts:26

Methods#

execute#

execute<R, A>(func: (...args: A) => R, ...args: A): Promise<any>

Execute a function in the current page context.

Type parameters:#

NameType
R-
Aany[]

Parameters:#

NameType
func(...args: A) => R
...argsA

Returns: Promise<any>

Implementation of: Webdriver.execute

Defined in: packages/puppeteer/src/index.ts:66


getElementRect#

getElementRect(selector: string): Promise<null | { height: number = 0; width: number = 0; x: number = 0; y: number = 0 } | { height: number = 0; width: number = 0; x: number = 0; y: number = 0 }[]>

Get the dimensions and coordinates of an element.

Parameters:#

NameType
selectorstring

Returns: Promise<null | { height: number = 0; width: number = 0; x: number = 0; y: number = 0 } | { height: number = 0; width: number = 0; x: number = 0; y: number = 0 }[]>

Implementation of: Webdriver.getElementRect

Defined in: packages/puppeteer/src/index.ts:32


setViewportSize#

setViewportSize(width: number, height: number): Promise<void>

Set the size of the viewport (meaning window minus chrome).

This is unlike setWindowRect which doesn't take the chrome into account.

Parameters:#

NameType
widthnumber
heightnumber

Returns: Promise<void>

Implementation of: Webdriver.setViewportSize

Defined in: packages/puppeteer/src/index.ts:54


takeViewportScreenshot#

takeViewportScreenshot(): Promise<string>

Take a viewport screenshot and return a base64 string.

Returns: Promise<string>

Implementation of: Webdriver.takeViewportScreenshot

Defined in: packages/puppeteer/src/index.ts:60