Pupperteer1.9.0文档(中文版)

大纲

  • Puppeteer v1.9.0
  • 版本说明
  • 概要
  • puppeteer和puppeteer-core比较
  • 环境变量
  • 错误句柄
  • 使用Chrome扩展运行
  • class: Puppeteer since v0.9.0
    • puppeteer.connect(options) since v0.9.0
    • puppeteer.createBrowserFetcher([options]) since v1.1.0
    • puppeteer.defaultArgs([options]) since v1.0.0
    • puppeteer.executablePath() since v0.11.0
    • puppeteer.launch([options]) since v0.9.0
  • class: BrowserFetcher since v1.1.0
    • browserFetcher.canDownload(revision) since v1.1.0
    • browserFetcher.download(revision[, progressCallback]) since v1.1.0
    • browserFetcher.localRevisions() since v1.1.0
    • browserFetcher.platform() since v1.1.0
    • browserFetcher.remove(revision) since v1.1.0
    • browserFetcher.revisionInfo(revision) since v1.1.0
  • class: Browser since v0.9.0
    • browser.on(‘disconnected’) since v0.13.0
    • browser.on(‘targetchanged’) since v0.13.0
    • browser.on(‘targetcreated’) since v0.13.0
    • browser.on(‘targetdestroyed’) since v0.13.0
    • browser.browserContexts() since v1.5.0
    • browser.close() since v0.9.0
    • browser.createIncognitoBrowserContext() since v1.5.0
    • browser.defaultBrowserContext() since v1.8.0
    • browser.disconnect() since v0.13.0
    • browser.newPage() since v0.9.0
    • browser.pages() since v0.13.0
    • browser.process() since v1.0.0
    • browser.target() new in v1.9.0
    • browser.targets() since v0.13.0
    • browser.userAgent() since v1.0.0
    • browser.version() since v0.9.0
    • browser.wsEndpoint() since v0.9.0
  • class: BrowserContext
    • browserContext.on(‘targetchanged’)
    • browserContext.on(‘targetcreated’)
    • browserContext.on(‘targetdestroyed’)
    • browserContext.browser()
    • browserContext.clearPermissionOverrides()
    • browserContext.close()
    • browserContext.isIncognito()
    • browserContext.newPage()
    • browserContext.overridePermissions(origin, permissions)
    • browserContext.pages()
    • browserContext.targets()
  • class: Page
    • page.on(‘close’)
    • page.on(‘console’)
    • page.on(‘dialog’)
    • page.on(‘domcontentloaded’)
    • page.on(‘error’)
    • page.on(‘frameattached’)
    • page.on(‘framedetached’)
    • page.on(‘framenavigated’)
    • page.on(‘load’)
    • page.on(‘metrics’)
    • page.on(‘pageerror’)
    • page.on(‘request’)
    • page.on(‘requestfailed’)
    • page.on(‘requestfinished’)
    • page.on(‘response’)
    • page.on(‘workercreated’)
    • page.on(‘workerdestroyed’)
    • page.coverage
    • page.keyboard
    • page.mouse
    • page.touchscreen
    • page.tracing
    • page.$(selector)
    • page.$$(selector)
    • page.$eval(selector, pageFunction[, …args])
    • page.$x(expression)
    • page.addScriptTag(options)
    • page.addStyleTag(options)
    • page.authenticate(credentials)
    • page.bringToFront()
    • page.browser()
    • page.click(selector[, options])
    • page.close(options)
    • page.content()
    • page.cookies(…urls)
    • page.deleteCookie(…cookies)
    • page.emulate(options)
    • page.emulateMedia(mediaType)
    • page.evaluate(pageFunction, …args)
    • page.evaluateHandle(pageFunction, …args)
    • page.evaluateOnNewDocument(pageFunction, …args)
    • page.exposeFunction(name, puppeteerFunction)
    • page.focus(selector)
    • page.frames()
    • page.goBack(options)
    • page.goForward(options)
    • page.goto(url, options)
    • page.hover(selector)
    • page.isClosed()
    • page.mainFrame()
    • page.metrics()
    • page.pdf(options)
    • page.queryObjects(prototypeHandle)
    • page.reload(options)
    • page.screenshot([options])
    • page.select(selector, …values)
    • page.setBypassCSP(enabled)
    • page.setCacheEnabled(enabled)
    • page.setContent(html)
    • page.setCookie(…cookies)
    • page.setDefaultNavigationTimeout(timeout)
    • page.setExtraHTTPHeaders(headers)
    • page.setGeolocation(options)
    • page.setJavaScriptEnabled(enabled)
    • page.setOfflineMode(enabled)
    • page.setRequestInterception(value)
    • page.setUserAgent(userAgent)
    • page.setViewport(viewport)
    • page.tap(selector)
    • page.target()
    • page.title()
    • page.type(selector, text[, options])
    • page.url()
    • page.viewport()
    • page.waitFor(selectorOrFunctionOrTimeout[, options[, …args]])
    • page.waitForFunction(pageFunction[, options[, …args]])
    • page.waitForNavigation(options)
    • page.waitForRequest(urlOrPredicate, options)
    • page.waitForResponse(urlOrPredicate, options)
    • page.waitForSelector(selector[, options])
    • page.waitForXPath(xpath[, options])
    • page.workers()
  • class: Worker
    • worker.evaluate(pageFunction, …args)
    • worker.evaluateHandle(pageFunction, …args)
    • worker.executionContext()
    • worker.url()
  • class: Keyboard
    • keyboard.down(key[, options])
    • keyboard.press(key[, options])
    • keyboard.sendCharacter(char)
    • keyboard.type(text, options)
    • keyboard.up(key)
  • class: Mouse
    • mouse.click(x, y, [options])
    • mouse.down([options])
    • mouse.move(x, y, [options])
    • mouse.up([options])
  • class: Touchscreen
    • touchscreen.tap(x, y)
  • class: Tracing
    • tracing.start(options)
    • tracing.stop()
  • class: Dialog
    • dialog.accept([promptText])
    • dialog.defaultValue()
    • dialog.dismiss()
    • dialog.message()
    • dialog.type()
  • class: ConsoleMessage
    • consoleMessage.args()
    • consoleMessage.text()
    • consoleMessage.type()
  • class: Frame
    • frame.$(selector)
    • frame.$$(selector)
    • frame.$eval(selector, pageFunction[, …args])
    • frame.$x(expression)
    • frame.addScriptTag(options)
    • frame.addStyleTag(options)
    • frame.childFrames()
    • frame.click(selector[, options])
    • frame.content()
    • frame.evaluate(pageFunction, …args)
    • frame.evaluateHandle(pageFunction, …args)
    • frame.executionContext()
    • frame.focus(selector)
    • frame.goto(url, options)
    • frame.hover(selector)
    • frame.isDetached()
    • frame.name()
    • frame.parentFrame()
    • frame.select(selector, …values)
    • frame.setContent(html)
    • frame.tap(selector)
    • frame.title()
    • frame.type(selector, text[, options])
    • frame.url()
    • frame.waitFor(selectorOrFunctionOrTimeout[, options[, …args]])
    • frame.waitForFunction(pageFunction[, options[, …args]])
    • frame.waitForNavigation(options)
    • frame.waitForSelector(selector[, options])
    • frame.waitForXPath(xpath[, options])
  • class: ExecutionContext
    • executionContext.evaluate(pageFunction, …args)
    • executionContext.evaluateHandle(pageFunction, …args)
    • executionContext.frame()
    • executionContext.queryObjects(prototypeHandle)
  • class: JSHandle
    • jsHandle.asElement()
    • jsHandle.dispose()
    • jsHandle.executionContext()
    • jsHandle.getProperties()
    • jsHandle.getProperty(propertyName)
    • jsHandle.jsonValue()
  • class: ElementHandle
    • elementHandle.$(selector)
    • elementHandle.$$(selector)
    • elementHandle.$eval(selector, pageFunction, …args)
    • elementHandle.$x(expression)
    • elementHandle.asElement()
    • elementHandle.boundingBox()
    • elementHandle.boxModel()
    • elementHandle.click([options])
    • elementHandle.contentFrame()
    • elementHandle.dispose()
    • elementHandle.executionContext()
    • elementHandle.focus()
    • elementHandle.getProperties()
    • elementHandle.getProperty(propertyName)
    • elementHandle.hover()
    • elementHandle.isIntersectingViewport()
    • elementHandle.jsonValue()
    • elementHandle.press(key[, options])
    • elementHandle.screenshot([options])
    • elementHandle.tap()
    • elementHandle.toString()
    • elementHandle.type(text[, options])
    • elementHandle.uploadFile(…filePaths)
  • class: Request
    • request.abort([errorCode])
    • request.continue([overrides])
    • request.failure()
    • request.frame()
    • request.headers()
    • request.isNavigationRequest()
    • request.method()
    • request.postData()
    • request.redirectChain()
    • request.resourceType()
    • request.respond(response)
    • request.response()
    • request.url()
  • class: Response
    • response.buffer()
    • response.frame()
    • response.fromCache()
    • response.fromServiceWorker()
    • response.headers()
    • response.json()
    • response.ok()
    • response.remoteAddress()
    • response.request()
    • response.securityDetails()
    • response.status()
    • response.statusText()
    • response.text()
    • response.url()
  • class: SecurityDetails
    • securityDetails.issuer()
    • securityDetails.protocol()
    • securityDetails.subjectName()
    • securityDetails.validFrom()
    • securityDetails.validTo()
  • class: Target
    • target.browser()
    • target.browserContext()
    • target.createCDPSession()
    • target.opener()
    • target.page()
    • target.type()
    • target.url()
  • class: CDPSession
    • cdpSession.detach()
    • cdpSession.send(method[, params])
  • class: Coverage
    • coverage.startCSSCoverage(options)
    • coverage.startJSCoverage(options)
    • coverage.stopCSSCoverage()
    • coverage.stopJSCoverage()
    • class: TimeoutError –

概要

Puppeteer是一个提供了高级API并通过DevTools协议控制Chromium或Chrome的Node库。
Puppeteer API层级分明,且能反映出浏览器结构。

注: 在下面的图中,阴影实体是不出现在Pupperteer中的。

  • Puppeteer communicates with the browser using DevTools Protocol.
  • Browser instance can own multiple browser contexts.
  • BrowserContext instance defines a browsing session and can own multiple pages.
  • Page has at least one frame: main frame. There might be other frames created by iframe or frame tags.
  • Frame has at least one execution context – the default execution context – where the frame’s JavaScript is executed. A Frame might have additional execution contexts that are associated with extensions.
  • Worker has a single execution context and facilitates interacting with WebWorkers.

点击量:3

发表评论