2

So the problem is this: When opening some websites (e.g. https://iamstripes.com - most of the urls load correctly, this is a example that doesn't) in a docker image, the webpage is not rendered correctly and clearly there is some JavaScript missing from the page.

If the same website is opened in local browser, then everything is loaded correctly.

I've tried multiple docker images, from selenium based, "simple" docker images only with browser and even sause labs instances and all of them with the same result.

My first assumption is that I'm missing some sort of flag when starting the browser, but I've tried (almost) everything suggested in the interwebs without success :(

TL;DR
Browser (chrome, firefox) launched in docker fails to open the URL correctly
Browser (chrome, firefox) launched locally opens the URL correctly

example docker image:

docker run -d --name=firefox -p 5800:5800 -v /docker/appdata/firefox:/config:rw jlesage/firefox

and then you can open the docker browser using http://localhost:5800 in any browser window

Several browser options I tried when launching the browser in a docker selenium (missing some here):

--disable-security
--no-sandbox

Also in Chrome capabilities: excludeSwitches: ["enable-automation"]

I've tried with and without these settings, and in the case of Firefox even went directly into the browser about:config and changed some security parameters there directly as well, without success.

Shawn
  • 4,064
  • 2
  • 11
  • 23
Claudio Batista
  • 286
  • 1
  • 9
  • Hmm you could try using [Selenium-Profiles](https://github.com/kaliiiiiiiiii/Selenium-Profiles), which aims on (undetected) emulate a specific browser & device. – kaliiiiiiiii Mar 17 '23 at 12:58
  • Try to start it not headless. Maybe insert some sleeps to your test. Then you can inspect what is going wrong. Without more details, it is pretty hard to help you. – akop Mar 22 '23 at 17:36
  • I don't see any problems with that website in the docker contained firefox. It is rendered as in my desktop firefox browser. But there are a few error messages in the browser console. Maybe that will help to identify your problem. – Jens Dibbern Mar 23 '23 at 15:03
  • @akop, in headless or not headless the problem is reproduced. – Claudio Batista Mar 23 '23 at 15:52
  • @JensDibbern , Its insane that its working for you in the docker container. We have our containers running in gitlab (where the problem is reproduced) and we have run debugging in Mac (with intel and M1 processors) and in Windows all with the same result...So I'm curious about your env :). Regarding the errors, yes, there is a error there that is related (trying to use a instance of a object that fails to be created) but that is just a clear indication that the JS file (that creates that object) is not being loaded – Claudio Batista Mar 23 '23 at 16:03
  • What is the reason that the script wasn't loaded? Open the devtools and look what the webbrowser says. – akop Mar 23 '23 at 17:34
  • It doesn't say anything in the logs related with that. My suspicion is around permissions for the user that runs the browser but I was not able to prove that – Claudio Batista Mar 23 '23 at 18:02
  • @ClaudioBatista It is Win11/WSL2/Ubuntu20LTS – Jens Dibbern Mar 23 '23 at 23:07

2 Answers2

0
  1. Might be a problem with the host machine's network settings.
  2. Docker container has a different network config, hence launch the docker container with the --name=firefox --net=host to the docker command.
  3. Setup the DNS server manually in the docker container but add the --dns=<dns_ip> to the docker command.
Rithik Banerjee
  • 447
  • 4
  • 16
  • Thanks for the answer but its not a network issue, if I open the url directly in the browser the url (js) contents are shown correctly. – Claudio Batista Mar 23 '23 at 15:49
0

For anyone coming across this question with similar problems...

Default user agent includes references to Apple and Safari, and for some reason the website is enabling features that Chrome and Firefox simply do not support and fail to load the content correctly. That said, if you send the flag:

--user-agent=Chrome

Then the site will load correctly without any issue...

Claudio Batista
  • 286
  • 1
  • 9