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.
I was working on something almost similar, mostly to create a browser agent, and LLMs are really good at writing playwright scripts compared to vanilla JS.
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.
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