2

I created a simple Asp.net core application and want to test playwright in my project. its is working fine in local Environment but when I am trying to deploy in docker container getting Error as Driver not found: /app/.playwright/node/linux/playwright.sh.

Test.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"]

SampleApplication.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";
        }
    }

Any help is Appreciated .

  • 1
    If I remember correctly `Microsoft.Playwright` got a few related fixes in their latest bugfix releases. Since you are using `1.12.0` I would try using `1.12.2` instead. – Max Schmitt Jun 23 '21 at 07:12

0 Answers0