Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSelenium using Docker and Firefox, Browser Not Opening on Mac

I am trying to use RSelenium with Docker, and everything appears to be working, except that I cannot see the firefox browser. I don't think there is anything in my code requiring it to be headless, but that must be the case. Is there a way to make it viewable like it was when using RSelenium::startServer() ?

I installed docker via the instructions in this article, https://www.raynergobran.com/2017/01/rselenium-mac-update/

I went to terminal and typed in: docker run -d -p 4445:4444 selenium/standalone-firefox without issue.

I go to R and run this code:

library(RSelenium)
remDr <- remoteDriver(port=4445L, browserName = "firefox")
remDr$open()
remDr$getStatus()
remDr$navigate("https://www.google.com/")
remDr$getCurrentUrl()

The output from the last command is as expected:

[[1]]
[1] "https://www.google.com/"

When looking at the output after remDr$open(), headless is set to false:

[1] "Connecting to remote server"
$`moz:profile`
[1] "/tmp/rust_mozprofile.EQnMfPLPKS4l"

$rotatable
[1] FALSE

$timeouts
$timeouts$implicit
[1] 0

$timeouts$pageLoad
[1] 300000

$timeouts$script
[1] 30000


$pageLoadStrategy
[1] "normal"

$`moz:headless`
[1] FALSE

$`moz:accessibilityChecks`
[1] FALSE

$acceptInsecureCerts
[1] FALSE

$browserVersion
[1] "58.0.2"

$platformVersion
[1] "4.9.60-linuxkit-aufs"

$`moz:processID`
[1] 741

$browserName
[1] "firefox"

$platformName
[1] "linux"

$`moz:webdriverClick`
[1] TRUE

$webdriver.remote.sessionid
[1] "bfa2d87a-67d3-4e5e-838b-e6894a90dd5c"

$id
[1] "bfa2d87a-67d3-4e5e-838b-e6894a90dd5c"

Again, the browser is not viewable on my screen but I'd like it to be.

I am running El Capitan 10.11.6.

Thank you for your help.

like image 311
mks212 Avatar asked Mar 12 '26 16:03

mks212


2 Answers

I think the issue seems to with your expectations to see the browser. You are launching the browser inside a docker container. The docker container doesn't have a UI, the browser is launched inside the container instance and not on your machine which initiates the call

The default selenium/standalone-firefox doesn't allow viewing of the browser. If you need to view the browser then you need to use the selenium/standalone-firefox-debug image. This image hosts VNC at port 5900 of the container. You will run it using below

docker run -d -p 4445:4444 -p 5900:5900 selenium/standalone-firefox-debug

Then you will execute your code and connect to 127.0.0.1:5900 using a VNC Viewer. It will ask for a password which is secret by default.

Then you will see the browser in that VNC

VNC View

The above is the result of running the code you had in question

like image 60
Tarun Lalwani Avatar answered Mar 15 '26 08:03

Tarun Lalwani


Here is a Dockerfile which may be useful to you https://github.com/jessfraz/dockerfiles/blob/master/chrome/stable/Dockerfile

inlined here for convenience:

# Run Chrome in a container
#
# docker run -it \
#   --net host \ # may as well YOLO
#   --cpuset-cpus 0 \ # control the cpu
#   --memory 512mb \ # max memory it can use
#   -v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket
#   -e DISPLAY=unix$DISPLAY \
#   -v $HOME/Downloads:/home/chrome/Downloads \
#   -v $HOME/.config/google-chrome/:/data \ # if you want to save state
#   --security-opt seccomp=$HOME/chrome.json \
#   --device /dev/snd \ # so we have sound
#   --device /dev/dri \
#   -v /dev/shm:/dev/shm \
#   --name chrome \
#   jess/chrome
#
# You will want the custom seccomp profile:
#   wget https://raw.githubusercontent.com/jfrazelle/dotfiles/master/etc/docker/seccomp/chrome.json -O ~/chrome.json

# Base docker image
FROM debian:sid
LABEL maintainer "Jessie Frazelle <[email protected]>"

ADD https://dl.google.com/linux/direct/google-talkplugin_current_amd64.deb /src/google-talkplugin_current_amd64.deb

