Implement Puppeteer adapter for Polly that works in web workers in order to test extensions
Created by: marekweb
Add a new PuppeteerAdapter
for Polly for intercepting HTTP requests.
Current status: this is a draft PR and includes a temporary test script (run withts-node test-puppeteer-adapter.ts
). There are still some errors that happen while intercepting some types of requests.
Problem background
This solves the limitation that the default Puppeteer adapter for Polly does not work to intercept requests inside of web workers.
This limitation is blocking us from writing integration tests for Sourcegraph extensions.
Issues: #12194 #12180 PR which is blocked: #12195
Implementation
The new PuppeteerAdapter
uses puppeteer-interceptor
which is a wrapper around the Chrome DevTools Protocol.
It uses CDP's "Fetch domain" to intercept requests, which seems to be the best way to do it right now -- however this part of CDP is still flagged as experimental. Actually, I don't see any mention in the docs of it being experimental, so that may have been outdated information.
Alternatives to consider
Because puppeteer-interceptor
makes it a bit difficult the follow the flow of the code, and because it's a relatively small wrapper around CDP calls, we could use CDP directly instead and it might result in a cleaner solution. This could be a next step after we get this current solution working properly.
Update and resolution
The above is no longer current. I abandoned the puppeteer-interceptor
approach and implemented the alternative instead. See the update comments on this PR for the details.