Remix.run Logo
dataviz1000 5 days ago

I'm copying the Puppeteer / Playwright client API to run in a Chrome extension using the native Chrome extension APIs.

It is possible to run Playwright inside a Chrome extension, however, it requires the Chrome DevTools Protocol (CDP) to automate a browser which really hurts the user experience, is very slow, and opens security vulnerabilities. Chrome extension APIs can accomplish maybe ~85% of the same functionality as CDP or Webdriver BiDi -- it isn't complete because of security features which shouldn't be bypassed anyhow. For example, instead of calling a function in a content script with 'script.callFunction' with Webdriver BiDi in Playwright, a function is called with chrome.scripting.executeScript(). It will be 2 or 3 more weeks before I post a PoC.

This is following my work using VSCode's core libraries in a Chrome extension exactly as they are used in an Electron app to drive VSCode and Cursor. The important part is VSCode's IPC / RPC which allows all the execution contexts and remote runtimes to communicate with each other. [0] This solves many problems I have had in the past automating browsers with a Chrome extension.

[0] https://github.com/adam-s/doomberg-terminal

tech234a 5 days ago | parent [-]

Cool concept, would you expect this to be compatible with Firefox/Safari as well? Safari in particular would be useful as it doesn't natively support Puppeteer/Playwright.

dataviz1000 4 days ago | parent [-]

Absolutely. However, it is easier to start with just Chromium flavor of browsers.

The two important concepts from Puppeteer/Playwright are managing the lifecycle of pages (tabs) and frames and the other is using handles / locators.

There are a lot of limitations using the extension API in any browser instead of CDP / Webdriver BiDi. I'm curious, how would you use this idea?

tech234a 4 days ago | parent [-]

Could be cool for automated website UI testing/verification (check if certain text appears), perhaps also with network API events as well.

4 days ago | parent [-]
[deleted]