@pipedream/browsers

1.0.3 • Public • Published

@pipedream/browsers package

This package abstracts the exact version pinning required for puppeteer & playwright to function properly in Pipedream code steps.

The index.mjs file reexports the specific pinned versions of puppeeter-core & playwright that are compatible with the same chromium version that is compatible with Lambda.

The reason this package is required is because NPM package versions can't be pinned in both playwright.app.mjs as an in-JS pin and pin over the playwright/package.json.

Therefore, it's not possible to offer both the pinned versions of chromium & playwright in both pre-built actions & in Node.js code steps.

Usage

This package exports two modules: puppeteer & playwright. Both modules share the same interface:

  • browser(opts?) - method to instantiate a new browser (returns a browser instance)
  • launch(opts?) - an alias to browser()
  • newPage() - creates a new page instance and returns both the page & browser

Note: After awaiting the browser instance with either puppeteer or playwright, make sure to close the browser at the end of your Node.js code step.

Puppeteer

import { puppeteer } from '@pipedream/browsers';

export default defineComponent({
  async run({steps, $}) {
    const browser = await puppeteer.browser();
    
    console.log(browser)
    // get page, perform actions, etc.

    await browser.close();
  },
})

Playwright

import { playwright } from '@pipedream/browsers';

export default defineComponent({
  async run({steps, $}) {
    const browser = await puppeteer.browser();
    const page = await browser.newPage();

    page.goto('https://pipedream.com');
    const title = await page.title()


    // Puppeteer requires you to close page context's before closing the browser itself
    // otherwise, the code step's execution will hang
    await page.context().close();
    await browser.close();
  },
})

Additional Resources

The reason why playwright is locked to an old version is because the latest Puppeeter Chromium version that works in a code step is chromium@121.

Package Sidebar

Install

npm i @pipedream/browsers

Weekly Downloads

195

Version

1.0.3

License

ISC

Unpacked Size

12.7 kB

Total Files

5

Last publish

Collaborators

  • ctrlaltdylan
  • celador
  • sacerdoti
  • dylburger
  • casret
  • tjk