Kees de Kooter
Kees de Kooter

Reputation: 7195

Is it possible to disable websockets with Puppeteer?

I am using puppeteer to create screenshots of websites and I want to eleminate all unneccesary traffic. Besides blocking analytics sites and the like I want to block websocket traffic as well.

I was not able to find something in the puppeteer API. Is there maybe a startup argument for this?

Upvotes: 3

Views: 2124

Answers (1)

browserless
browserless

Reputation: 2142

You should be looking for Upgrade headers in http requests. Puppeteer has an API for intercepting requests here, however it's not well documented on what gets passed into that function, so you might have to inspect/debug that out a bit.

In short, all websocket requests start with an HTTP request with an Upgrade header as a handshake of sorts. If you can reject those requests then the following websocket request shouldn't ever happen.

Upvotes: 6

Related Questions