Skip to content

wix-playground/puppeteer-direct

This branch is 4 commits ahead of noamr/puppeteer-direct:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

42f823a · Jun 27, 2018

History

17 Commits
Dec 6, 2017
Dec 6, 2017
Dec 4, 2017
Dec 5, 2017
Dec 4, 2017
Jun 27, 2018
Dec 5, 2017
Dec 5, 2017

Repository files navigation

puppeteer-direct

puppeteer-direct is a small library that allows easy access to in-browser JS when using puppeteer.

The problem it comes to solve

Puppeteer (headless-chrome for node.js) gives access to JS inside the browser, using JSHandles. However the code that runs them is a bit cumbersome, you keep have to separating between the node context and the browser context.

Code in puppeteer looks like this:

     const text = await page.evaluate(id => window.document.querySelector(`#${id}`).innerText, id)

The node-side parameters have to be manually passed to the browser context.

Code with puppeteer-direct looks like this:

     const text = await getWindowHandle(page).document.querySelector(`#${id}`).innerText

API

puppeteer-direct exposes two functions:

     directJSHandle(Puppeteer.JSHandle | Promise<Puppeteer.JSHandle]>): PuppeteerDirectHandle

This function wraps a puppeteer JSHandle, with a proxy that works with direct JS access.

     getWindowHandle(Puppeteer.Page): PuppeteerDirectHandle

getWindowHandle wraps the window handle for a specific page.

About

Direct access to Javascript handles in puppeteer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%