Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resort:Failed to launch browser。 #2651

Closed
iarthit opened this issue May 31, 2024 · 4 comments
Closed

resort:Failed to launch browser。 #2651

iarthit opened this issue May 31, 2024 · 4 comments

Comments

@iarthit
Copy link

iarthit commented May 31, 2024

this is my code

using var browserFetcher = new BrowserFetcher();
var revisionInfo = await browserFetcher.DownloadAsync();
string executablePath = revisionInfo.GetExecutablePath();

// 启动 Chromium,设置为无头模式
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
    Headless = true,
    ExecutablePath = executablePath,
    //Args = ["--no-sandbox"]
});
// 打开一个新的页面
var page = await browser.NewPageAsync();

this is my dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER root
WORKDIR /app
EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Signin.csproj", "."]
RUN dotnet restore "./././Signin.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "./Signin.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Signin.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app

RUN apt-get update && \
    apt-get install -y libglib2.0-0 && \
    rm -rf /var/lib/apt/lists/*
ENV LANG=C.UTF-8

COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Signin.dll"]

Code running error

Failed to launch browser! 
at PuppeteerSharp.States.ProcessStartingState.StartCoreAsync(LauncherBase p) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/States/ProcessStartingState.cs:line 83 
at PuppeteerSharp.States.ProcessStartingState.StartCoreAsync(LauncherBase p) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/States/ProcessStartingState.cs:line 89 
at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Launcher.cs:line 66 
at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Launcher.cs:line 99  
 at Signin.Service.PTSigninService.<>c__DisplayClass0_0.<<AddModuleRoutes>b__3>d.MoveNext() in /src/Service/PTSigninService.cs:line 110"

Please advise on how to solve it, thank you

@HankeXia
Copy link

executablePath 你下载好放到copy到容器里面 直接设置路径,这个下载是要连google的 ,,墙了 下不来

@iarthit
Copy link
Author

iarthit commented Aug 23, 2024

好滴,请问那个依赖这块还需要装什么,我感觉我写的不对

RUN apt-get update && \
    apt-get install -y libglib2.0-0 && \
    rm -rf /var/lib/apt/lists/*

@HankeXia
Copy link

RUN apt-get update &&
apt-get -y install xvfb gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2
libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0
libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1
libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1
libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget unzip procps
--no-install-recommends
&& rm -rf /var/lib/apt/lists/*

--我这里是把浏览器包压缩了 上传容器后解压
RUN unzip Chrome/chrome-linux.zip -d .
&& rm -rf Chrome/chrome-linux.zip

@iarthit
Copy link
Author

iarthit commented Aug 23, 2024

谢谢老铁,我试试去

@kblok kblok closed this as completed Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants