Setting up SUID sandbox properly for Docker/Selenium with Headless Chrome

I am experimenting with running Selenium and headless Chrome in a Docker container for testing purposes.

Previously, I successfully ran Selenium in headless Chrome outside of my Docker container using the code snippet below in my .js file:

const client = webdriverio.remote({
   desiredCapabilities: {
   browserName: 'chrome',
   chromeOptions: {
     args: ['--headless', '--disable-gpu']
   },
   binary: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
   },
 baseUrl: CONFIG.host,
 logLevel: 'verbose',
 waitForTimeout: 3000
 })

However, I encountered issues when attempting to replicate this setup within my Docker container. I am using "FROM selenium/standalone-chrome" in my Dockerfile without any apparent problems. The challenge arises while trying to execute my Selenium tests within the container. Despite changing the binary_path in my .js file to /opt/google/chrome/google-chrome, the tests fail and the client initialization does not occur.

To troubleshoot, I attempted to directly run /opt/google/chrome/google-chrome to verify if Chrome is functioning within the container, but I received the following error:

[0711/005304.226472:ERROR:nacl_helper_linux.cc(311)] NaCl helper 
process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly      

As someone new to this topic and seeking assistance on Stack Overflow, I acknowledge that there may be fundamental aspects that I have overlooked.

Answer №1

Remember to add --no-sandbox

chromeOptions: {
  args: ['--headless', '--disable-gpu', '--no-sandbox']
},

You can see an example of this in action at this GitHub repository

Answer №2

When you encounter this error message...

