Version
1.49.0
Steps to reproduce
Execute the following C# code, which is using the new headless mode.
It used to work fine with the old headless mode.
using Microsoft.Playwright;
int width = 468;
int height = 60;
var problematicUrl = "https://api.bannerflow.com/preview/731073/10760085/preview?access-token=[access_token_removed]&snapshot=12689920&autoplay=off&preload=false&seek=preload-frame&fadein=false&env=image-generator";
var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Channel = "chromium",
Args = ["--headless"]
});
var page = await browser.NewPageAsync(new BrowserNewPageOptions
{
ScreenSize = new ScreenSize
{
Height = height,
Width = width
}
});
// removing the SetViewportSizeAsync call fixes the timeout issue
await page.SetViewportSizeAsync(width, height);
Console.WriteLine("navigating to url");
await page.GotoAsync(problematicUrl);
Console.WriteLine("waiting 10 seconds for the page to load");
await Task.Delay(10000);
Console.WriteLine("Taking screenshot (this will timeout in 30s)");
_ = await page.ScreenshotAsync();
Console.WriteLine($"screenshot taken!");
await page.CloseAsync();
Console.ReadLine();
project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Playwright" Version="1.49.0" />
</ItemGroup>
</Project>
Environment
Docker
FROM mcr.microsoft.com/dotnet/runtime:9.0 AS base
WORKDIR /app
ARG BUILD_CONFIGURATION=Release
# Install node so that we can install playwright
RUN apt-get update && apt-get --no-install-recommends install -y \
ca-certificates \
gnupg \
wget \
&& rm -rf /var/lib/apt/lists/*
RUN wget -qO- --max-redirect=0 https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get --no-install-recommends install -y nodejs \
&& rm -rf /var/lib/apt/lists/*
# install playwright
RUN npx playwright@1.49 install --with-deps chromium --no-shell
RUN mkdir -p /home/app/.cache/ms-playwright
RUN chown -R $APP_UID /home/app/.cache/ms-playwright
RUN cp -r /root/.cache/ms-playwright/* /home/app/.cache/ms-playwright/
RUN chown -R $APP_UID /home/app/.cache/ms-playwright
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
COPY ["PlaywrightIssue.csproj", "./"]
RUN dotnet restore "PlaywrightIssue.csproj"
COPY . .
WORKDIR "/src/"
RUN dotnet build "PlaywrightIssue.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "PlaywrightIssue.csproj" -c Release -o /app/publish /p:UseAppHost=false
RUN chown -R $APP_UID /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
USER $APP_UID
ENTRYPOINT ["dotnet", "PlaywrightIssue.dll"]
Expected behavior
Screenshot is taken
Actual behavior
Unhandled exception. System.TimeoutException: Timeout 30000ms exceeded.
2025-01-28T09:01:10.408058028Z Call log:
2025-01-28T09:01:10.408061179Z - - taking page screenshot
2025-01-28T09:01:10.408063638Z - - waiting for fonts to load...
2025-01-28T09:01:10.408066003Z - - fonts loaded
2025-01-28T09:01:10.408068476Z at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](ChannelOwner object, String method, Dictionary`2 dictionary, Boolean keepNulls) in /_/src/Playwright/Transport/Connection.cs:line 206
2025-01-28T09:01:10.408072276Z at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1 action, Boolean isInternal) in /_/src/Playwright/Transport/Connection.cs:line 535
2025-01-28T09:01:10.408075101Z at Microsoft.Playwright.Core.Page.ScreenshotAsync(PageScreenshotOptions options) in /_/src/Playwright/Core/Page.cs:line 690
2025-01-28T09:01:10.408077688Z at Program.<Main>$(String[] args) in /home/aleks/RiderProjects/PlaywrightIssue/Program.cs:line 33
2025-01-28T09:01:10.408080571Z at Program.<Main>(String[] args)
Additional context
Works fine when the call to page.SetViewportSizeAsync(width, height) is removed
Version
1.49.0
Steps to reproduce
Execute the following C# code, which is using the new headless mode.
It used to work fine with the old headless mode.
project file:
Environment
Docker
Expected behavior
Screenshot is taken
Actual behavior
Additional context
Works fine when the call to page.SetViewportSizeAsync(width, height) is removed