jlesage / docker-firefox

Docker container for Firefox
MIT License
1.61k stars 288 forks source link

Connecting to instance without Proxy? #154

Open j-mendez opened 1 year ago

j-mendez commented 1 year ago

Currently to interact with the firefox image you need to directly use the browser. If you were to start the container and try to connect using CDP or try to get the /version/json for the websocket connection the request will fail since localhost is not being forwarded. The only workaround at the moment is to use a proxy.

jlesage commented 1 year ago

I've done a similar comment done in #121:

The CDP interface should use a different port than 5800 (the one used by the container to display Firefox UI).

Also, from what I understand, CDP interface listens only on localhost (127.0.0.1). That means that if you create the container with the default bridge network, you can access the CDP interface only when inside the container. The other solution is to create the container with the host network: in this case, you should be able to access the interface from the host running the container.

j-mendez commented 1 year ago

@jlesage thank you for the detailed explanation. I wonder why we can only use the physical address on firefox by default ( extra security ?). On chrome CDP works outside the container. The network host may work in the case here. I am mainly trying to solve it for being able to run on a load balancer with AWS Fargate split FireFox tasks to scale elastically.

jlesage commented 1 year ago

On chrome CDP works outside the container.

Do you have an example ? I can try to see how it works, maybe I'm missing something.

j-mendez commented 1 year ago

@jlesage Yes, the easiest example would be to use the A11yWatch CLI to get a instance up of the chrome container I am working with https://github.com/a11ywatch/a11ywatch.

npm i a11ywatch-cli -g.

  1. a11ywatch build - init build the project.
  2. a11ywatch start - start the project api backend via docker.
  3. a11ywatch scan --url https://a11ywatch.com - optional if you need to test to see the reports, uses chrome.

containers open 9222 for chrome. The gRPC instance pagemind can connect outside.

Crawl method that connects from one instance to another. The firefox method does not work atm when using from docker.

If you need a firefox example a quick one can be set up by adding the firefox service to the dev-compose. It requires checking out all of the projects locally unfortunately.

j-mendez commented 1 year ago

https://github.com/a11ywatch/firefox has sozu as a proxy on startup and the WebSocket connection upgrades fail over puppeteer with nginx or sozu ( I think I was using the same port that nginx was using could have been an issue ). Trying to avoid using proxies unless needed.