allow to use proxying without authorization
Hi,
First thank you for the package is very nice and useful!
for my use scenario I need to use some free proxies that doesn't require authentication (username, & password).
possible solutions I found for this is:
- here https://github.com/apify/proxy-chain/blob/e4367ce73f16fd0d76cf617e80dd7bf541305fe5/src/anonymize_proxy.ts#L47 to remove this condition.
- add property for in options that let me use the proxy without username and password.
thanks a lot!
So you'd like the anonymizeProxy function to return a URL like http://localhost:8453 instead of the password-less http://myproxy.example.com ? Please can you explain why, what difference does it make to you?
I using external free proxies without authorization - on tunnel, for example the browser loaded with proxy 127.0.0.1:8080 always and the tunnel changed on the fly...
Hi Jan, do you have any updates?
But why do you need the "anonymized" URL like http://127.0.0.1:8080, why don't you use the target free proxy URL? It just works too, no?
My need is to open a browser with http://127.0.0.1:8080 as a tunnel for switching proxies on the fly. When I want to use some proxy I use the proxy-chain that way I can switch between proxies as shown below:
import * as Puppeteer from 'puppeteer';
import * as proxyChain from 'proxy-chain';
let newProxyUrl = null;
let page = null;
(async () => {
const browser = await Puppeteer.launch({
headless: false,
args: [`--proxy-server=http://127.0.0.1:8080`], //the proxy is static, NOT CHANGED ANY MORE
});
page = await browser.newPage();
//first time set proxy
await switchProxy(
'http://username:passwored@proxyExample:port'
);
await page.goto('https://ifconfig.me/');
})();
async function switchProxy(proxy) {
console.log('switch IP to new one: ' + proxy);
if (newProxyUrl !== null)
await proxyChain.closeAnonymizedProxy(newProxyUrl, true);
newProxyUrl = await proxyChain.anonymizeProxy({ url: proxy, port: 8080 });
await page.goto('https://ifconfig.me/');
console.log(newProxyUrl);
}
function randomProxy() {
const proxyList = [
// example for proxy WITH username and password (works good)
'http://username:passwored@proxyExample:port',
// example for proxy WITHOUT username and password (throw exception)
'http://proxyExample:port',
];
switchProxy(proxyList[Math.floor(Math.random() * proxyList.length)]);
}
//this will change the proxy every minute
setInterval(randomProxy, 15000);
In the code example as shown above you can see that the tunnel is loaded only if I use proxy with username and password.
and that because the tunnel is not longer open and you return the proxy string as is (as it was provided, without processing the proxy tunnel).
Oh right, now I understand. Let us look into it. CC @szmarczak
Perhaps we could add an option that would also anonymize password-less proxy URLs, but not sure whether it's not overkill, as the caller might decide this for themselves. "anonymization" might refer to also hiding proxy hostname and password, so logically this would be correct.
Thanks you very much for the fast reply :) We are looking for the solution for the detailed scenario. Would love if you can update us for an estimation :)
Hi @avihaizanaa! I believe that the best solution would be to use ProxyChain.Server like so:
let upstreamProxyUrl = 'http://proxy.example.com:2222';
const switchProxy = proxy => {
upstreamProxyUrl = proxy;
// Force browsers to update the connections in order not to use the old proxy anymore
server.closeConnections();
};
const server = new ProxyChain.Server({
port: 8000,
prepareRequestFunction: () => {
return {
upstreamProxyUrl,
};
},
});
await server.listen();
This way you don't need to close & start the server over and over again.
https://github.com/apify/proxy-chain/pull/296
@anton-lsports Can you explain your comment a bit more please? I'm confused.
Hi @szmarczak, We will test the solution you gave us, but in the mean time we would like if you can check the PR we send as a solution suggestion. https://github.com/apify/proxy-chain/pull/296 thanks!
Hello, can you further comment on the Pull Request? And also comment what forceTunnel means in the code. Thanks
Closing as @szmarczak's suggestion in https://github.com/apify/proxy-chain/issues/288#issuecomment-1232787186 should be enough for this usecase.