Why is my Selenium Docker image differing in behaviour when running locally vs when running on a host server?

I’ve been trying to deploy a NodeJS scraper selenium browser to docker, and host it on a dedicated server. When I run it locally, it works as intended. One of the problems I’ve encountered is that selenium can’t load an extension into the browser unless run headfully, so I’m using Xvfb – again, this works locally. I’m trying to add cookies to my driver to automate login after navigating to my desired url, which leads to an invalid cookie domain error:

Error in browser session: InvalidCookieDomainError: invalid cookie domain
  (Session info: chrome=124.0.6367.155)
    at Object.throwDecodedError (/app/node_modules/selenium-webdriver/lib/error.js:521:15)
    at parseHttpResponse (/app/node_modules/selenium-webdriver/lib/http.js:514:13)
    at Executor.execute (/app/node_modules/selenium-webdriver/lib/http.js:446:28)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Driver.execute (/app/node_modules/selenium-webdriver/lib/webdriver.js:740:17)

-> I fall back to logging in with a username and password if not, which again doesn’t work, and I time out with error:

error TimeoutError: Waiting for element to be located By(css selector, *[name="username"])
Wait timed out after 20081ms
    at /app/node_modules/selenium-webdriver/lib/webdriver.js:911:22
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  remoteStacktrace: ''

This error only occurs when trying to run the image on the external server. The following is my Dockerfile:

# BUILD COMMAND: docker buildx build --load --platform linux/amd64 -t <name here> .
FROM node:22.1-bullseye

WORKDIR /app

COPY package.json /app
RUN npm install

RUN apt-get update && apt-get install -y wget unzip

RUN wget -q https://storage.googleapis.com/chrome-for-testing-public/124.0.6367.91/linux64/chromedriver-linux64.zip
RUN unzip chromedriver-linux64.zip
RUN mv chromedriver-linux64/chromedriver /usr/bin/chromedriver

RUN apt install libnss3-dev libgdk-pixbuf2.0-dev libgtk-3-dev libxss-dev libasound2 -y

RUN apt-get install -y xvfb

RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb 
RUN apt-get install -y ./google-chrome-stable_current_amd64.deb


COPY index.js /app
COPY chromeExt /app/chromeExt

CMD ["node", "index.js"]

And my driver options:

options.windowSize({ width: 1400, height: 800 });
options.addArguments('--lang=en-US');
// Load chrome ext from ./chromeExt
options.addArguments('--load-extension=' + path.resolve(__dirname, './chromeExt'));
options.addArguments('--remote-debugging-pipe');
options.addArguments('--disable-gpu');
options.addArguments('--no-sandbox');

Has anyone encountered this issue, and can offer guidance? Thanks in advance!

I’ve tried running it headless, which doesn’t support loading chrome extensions. I’m sure I’m just missing one piece of this. Thanks again!

New contributor

Gabriel Schull is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật