npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

playwright-crx

v0.6.0

Published

This package contains the [Chrome Extensions](https://developer.chrome.com/docs/extensions/) flavor of the [Playwright](http://github.com/microsoft/playwright) library.

Downloads

118

Readme

Playwright CRX

This package contains the Chrome Extensions flavor of the Playwright library.

For that, it relies on chrome.debugger to implement playwright's ConnectionTransport interface.

NOTE: If you want to write end-to-end tests, you should use @playwright/test instead.

Recorder / Player

Note: This extension is available in Chrome Web Store.

A small demo of recorder and player in action:

Playwright CRX Recorder / Player

It provides playwright recorder (the same used in playwright codegen) bundled as a chrome extension, with no other dependencies. This way, with your normal chrome / chromium / edge browser, you can record playwright scripts in your prefered language.

In terms of chrome extension functionality, it provides:

  • action button for attaching current tab into recorder (it opens the recorder if it's closed)
  • context menu for the same purpose
  • pages must be explicitly attached to be recordable, except if they are opened from already attached pages
  • closing the recorder window will detach all pages and uninstall injected scripts (highlights and event listeners)
  • a player that will run the recorded instructions, in any supported language*
    • it actually doesn't run Java, Python or C#, but it uses an internal JSONL format to know which instructions it needs to run and how to map them into the current selected code. This way, it can highlight the lines being executed.

API

It's possible to use playwright-crx as a library to create new chrome extensions.

Here's a simple example of a background service worker for a chrome extension using playwright-crx:

import { crx, expect } from 'playwright-crx/test';

// if you don't need assertions, you can reduce the bundle size by importing crx from playwright-crx
// import { crx } from 'playwright-crx';

chrome.action.onClicked.addListener(async ({ id: tabId }) => {
  const crxApp = await crx.start({ slowMo: 500 });

  try {
    // tries to connect to the active tab, or creates a new one
    const page = await crxApp.attach(tabId!).catch(() => crxApp.newPage());

    await page.goto('https://demo.playwright.dev/todomvc/#/');
    await page.getByPlaceholder('What needs to be done?').click();
    await page.getByPlaceholder('What needs to be done?').fill('Hello World!');
    await page.getByPlaceholder('What needs to be done?').press('Enter');

    // assertions work too
    await expect(page.getByTestId('todo-title')).toHaveText('Hello World!');
  } finally {
    // page stays open, but no longer controlled by playwright
    await crxApp.detach(page);
    // releases chrome.debugger
    await crxApp.close();
  }
});

A more complete example can be found in examples/todomvc-crx.

Build

To build playwright-crx:

npm ci
npm run build

Updating Playwright

Playwright is nested as a git subtree.

To update it, just run the following command (replace v1.40.0 with the desired release tag):

git subtree pull --prefix=playwright [email protected]:microsoft/playwright.git v1.40.0 --squash