question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to connect with proxy server

See original GitHub issue
Component Version
Operating system win 10
Node.js 12.16.1
Chrome/Chromium/… Chrome 87 (latest), using Chrome Launcher 0.13.4
chrome-remote-interface 0.28.2

Is Chrome running in a container? YES / NO

Attempting to connect to webpages through a free proxy server, using sites like:

https://www.proxynova.com/proxy-server-list http://www.freeproxylists.net/ https://free-proxy-list.net/

For this I’ve been using Chrome Launcher to set up the headless chrome instance, and then some really basic chrome remote interface stuff to test that the IP address has changed. I’m checking my IP address of the headless chrome instance using this website https://whatismyipaddress.com/. Following similarly to https://www.youtube.com/watch?v=wAyocwixpFA.

Code that I’m using to connect, use proxy and check IP

const chromeLauncher = require("chrome-launcher");
const CDP = require("chrome-remote-interface");
const proxy = "--proxy-server=PROXY_IP:PROXY_PORT";

(async function() {

    // launch chrome running on debug port 9222 (for chrome-remote-interface), with headless and proxy flags

    let chrome = await chromeLauncher.launch({
        port: 9222, 
        chromeFlags: ["--disable-gpu", "--headless", "--enable-logging", proxy]
    });

    let client = await CDP();

    let Page = client.Page;
    await Page.enable();

    let Runtime = client.Runtime;
    await Runtime.enable();

    // go to website and wait until page has loaded

    await Page.navigate({ url: "https://whatismyipaddress.com/"});
    await Page.loadEventFired();

    // scrape IP address from website

    const { result: { value }} = await Runtime.evaluage({
        expression: "document.querySelectorAll('#ipv4 > a')[0].innerHTML;"
    });

    // return the scraped ip address eg; (255.255.255.255)

    console.log("IP Address:", value);
})();

In this case with and without using the chrome flag --proxy-server=PROXY_IP:PROXY_PORT, I always retrieve my IP address, and never get the address of any of the proxy servers. I’ve also tried different variations of the --proxy-server option: You can find the three here https://www.chromium.org/developers/design-documents/network-settings#TOC-Command-line-options-for-proxy-settings

–proxy-server=PROXY_IP:PROXY_PORT eg; (–proxy-server=255.255.255.255:8080) –proxy-server=SCHEME=PROXY_IP:PROXY_PORT eg; (–proxy-server=https=255.255.255.255:8080) –proxy-server=LINK_TO_PROXY eg; (https://255.255.255.255:8080)

I’ve tried all of these, including adding the “double quotes” around the values, and all have given me the same result, I’ve also tried using a random string (in attempt to get an error) for the proxy ip, and again get the same result. I’m not sure whether this is a chrome-launcher issue or a chrome-remote-interface issue either. In any case, I never recieve an error from chrome-launcher or chrome-remote-interface, and the script just spits out my IP address.

Any help with this would be greatly appreciated, if you need any more information I can provide this asap.

EDIT: For anyone with the same issue, I was able to solve this issue using --proxy-server=PROXY_IP:PROXY_PORT eg; ( --proxy-server=255.255.255.255:8080 ), and the security code provided below by cyrus-and. I would sugest using a free proxy for testing from http://www.freeproxylists.net/, atleast proxies from there worked for me

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
cyrus-andcommented, Jan 9, 2021

Sorry for the late reply, here you go, this should work:

const CDP = require('chrome-remote-interface');

const PROXY_AUTH = {
    username: 'user',
    password: 'password'
};

CDP(async (client) => {
    const {Fetch, Network, Page} = client;

    // provide credentials when needed
    Fetch.authRequired(({requestId}) => {
        Fetch.continueWithAuth({
            requestId,
            authChallengeResponse: {
                response: 'ProvideCredentials',
                ...PROXY_AUTH
            }
        });
    });

    // just continue any other requests
    Fetch.requestPaused(({requestId}) => {
        Fetch.continueRequest({requestId});
    });

    // enable requests interception
    await Fetch.enable({handleAuthRequests: true});

    // usual demo code below...

    Network.requestWillBeSent((params) => {
        console.log(params.request.url);
    });

    try {
        await Network.enable();
        await Page.enable();
        await Page.navigate({url: 'https://github.com'});
        await Page.loadEventFired();
    } catch (err) {
        console.error(err);
    } finally {
        client.close();
    }
}).on('error', (err) => {
    console.error(err);
});
0reactions
SwitchGMcommented, Jan 9, 2021

Exactly what I was looking for, thank you again for the assistance

Read more comments on GitHub >

github_iconTop Results From Across the Web

FIX: Unable to Connect to proxy server in Windows 10/11
Open Internet Options window. · Go to the Connections tab and click the LAN Settings button. Unable to connect to proxy server Chrome...
Read more >
How to Fix Unable to Connect to the Proxy Server
Open the start menu · Open settings · Open on network and internet · Click on the reset network · Click on the...
Read more >
WiFi Troubleshooting - Unable to connect to proxy server
Go to Settings > Internet Options > Connections > LAN Settings · Under Proxy Server, uncheck the box next to "Use a proxy...
Read more >
How to fix "There is something wrong with the proxy server ...
Method 3: Checking your Proxy Settings · On your keyboard, press Windows Key+S. · Type “control panel” (no quotes), then hit Enter. ·...
Read more >
How to Fix “There Is Something Wrong With the Proxy ...
2. Restore Your Proxy Server to Its Default Settings · Go to the Control Panel. · Click on Internet Options. · Click on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found