# Install Chrome
RUN apt-get update && apt-get install -y \
    libcanberra-gtk* \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    hicolor-icon-theme \
    libgl1-mesa-dri \
    libgl1-mesa-glx \
    libpango1.0-0 \
    libpulse0 \
    libv4l-0 \
    fonts-symbola \
    --no-install-recommends \
    && curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list \
    && apt-get update && apt-get install -y \
    google-chrome-stable \
    --no-install-recommends \
    && dpkg -i '/src/google-talkplugin_current_amd64.deb' \
    && apt-get purge --auto-remove -y curl \
    && rm -rf /var/lib/apt/lists/* \
    && rm -rf /src/*.deb

# Add chrome user
RUN groupadd -r chrome && useradd -r -g chrome -G audio,video chrome \
    && mkdir -p /home/chrome/Downloads && chown -R chrome:chrome /home/chrome

COPY local.conf /etc/fonts/local.conf

# Run Chrome as non privileged user
USER chrome

# Autorun chrome
ENTRYPOINT [ "google-chrome" ]
CMD [ "--user-data-dir=/data" ]

Additionally, this project https://github.com/sameersbn/docker-browser-box

Inlined Dockerfile for convenience.

FROM sameersbn/ubuntu:14.04.20170123

ENV TOR_VERSION=6.5 \
    TOR_FINGERPRINT=0x4E2C6E8793298290

RUN wget -q -O - "https://dl-ssl.google.com/linux/linux_signing_key.pub" | sudo apt-key add - \
 && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
 && mkdir ~/.gnupg \
 && gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys ${TOR_FINGERPRINT} \
 && gpg --fingerprint ${TOR_FINGERPRINT} | grep -q "Key fingerprint = EF6E 286D DA85 EA2A 4BA7  DE68 4E2C 6E87 9329 8290" \
 && apt-get update \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y xz-utils file locales dbus-x11 pulseaudio dmz-cursor-theme curl \
      fonts-dejavu fonts-liberation hicolor-icon-theme \
      libcanberra-gtk3-0 libcanberra-gtk-module libcanberra-gtk3-module \
      libasound2 libglib2.0 libgtk2.0-0 libdbus-glib-1-2 libxt6 libexif12 \
      libgl1-mesa-glx libgl1-mesa-dri libstdc++6 nvidia-346 \
      gstreamer-1.0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
      gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav \
      google-chrome-stable chromium-browser firefox \
 && update-locale LANG=C.UTF-8 LC_MESSAGES=POSIX \
 && mkdir -p /usr/lib/tor-browser \
 && wget -O /tmp/tor-browser-linux64-${TOR_VERSION}_en-US.tar.xz  https://www.torproject.org/dist/torbrowser/${TOR_VERSION}/tor-browser-linux64-${TOR_VERSION}_en-US.tar.xz \
 && wget -O /tmp/tor-browser-linux64-${TOR_VERSION}_en-US.tar.xz.asc https://www.torproject.org/dist/torbrowser/${TOR_VERSION}/tor-browser-linux64-${TOR_VERSION}_en-US.tar.xz.asc \
 && gpg /tmp/tor-browser-linux64-${TOR_VERSION}_en-US.tar.xz.asc \
 && tar -Jvxf /tmp/tor-browser-linux64-${TOR_VERSION}_en-US.tar.xz --strip=1 -C /usr/lib/tor-browser \
 && ln -sf /usr/lib/tor-browser/Browser/start-tor-browser /usr/bin/tor-browser \
 && rm -rf /tmp/tor-browser-linux64-${TOR_VERSION}_en-US.tar.xz \
 && rm -rf ~/.gnupg \
 && rm -rf /var/lib/apt/lists/*

COPY scripts/ /var/cache/browser-box/
COPY entrypoint.sh /sbin/entrypoint.sh
COPY confs/local.conf /etc/fonts/local.conf
RUN chmod 755 /sbin/entrypoint.sh

ENTRYPOINT ["/sbin/entrypoint.sh"]
like image 22
dwright Avatar answered Mar 15 '26 10:03

dwright



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!