Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use different ip addresses in puppeteer requests

Tags:

I have multiple ip interfaces in my server and I can't find how to force puppeteer to use them in its requests

I am using node v10.15.0 and puppeteer 1.11.0

like image 929
Imad Avatar asked Apr 19 '19 09:04

Imad


2 Answers

You can use the flag --netifs-to-ignore when launching the browser to specify which interfaces should be ignored by Chrome. Quote from the List of Chromium Command Line Switches:

--netifs-to-ignore: List of network interfaces to ignore. Ignored interfaces will not be used for network connectivity

You can use the argument like this when launching the browser:

const browser = await puppeteer.launch({
    args: ['--netifs-to-ignore=INTERFACE_TO_IGNORE']
});
like image 190
Thomas Dondorf Avatar answered Sep 27 '22 20:09

Thomas Dondorf


Maybe this will help. You can see the full code here

'use strict';

const puppeteer = require('puppeteer');

(async() => {
  const browser = await puppeteer.launch({
    // Launch chromium using a proxy server on port 9876.
    // More on proxying:
    //    https://www.chromium.org/developers/design-documents/network-settings
    args: [ '--proxy-server=127.0.0.1:9876' ]
  });
  const page = await browser.newPage();
  await page.goto('https://google.com');
  await browser.close();
})();
like image 21
Divyesh Puri Avatar answered Sep 27 '22 18:09

Divyesh Puri