我创建了一个简单的 Asp.net 核心应用程序,并想在我的项目中测试 playwright。它在本地环境中运行良好,但是当我尝试在 docker 容器中部署时,得到错误为Driver not found: /app/.playwright/node/linux/playwright.sh
.
测试.csproj
<ItemGroup>
<PackageReference Include="Microsoft.Playwright" Version="1.12.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.13" />
</ItemGroup>
DockerFile
FROM mcr.microsoft.com/dotnet/aspnet:3.1-bionic AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["Test.csproj", "./"]
RUN dotnet restore "./Test.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "Test.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Test.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Test.dll"]
示例应用程序.cs
public async Task<string> Get()
{
try
{
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false,
SlowMo = 250,
Args = new[] { "--disable-dev-shm-usage", "--no-sandbox", "--user pwuser" },
});
var page = await browser.NewPageAsync();
// Navigate to the home page
await page.GotoAsync("https://www.facebook.com/");
await page.WaitForTimeoutAsync(10000);
}
catch (Exception e)
{
return e.Message.ToString();
}
return "This will open facebook page";
}
}
任何帮助表示赞赏。