1
1
mirror of https://github.com/namibia/awesome-cheatsheets.git synced 2025-01-23 23:28:25 +00:00

feat(puppeteer): add comments

This commit is contained in:
Julien Le Coupanec 2020-03-17 14:13:45 +01:00
parent c882af50b7
commit c5faec60ef

View File

@ -69,26 +69,26 @@ browserFetcher.revisionInfo(revision) // Returns all the informa
const browser = await puppeteer.launch(); const browser = await puppeteer.launch();
browser.on('disconnected') // browser.on('disconnected') // Emitted when Puppeteer gets disconnected from the Chromium instance.
browser.on('targetchanged') // browser.on('targetchanged') // Emitted when the url of a target changes.
browser.on('targetcreated') // browser.on('targetcreated') // Emitted when a target is created, for example when a new page is opened by window.open or browser.newPage.
browser.on('targetdestroyed') // browser.on('targetdestroyed') // Emitted when a target is destroyed, for example when a page is closed.
browser.browserContexts() browser.browserContexts() //
browser.close() browser.close() //
browser.createIncognitoBrowserContext() browser.createIncognitoBrowserContext() //
browser.defaultBrowserContext() browser.defaultBrowserContext() //
browser.disconnect() browser.disconnect() //
browser.isConnected() browser.isConnected() //
browser.newPage() browser.newPage() //
browser.pages() browser.pages() //
browser.process() browser.process() //
browser.target() browser.target() //
browser.targets() browser.targets() //
browser.userAgent() browser.userAgent() //
browser.version() browser.version() //
browser.waitForTarget(predicate[, options]) browser.waitForTarget(predicate[, options]) //
browser.wsEndpoint() browser.wsEndpoint() //
// BROWSER CONTEXT // BROWSER CONTEXT
// BrowserContexts provide a way to operate multiple independent browser sessions // BrowserContexts provide a way to operate multiple independent browser sessions
@ -96,19 +96,19 @@ browser.wsEndpoint()
const context = await browser.createIncognitoBrowserContext(); const context = await browser.createIncognitoBrowserContext();
browserContext.on('targetchanged') browserContext.on('targetchanged') //
browserContext.on('targetcreated') browserContext.on('targetcreated') //
browserContext.on('targetdestroyed') browserContext.on('targetdestroyed') //
browserContext.browser() browserContext.browser() //
browserContext.clearPermissionOverrides() browserContext.clearPermissionOverrides() //
browserContext.close() browserContext.close() //
browserContext.isIncognito() browserContext.isIncognito() //
browserContext.newPage() browserContext.newPage() //
browserContext.overridePermissions(origin, permissions) browserContext.overridePermissions(origin, permissions) //
browserContext.pages() browserContext.pages() //
browserContext.targets() browserContext.targets() //
browserContext.waitForTarget(predicate[, options]) browserContext.waitForTarget(predicate[, options]) //
// PAGE // PAGE
// Page provides methods to interact with a single tab or extension background page in Chromium. // Page provides methods to interact with a single tab or extension background page in Chromium.
@ -117,338 +117,338 @@ browserContext.waitForTarget(predicate[, options])
const page = await browser.newPage(); const page = await browser.newPage();
page.on('close') page.on('close') //
page.on('console') page.on('console') //
page.on('dialog') page.on('dialog') //
page.on('domcontentloaded') page.on('domcontentloaded') //
page.on('error') page.on('error') //
page.on('frameattached') page.on('frameattached') //
page.on('framedetached') page.on('framedetached') //
page.on('framenavigated') page.on('framenavigated') //
page.on('load') page.on('load') //
page.on('metrics') page.on('metrics') //
page.on('pageerror') page.on('pageerror') //
page.on('popup') page.on('popup') //
page.on('request') page.on('request') //
page.on('requestfailed') page.on('requestfailed') //
page.on('requestfinished') page.on('requestfinished') //
page.on('response') page.on('response') //
page.on('workercreated') page.on('workercreated') //
page.on('workerdestroyed') page.on('workerdestroyed') //
page.accessibility page.accessibility //
page.coverage page.coverage //
page.keyboard page.keyboard //
page.mouse page.mouse //
page.touchscreen page.touchscreen //
page.tracing page.tracing //
page.$(selector) page.$(selector) //
page.$$(selector) page.$$(selector) //
page.$$eval(selector, pageFunction[, ...args]) page.$$eval(selector, pageFunction[, ...args]) //
page.$eval(selector, pageFunction[, ...args]) page.$eval(selector, pageFunction[, ...args]) //
page.$x(expression) page.$x(expression) //
page.addScriptTag(options) page.addScriptTag(options) //
page.addStyleTag(options) page.addStyleTag(options) //
page.authenticate(credentials) page.authenticate(credentials) //
page.bringToFront() page.bringToFront() //
page.browser() page.browser() //
page.browserContext() page.browserContext( //
page.click(selector[, options]) page.click(selector[, options]) //
page.close([options]) page.close([options]) //
page.content() page.content() //
page.cookies([...urls]) page.cookies([...urls]) //
page.deleteCookie(...cookies) page.deleteCookie(...cookies) //
page.emulate(options) page.emulate(options) //
page.emulateMedia(type) page.emulateMedia(type) //
page.emulateMediaFeatures(features) page.emulateMediaFeatures(features) //
page.emulateMediaType(type) page.emulateMediaType(type) //
page.emulateTimezone(timezoneId) page.emulateTimezone(timezoneId) //
page.evaluate(pageFunction[, ...args]) page.evaluate(pageFunction[, ...args]) //
page.evaluateHandle(pageFunction[, ...args]) page.evaluateHandle(pageFunction[, ...args]) //
page.evaluateOnNewDocument(pageFunction[, ...args]) page.evaluateOnNewDocument(pageFunction[, ...args]) //
page.exposeFunction(name, puppeteerFunction) page.exposeFunction(name, puppeteerFunction) //
page.focus(selector) page.focus(selector) //
page.frames() page.frames() //
page.goBack([options]) page.goBack([options]) //
page.goForward([options]) page.goForward([options]) //
page.goto(url[, options]) page.goto(url[, options]) //
page.hover(selector) page.hover(selector) //
page.isClosed() page.isClosed() //
page.mainFrame() page.mainFrame() //
page.metrics() page.metrics() //
page.pdf([options]) page.pdf([options]) //
page.queryObjects(prototypeHandle) page.queryObjects(prototypeHandle) //
page.reload([options]) page.reload([options]) //
page.screenshot([options]) page.screenshot([options]) //
page.select(selector, ...values) page.select(selector, ...values) //
page.setBypassCSP(enabled) page.setBypassCSP(enabled) //
page.setCacheEnabled([enabled]) page.setCacheEnabled([enabled]) //
page.setContent(html[, options]) page.setContent(html[, options]) //
page.setCookie(...cookies) page.setCookie(...cookies) //
page.setDefaultNavigationTimeout(timeout) page.setDefaultNavigationTimeout(timeout) //
page.setDefaultTimeout(timeout) page.setDefaultTimeout(timeout) //
page.setExtraHTTPHeaders(headers) page.setExtraHTTPHeaders(headers) //
page.setGeolocation(options) page.setGeolocation(options) //
page.setJavaScriptEnabled(enabled) page.setJavaScriptEnabled(enabled) //
page.setOfflineMode(enabled) page.setOfflineMode(enabled) //
page.setRequestInterception(value) page.setRequestInterception(value) //
page.setUserAgent(userAgent) page.setUserAgent(userAgent) //
page.setViewport(viewport) page.setViewport(viewport) //
page.tap(selector) page.tap(selector) //
page.target() page.target() //
page.title() page.title() //
page.type(selector, text[, options]) page.type(selector, text[, options]) //
page.url() page.url() //
page.viewport() page.viewport() //
page.waitFor(selectorOrFunctionOrTimeout[, options[, ...args]]) page.waitFor(selectorOrFunctionOrTimeout[, options[, ...args]]) //
page.waitForFileChooser([options]) page.waitForFileChooser([options]) //
page.waitForFunction(pageFunction[, options[, ...args]]) page.waitForFunction(pageFunction[, options[, ...args]]) //
page.waitForNavigation([options]) page.waitForNavigation([options]) //
page.waitForRequest(urlOrPredicate[, options]) page.waitForRequest(urlOrPredicate[, options]) //
page.waitForResponse(urlOrPredicate[, options]) page.waitForResponse(urlOrPredicate[, options]) //
page.waitForSelector(selector[, options]) page.waitForSelector(selector[, options]) //
page.waitForXPath(xpath[, options]) page.waitForXPath(xpath[, options]) //
page.workers() page.workers() //
// WORKER // WORKER
// The Worker class represents a WebWorker. // The Worker class represents a WebWorker.
// The events workercreated and workerdestroyed are emitted on the page object to signal the worker lifecycle. // The events workercreated and workerdestroyed are emitted on the page object to signal the worker lifecycle.
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-worker // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-worker
worker.evaluate(pageFunction[, ...args]) worker.evaluate(pageFunction[, ...args]) //
worker.evaluateHandle(pageFunction[, ...args]) worker.evaluateHandle(pageFunction[, ...args]) //
worker.executionContext() worker.executionContext() //
worker.url() worker.url() //
// ACCESSIBILITY // ACCESSIBILITY
// The Accessibility class provides methods for inspecting Chromium's accessibility tree. // The Accessibility class provides methods for inspecting Chromium's accessibility tree.
// The accessibility tree is used by assistive technology such as screen readers or switches. // The accessibility tree is used by assistive technology such as screen readers or switches.
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-accessibility // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-accessibility
accessibility.snapshot([options]) accessibility.snapshot([options]) //
// KEYBOARD // KEYBOARD
// Keyboard provides an api for managing a virtual keyboard. // Keyboard provides an api for managing a virtual keyboard.
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-keyboard // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-keyboard
keyboard.down(key[, options]) keyboard.down(key[, options]) //
keyboard.press(key[, options]) keyboard.press(key[, options]) //
keyboard.sendCharacter(char) keyboard.sendCharacter(char) //
keyboard.type(text[, options]) keyboard.type(text[, options]) //
keyboard.up(key) keyboard.up(key) //
// MOUSE // MOUSE
// The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport. // The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport.
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-mouse // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-mouse
mouse.click(x, y[, options]) mouse.click(x, y[, options]) //
mouse.down([options]) mouse.down([options]) //
mouse.move(x, y[, options]) mouse.move(x, y[, options]) //
mouse.up([options]) mouse.up([options]) //
// TOUCHSCREEN // TOUCHSCREEN
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-touchscreen // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-touchscreen
touchscreen.tap(x, y) touchscreen.tap(x, y) //
// TRACING // TRACING
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-tracing // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-tracing
tracing.start([options]) tracing.start([options]) //
tracing.stop() tracing.stop() //
// FILE CHOOSER // FILE CHOOSER
// FileChooser objects are returned via the 'page.waitForFileChooser' method. // FileChooser objects are returned via the 'page.waitForFileChooser' method.
// File choosers let you react to the page requesting for a file. // File choosers let you react to the page requesting for a file.
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-filechooser // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-filechooser
fileChooser.accept(filePaths) fileChooser.accept(filePaths) //
fileChooser.cancel() fileChooser.cancel() //
fileChooser.isMultiple() fileChooser.isMultiple() //
// DIALOG // DIALOG
// Dialog objects are dispatched by page via the 'dialog' event. // Dialog objects are dispatched by page via the 'dialog' event.
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-dialog // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-dialog
dialog.accept([promptText]) dialog.accept([promptText]) //
dialog.defaultValue() dialog.defaultValue() //
dialog.dismiss() dialog.dismiss() //
dialog.message() dialog.message() //
dialog.type() dialog.type() //
// CONSOLE MESSAGE // CONSOLE MESSAGE
// ConsoleMessage objects are dispatched by page via the 'console' event. // ConsoleMessage objects are dispatched by page via the 'console' event.
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-consolemessage // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-consolemessage
consoleMessage.args() consoleMessage.args() //
consoleMessage.location() consoleMessage.location() //
consoleMessage.text() consoleMessage.text() //
consoleMessage.type() consoleMessage.type() //
// FRAME // FRAME
// At every point of time, page exposes its current frame tree via the page.mainFrame() and frame.childFrames() methods. // At every point of time, page exposes its current frame tree via the page.mainFrame() and frame.childFrames() methods.
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-frame // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-frame
frame.$(selector) frame.$(selector) //
frame.$$(selector) frame.$$(selector) //
frame.$$eval(selector, pageFunction[, ...args]) frame.$$eval(selector, pageFunction[, ...args]) //
frame.$eval(selector, pageFunction[, ...args]) frame.$eval(selector, pageFunction[, ...args]) //
frame.$x(expression) frame.$x(expression) //
frame.addScriptTag(options) frame.addScriptTag(options) //
frame.addStyleTag(options) frame.addStyleTag(options) //
frame.childFrames() frame.childFrames() //
frame.click(selector[, options]) frame.click(selector[, options]) //
frame.content() frame.content() //
frame.evaluate(pageFunction[, ...args]) frame.evaluate(pageFunction[, ...args]) //
frame.evaluateHandle(pageFunction[, ...args]) frame.evaluateHandle(pageFunction[, ...args]) //
frame.executionContext() frame.executionContext() //
frame.focus(selector) frame.focus(selector) //
frame.goto(url[, options]) frame.goto(url[, options]) //
frame.hover(selector) frame.hover(selector) //
frame.isDetached() frame.isDetached() //
frame.name() frame.name() //
frame.parentFrame() frame.parentFrame() //
frame.select(selector, ...values) frame.select(selector, ...values) //
frame.setContent(html[, options]) frame.setContent(html[, options]) //
frame.tap(selector) frame.tap(selector) //
frame.title() frame.title() //
frame.type(selector, text[, options]) frame.type(selector, text[, options]) //
frame.url() frame.url() //
frame.waitFor(selectorOrFunctionOrTimeout[, options[, ...args]]) frame.waitFor(selectorOrFunctionOrTimeout[, options[, ...args]]) //
frame.waitForFunction(pageFunction[, options[, ...args]]) frame.waitForFunction(pageFunction[, options[, ...args]]) //
frame.waitForNavigation([options]) frame.waitForNavigation([options]) //
frame.waitForSelector(selector[, options]) frame.waitForSelector(selector[, options]) //
frame.waitForXPath(xpath[, options]) frame.waitForXPath(xpath[, options]) //
// EXECUTION CONTEXT // EXECUTION CONTEXT
// The class represents a context for JavaScript execution. // The class represents a context for JavaScript execution.
// Besides pages, execution contexts can be found in workers. // Besides pages, execution contexts can be found in workers.
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-executioncontext // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-executioncontext
executionContext.evaluate(pageFunction[, ...args]) executionContext.evaluate(pageFunction[, ...args]) //
executionContext.evaluateHandle(pageFunction[, ...args]) executionContext.evaluateHandle(pageFunction[, ...args]) //
executionContext.frame() executionContext.frame() //
executionContext.queryObjects(prototypeHandle) executionContext.queryObjects(prototypeHandle) //
// JSHANDLE // JSHANDLE
// JSHandle represents an in-page JavaScript object. // JSHandle represents an in-page JavaScript object.
// JSHandles can be created with the page.evaluateHandle method. // JSHandles can be created with the page.evaluateHandle method.
// const windowHandle = await page.evaluateHandle(() => window); // const windowHandle = await page.evaluateHandle(() => window);
jsHandle.asElement() jsHandle.asElement() //
jsHandle.dispose() jsHandle.dispose() //
jsHandle.evaluate(pageFunction[, ...args]) jsHandle.evaluate(pageFunction[, ...args]) //
jsHandle.evaluateHandle(pageFunction[, ...args]) jsHandle.evaluateHandle(pageFunction[, ...args]) //
jsHandle.executionContext() jsHandle.executionContext() //
jsHandle.getProperties() jsHandle.getProperties() //
jsHandle.getProperty(propertyName) jsHandle.getProperty(propertyName) //
jsHandle.jsonValue() jsHandle.jsonValue() //
// ELEMENTHANDLE // ELEMENTHANDLE
// ElementHandle represents an in-page DOM element. // ElementHandle represents an in-page DOM element.
// ElementHandles can be created with the page.$ method. // ElementHandles can be created with the page.$ method.
// const hrefElement = await page.$('a'); // const hrefElement = await page.$('a');
elementHandle.$(selector) elementHandle.$(selector) //
elementHandle.$$(selector) elementHandle.$$(selector) //
elementHandle.$$eval(selector, pageFunction[, ...args]) elementHandle.$$eval(selector, pageFunction[, ...args]) //
elementHandle.$eval(selector, pageFunction[, ...args]) elementHandle.$eval(selector, pageFunction[, ...args]) //
elementHandle.$x(expression) elementHandle.$x(expression) //
elementHandle.asElement() elementHandle.asElement() //
elementHandle.boundingBox() elementHandle.boundingBox() //
elementHandle.boxModel() elementHandle.boxModel() //
elementHandle.click([options]) elementHandle.click([options]) //
elementHandle.contentFrame() elementHandle.contentFrame() //
elementHandle.dispose() elementHandle.dispose() //
elementHandle.evaluate(pageFunction[, ...args]) elementHandle.evaluate(pageFunction[, ...args]) //
elementHandle.evaluateHandle(pageFunction[, ...args]) elementHandle.evaluateHandle(pageFunction[, ...args]) //
elementHandle.executionContext() elementHandle.executionContext() //
elementHandle.focus() elementHandle.focus() //
elementHandle.getProperties() elementHandle.getProperties() //
elementHandle.getProperty(propertyName) elementHandle.getProperty(propertyName) //
elementHandle.hover() elementHandle.hover() //
elementHandle.isIntersectingViewport() elementHandle.isIntersectingViewport() //
elementHandle.jsonValue() elementHandle.jsonValue() //
elementHandle.press(key[, options]) elementHandle.press(key[, options]) //
elementHandle.screenshot([options]) elementHandle.screenshot([options]) //
elementHandle.select(...values) elementHandle.select(...values) //
elementHandle.tap() elementHandle.tap() //
elementHandle.toString() elementHandle.toString() //
elementHandle.type(text[, options]) elementHandle.type(text[, options]) //
elementHandle.uploadFile(...filePaths) elementHandle.uploadFile(...filePaths) //
// REQUEST // REQUEST
// Represents a request which are sent by a page. // Represents a request which are sent by a page.
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-request // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-request
request.abort([errorCode]) request.abort([errorCode]) //
request.continue([overrides]) request.continue([overrides]) //
request.failure() request.failure() //
request.frame() request.frame() //
request.headers() request.headers() //
request.isNavigationRequest() request.isNavigationRequest() //
request.method() request.method() //
request.postData() request.postData() //
request.redirectChain() request.redirectChain() //
request.resourceType() request.resourceType() //
request.respond(response) request.respond(response) //
request.response() request.response() //
request.url() request.url() //
// RESPONSE // RESPONSE
// Response class represents responses which are received by page. // Response class represents responses which are received by page.
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-response // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-response
response.buffer() response.buffer() //
response.frame() response.frame() //
response.fromCache() response.fromCache() //
response.fromServiceWorker() response.fromServiceWorker() //
response.headers() response.headers() //
response.json() response.json() //
response.ok() response.ok() //
response.remoteAddress() response.remoteAddress() //
response.request() response.request() //
response.securityDetails() response.securityDetails() //
response.status() response.status() //
response.statusText() response.statusText() //
response.text() response.text() //
response.url() response.url() //
// SECURITY DETAILS // SECURITY DETAILS
// SecurityDetails class represents the security details when response was received over the secure connection. // SecurityDetails class represents the security details when response was received over the secure connection.
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-securitydetails // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-securitydetails
securityDetails.issuer() securityDetails.issuer() //
securityDetails.protocol() securityDetails.protocol() //
securityDetails.subjectName() securityDetails.subjectName() //
securityDetails.validFrom() securityDetails.validFrom() //
securityDetails.validTo() securityDetails.validTo() //
// TARGET // TARGET
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-target // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-target
target.browser() target.browser() //
target.browserContext() target.browserContext() //
target.createCDPSession() target.createCDPSession() //
target.opener() target.opener() //
target.page() target.page() //
target.type() target.type() //
target.url() target.url() //
target.worker() target.worker() //
// CDPSESSION // CDPSESSION
// The CDPSession instances are used to talk raw Chrome Devtools Protocol // The CDPSession instances are used to talk raw Chrome Devtools Protocol
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-cdpsession // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-cdpsession
cdpSession.detach() cdpSession.detach() //
cdpSession.send(method[, params]) cdpSession.send(method[, params]) //
// COVERAGE // COVERAGE
// Coverage gathers information about parts of JavaScript and CSS that were used by the page. // Coverage gathers information about parts of JavaScript and CSS that were used by the page.
// https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-coverage // https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-coverage
coverage.startCSSCoverage([options]) coverage.startCSSCoverage([options]) //
coverage.startJSCoverage([options]) coverage.startJSCoverage([options]) //
coverage.stopCSSCoverage() coverage.stopCSSCoverage() //
coverage.stopJSCoverage() coverage.stopJSCoverage() //