Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use a proxy in Puppeteer for Firefox?

Is there a way to configure Puppeteer to use a proxy with Firefox, without manually having to adjust my operating system's proxy settings?

I am able to accomplish this in Chrome by using the command line argument args: [ '--proxy-server=http://0.0.0.0:0000' ], but Firefox doesn't seem to have this capability.

like image 536
diogenes Avatar asked Nov 17 '25 02:11

diogenes


2 Answers

Proxies in Firefox can be configured via preferences. Here a list of these with their default values:

pref("network.proxy.ftp",                   "");
pref("network.proxy.ftp_port",              0);
pref("network.proxy.http",                  "");
pref("network.proxy.http_port",             0);
pref("network.proxy.ssl",                   "");
pref("network.proxy.ssl_port",              0);
pref("network.proxy.socks",                 "");
pref("network.proxy.socks_port",            0);
pref("network.proxy.socks_version",         5);
pref("network.proxy.proxy_over_tls",        true);
pref("network.proxy.no_proxies_on",         "");

To actually make use of them install the official puppeteer node.js package with Firefox as selected product (note that puppeteer-firefox is deprecated). Then preferences can be specified via extraPrefsFirefox for the call to puppeteer.launch(). Here an example for the necessary steps from the puppeteer repository.

like image 170
Henrik Avatar answered Nov 18 '25 19:11

Henrik


Unfortunately, there is no 'proxy-server' argument in Firefox.

However, you can intercept the request and set a proxy with the puppeteer-proxy library.

Here is an example.

import puppeteer from 'puppeteer';
import { proxyRequest } from 'puppeteer-proxy';

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  await page.setRequestInterception(true);

  page.on('request', async (request) => {
    await proxyRequest({
      page,
      proxyUrl: 'http://127.0.0.1:3000',
      request,
    });
  });

  await page.goto('http://gajus.com');
})();

It will work in Chrome and Firefox as well.

like image 25
Yevhen Laichenkov Avatar answered Nov 18 '25 20:11

Yevhen Laichenkov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!