运行某些npm测试时遇到问题。我收到的错误是:“NaCl辅助程序进程在没有沙箱的情况下运行!”,这是正确的,因为我正在使用“--no-sandbox”选项运行浏览器。我必须运行此选项,因为浏览器以root身份运行,而我根本没有选择将其运行到另一个用户(这是一个docker镜像)。 有人可以帮我解决一下吗?
P.S我正在以下列方式安装浏览器:
RUN apt-get update
RUN apt-get install -y nodejs npm
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get install -y apt-transport-https
RUN apt-get update
RUN apt-get install -y google-chrome-stable
提前致谢!
答案 0 :(得分:11)
此错误消息...
NaCl helper process running without a sandbox!
...表示您的系统中没有setuid沙箱,因此该程序无法启动/产生新的浏览上下文即 Chrome浏览器会话。
一种快速的解决方案是,如果您要运行Chrome并且仅使用名称空间沙箱,则可以设置标志:
--disable-setuid-sandbox
此标志将禁用setuid沙箱(仅Linux)。但是,如果在没有名称空间沙箱适当内核支持的主机上执行此操作,Chrome将不会启动。另外,您也可以使用标志:
--no-sandbox
此标志将为通常被沙盒化的所有进程类型禁用沙盒。
示例:
chromeOptions: {
args: ['--disable-setuid-sandbox', '--no-sandbox']
},
您可以在Security Considerations - ChromeDriver - Webdriver for Chrome
中找到详细的讨论
根据Linux SUID Sandbox Development google-chrome中的文档,需要一个SUID
帮助程序二进制文件才能在Linux上打开沙箱。在大多数情况下,您可以使用以下命令为您安装适当的沙箱:
build/update-linux-sandbox.sh
该程序将在/usr/local/sbin
中为您安装正确的沙盒,并告诉您根据需要更新.bashrc
。
但是,举例来说,可能会有一些例外,如果您的setuid
二进制文件已过期,则会收到诸如以下消息:
Running without the SUID sandbox!
或
The setuid sandbox provides API version X, but you need Y
You are using a wrong version of the setuid binary!
在这些情况下,您需要:
chrome_sandbox
而不是ninja -C xxx chrome chrome_sandbox
)时都构建ninja -C xxx chrome
构建后,执行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
最后,您必须在~/.bashrc
(或.zshenv
)中加入以下行:
export CHROME_DEVEL_SANDBOX=/usr/local/sbin/chrome-devel-sandbox
答案 1 :(得分:1)
如果您使用业力运行测试,请确保使用const PrivateRoute = ({component: Component, loggedIn, ...rest }) => {
if(!loggedIn) {
return <Redirect to="/login" />
}
return <Route {...rest} component={Component}/>
}
}
}
const IndexRouter = ({ loggedIn }) => (
<Switch>
<PrivateRoute exact path="/dashboard" component={DashboardRouter} />
<PrivateRoute exact path="/stock" component={StockRouter} />
<Redirect to="/dashboard" />
</Switch>
);
作为ChromeHeadless
上的浏览器