[1003/144118.702053:ERROR:nacl_helper_linux.cc(310)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly

...it indicates that there is no setuid sandbox on your system, resulting in the program's inability to start/initiate a new Browsing Context, specifically a Chrome Browser session.


Fix

The simplest (though not recommended) solution is to run Chrome with just the namespace sandbox enabled by using the flag:

--disable-setuid-sandbox

This flag disables the setuid sandbox feature (Linux only). However, if used on a host lacking proper kernel support for the namespace sandbox, Chrome won't launch. Alternatively, you can utilize the following flag:

--no-sandbox

This flag turns off the sandbox for all normally sandboxed processes.

For instance:

chromeOptions: {
      args: ['--disable-setuid-sandbox', '--no-sandbox']
},

For more information, refer to this detailed discussion: Security Considerations - ChromeDriver - Webdriver for Chrome


In-depth Analysis

According to the documentation at Linux SUID Sandbox Development, requires a SUID helper binary to activate the sandbox on Linux. In most cases, you can install the appropriate sandbox by running the command:

build/update-linux-sandbox.sh

This utility will install the necessary sandbox in /usr/local/sbin and provide guidance on updating your .bashrc if needed.

However, there might be exceptions where an outdated setuid binary leads to messages like:

NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly 

Or

Running without the SUID sandbox!

In such scenarios, you should:

  • Build chrome_sandbox simultaneously when building chrome (
    ninja -C xxx chrome chrome_sandbox
    instead of ninja -C xxx chrome)
  • After compilation, execute update-linux-sandbox.sh.

    # needed if you build on NFS!
    sudo cp out/Debug/chrome_sandbox /usr/local/sbin/chrome-devel-sandbox
    sudo chown root:root /usr/local/sbin/chrome-devel-sandbox
    sudo chmod 4755 /usr/local/sbin/chrome-devel-sandbox
    
  • Lastly, add the following line to your ~/.bashrc (or .zshenv):

    export CHROME_DEVEL_SANDBOX=/usr/local/sbin/chrome-devel-sandbox        
    

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sending Data From Child Component to Parent Component in React Using a onClick Event

I am a newcomer to using React and am currently immersed in a React Rails application. <h1><img src={activity.image_url}/></h1> <p> {activity.name} </p> <p> Rating: {activity.rating} </p> ...

Encountered a problem with AngularUniversal prerendering: UnhandledPromiseRejectionWarning: Unable to locate NgModule metadata for 'class{}'

Objective The task may seem lengthy, but it's straightforward! Currently, I am utilizing Angular Universal for Server-Side Rendering (SSR) by following a tutorial. The Universal/express-engine has been installed, main.js is generated in the dist/pro ...

Tips for choosing a dynamically generated ajax element

Question for you: I have a snippet of HTML code that looks like this: <li class='entry'> <div class='entryContent'> <p class='entryText'>Entry text></p> <a href="#" c ...

Issues with Jquery and revslider functionality in React.js are causing problems

Just getting started with react.js and diving into the world of react development. Encountering an issue while converting static HTML to react.js where jQuery scripts only execute after manually refreshing the page, causing a slowdown in React speed. T ...

What could be the reason for the error I am experiencing?

import requests from selenium import webdriver chrome_options = webdriver.ChromeOptions() links = {"profile.default_content_setting_values.notifications": 2} chrome_options.add_experimental_option("prefs", links) driver = webdriver.Chrome(chrome_options=c ...

Integration of Cypress testing into Gitlab's CI/CD pipeline

Hi there, I'm looking to integrate my Cypress tests with GitLab pipelines. I have a Docker image set up with the following configuration: FROM cypress/browsers:latest ARG DIR="/usr/tests/e2e" ENV NODE_MODULES_PATH="$DIR/node_modules" WORKDIR $DIR COP ...

Incorporate pug and sass into your React project for a more

Are pug/jade and sass compatible with react? I enjoy organizing my code by separating files, and the functionality that sass and pug provide is great for this purpose. Is there a way to integrate pug and sass into a react project? Pug example: doctype ...

The error message thrown by react-big-calendar says: "Attempting to access property '0' of an undefined value",

Issue I encountered an error while trying to integrate react-calendar. The back and next buttons that are supposed to change dates are causing this error: Uncaught TypeError: Cannot read property '0' of undefined Initially, everything was wo ...

Using Javascript to Showcase a Video's Number of Views with Brightcove

How can I show the number of views for a video without using Brightcove's player? Brightcove Support shared this resource: , but I'm having trouble understanding it. ...

The file refuses to download after an AJAX post

When accessing the URL directly from my program that generates a PDF, I am able to initiate a direct download. public void Download(byte[] file) { try { MemoryStream mstream = new MemoryStream(file); long dataLengthToRead = mstre ...

What is the best method for submitting an array of objects using Axios, Formik, and React.js?

Hello, I am facing an issue with posting an array of objects using axios and Formik while also utilizing npm react-select. Here is my initial data: const [initialValues, setInitialValues] = useState( { nom: "",drugs: [{}] ...

Showing a 2D array in Jquery within an MVC environment - what's the solution?

I am in the process of building an MVC application. My goal is to transmit data from the controller and display it using JQuery. I have constructed an array in the controller and sent it to JQuery using Json. Here is the array... And here is the JQuery ...

The required module does not have a default export available when using express routing

I could really use some help figuring out what I'm missing here. Just to provide some context, my app is built on node.js (version 16.13.1) using the latest version of express and a nginx reverse proxy. app.mjs import router from './assets/js/r ...

What are the steps for utilizing ckeditor to send textarea information via ajax?

Here is the code snippet that controls the textarea in my chat application: <div class="chat"> <div class="messages"></div> <textarea class="entry" name="entry" placeholder="Welcome to the Chat. Enter your message here!">&l ...

Moving a window in Pyqt5 using QtWebChannel

My goal is to enable the mousePressEvent and mouseMoveEvent events in order to move my app window using QtWebChannel. To achieve this, I am utilizing self.setWindowFlags(QtCore.Qt.FramelessWindowHint) to eliminate the default window flag and create a cust ...

What is the best way to pass a variable to the chrome.tab.create function?

Is there a way to pass a variable to the `chrome.tabs.create` function? I am currently working on setting up event listeners for my anchors, but I am faced with a challenge as I am creating them within a for loop: for (var i = 0; i < links.length; i++) ...

Tips for manipulating 2 arrays where the value in one array is reliant on the value in another array

Currently, I have two arrays - arrayGuest and arrayRent. They both contain objects with a common field, GuestID. My goal is to create a list that combines fields from both arrays when their guestIDs match. The structure of the objects is as follows: class ...

Displaying a DIV after entering text into an <input> field using JavaScript

Attempting to create a JavaScript function that will show/hide a 'DIV' after entering some text into an input field. I have successfully written the function, but I am struggling to make it only work when the user enters a value greater than 8. ...

What could be preventing me from exporting and applying my custom JavaScript styles?

This is my primary class import React, { Component } from 'react'; import { withStyles } from '@material-ui/core/styles'; import styles from './FoodStyles'; class Food extends Component { render () { return ( & ...

WebdriverIo- Focus remains outside the browser after closing a pop-up window

Trying to automate a scenario, but encountering an issue where execution stops after step 3. Entering username/password on login page Clicking submit button opens a pop-up window, entering data in input box on pop-up window and clicking the OK button Pop- ...