by dataviz1000 · 1y ago · 0 comments
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.
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?