xk6-browser
xk6-browser copied to clipboard
Unable to set up proxy
As the title suggests I am unable to initiate the xk6-browser using a proxy. I am aware that the README is a bit wrong on the way it defines the proxy, because proxy support through variables is still on TODO.
https://github.com/grafana/xk6-browser/blob/main/common/connection.go#L146
So currently the proxy value is in theory taken from the environment variables.
However when exporting them, a proxy is still not used. For example:
export http_proxy='http://proxy.net:43' export https_proxy='http://proxy.net:43' export HTTP_PROXY='http://proxy.net:43' export HTTPS_PROXY='http://proxy.net:43'
Is there any workaround for this issue?
Hi @asteriosgr,
This is for connecting to the Browser's WebSocket DevTools URL. Even if we set it, the browser wouldn't use it.
To fix this issue, I need some information from you. Could you tell me your motivation for using a proxy in this case? Is it about passing proxy information to the launched browser and letting the browser use the proxy?
Hi @inancgumus . I am trying to test a website using playwright. The website is accessible only through a specific proxy. With plain playwright, I am able to set up a proxy in the following way:
proxy: { server: PROXY},
However, with the xk6 browser, I tried setting proxy also as a chrome argument (flag), and also through the way it is mentioned in the README https://github.com/grafana/xk6-browser#launch-options . In both cases I was unable to establish connection to the PROXY. Then going through the code I noticed that you should try exporting it as an env variable, https://pkg.go.dev/net/http#ProxyFromEnvironment . Once again this did not do the trick.
So, TLDR, I simply need to access a website through a PROXY. However, I am unable to set up a proxy.
@asteriosgr, I can let you pass the proxy
options to the browser if that works for you (since we're also missing and not passing these options to the browser yet). Could you check whether you can access the website by launching chrome with these command-line arguments:
<path-to-your-chrome-executable> --proxy-server="<your-proxy-url-here>"
For example (chromium is my $PATH
environment variable):
chromium --proxy-server="https://myproxy:myproxyport"
Please launch Chrome with the proxy server argument and then head to your website.
Well as I mentioned earlier, I am starting chrome with the following args:
const browser = launcher.launch(‘chromium’, { headless: false, args: [--proxy-server=“http://myproxy:port”
,--no-sandbox
, ‘--ignore-certificate-errors’, ‘--incognito’], proxy: { server: myproxy:myport}});
Where myproxy and myport of course is the proxy value and the port number I am using.
Still using the chrome proxy argument, is not working.
Edit: A quick workaround is to set up a proxy at a system (OS) level. It works that way. However, this is not ideal for apparent reasons, so I would like to avoid that if possible.
@asteriosgr, sorry, I couldn't explain what I meant. My previous message was that instead of running via xk6-browser or Playwright, starting Chrome directly from the command line with the proxy arguments, going to the website behind a proxy, and telling me if it works that way. Then we can fix the args
option and let you test the website in your script too.
On my end, setting the --proxy-server
argument, is not doing anything in the local chrome browser.