It is easy to use proxy globally for the puppeteer instance, but there is a trick to use proxy on a per-page basis.
Puppeteer allows you to automate everything you can do in the browser manually and even more. There are cases when you need to use a proxy. It is easy to use proxy globally for the puppeteer instance, but there is a trick to use proxy on a per-page basis.
We are going to use an excellent plugin puppeteer-page-proxy to solve the problem with proxy per page.
The plugin supports:
proxy per page and proxy per request;
http, https, socks4 and socks5 proxies;
authentication;
and cookies.
Install:
Then you can import the library and use proxy on per-page basis:
In this example I take a screenshot through proxy.
Authentication
To use authentication with proxying, you need to specify user and password in your proxy connection URL:
Proxy per request
You can go further and proxy on per request basis:
This example is not different from the regular usage because we proxy every page request. But! Imagine you don’t want to load your proxy bandwidth and skip proxying images. This way, it becomes more valuable:
The plugin covers as many cases as you can image.
Proxy taking screenshots with API
If, in your case, you want to take screenshots or render HTML and you are OK with saving time and money, you can use our screenshot API with proxy to take screenshots.