[BUG] Playwright and Azure Function Deployment Issues
See original GitHub issueThere is an issue with .net 6.0 playwright version 1.22.0 that is currently not allowing for deployment to Azure Functions. We have tried multiple solutions including manually setting up the browser EXE’s as well as installing them locally. We created a test app shown below that outputs the error below that.
namespace PlaywrightTesterLibrary
{
using Microsoft.Extensions.Logging;
using Microsoft.Playwright;
public class PlaywrightTester : IPlaywrightTester
{
private readonly ILogger _logger;
public PlaywrightTester(ILogger<PlaywrightTester> logger)
{
_logger = logger;
}
public void Run()
{
PlaywrightExecution().Wait();
}
private async Task PlaywrightExecution()
{
try
{
Microsoft.Playwright.Program.Main(new[] { "install", "chromium" });
_logger.LogDebug("Playwright Installed");
using var playwright = await Playwright.CreateAsync();
_logger.LogDebug("Created Playwright Asynchroniously");
await using var browser = await playwright.Chromium.LaunchAsync(
new BrowserTypeLaunchOptions
{
Headless = false,
ExecutablePath = Environment.GetEnvironmentVariable("HOME_EXPANDED"),
});
_logger.LogDebug("Creating Browser");
var page = await browser.NewPageAsync();
_logger.LogDebug("Opening Page");
await page.GotoAsync("https://playwright.dev/dotnet");
_logger.LogDebug("Going to Playwright Page");
await page.ScreenshotAsync(new PageScreenshotOptions { Path = "screenshot.png" });
_logger.LogDebug("Taking Screenshot");
}
catch (Exception ex)
{
_logger.LogError(ex.Message + ex);
}
finally
{
_logger.LogDebug("Success");
}
}
}
}
This function runs locally, successfully (without the home expanded environment variable)
Error in Playwright: Failed to launch: Error: spawn D:\DWASFiles\Sites\test-inc-robot\VirtualDirectory0 ENOENT =========================== logs =========================== <launching> D:\DWASFiles\Sites\test-inc-robot\VirtualDirectory0 --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --no-sandbox --user-data-dir=C:\local\Temp\playwright_chromiumdev_profile-2czlmr --remote-debugging-pipe --no-startup-window [pid=N/A] starting temporary directories cleanup [pid=N/A] finished temporary directories cleanup ============================================================Microsoft.Playwright.PlaywrightException: Failed to launch: Error: spawn D:\DWASFiles\Sites\test-inc-robot\VirtualDirectory0 ENOENT =========================== logs =========================== <launching> D:\DWASFiles\Sites\test-inc-robot\VirtualDirectory0 --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --no-sandbox --user-data-dir=C:\local\Temp\playwright_chromiumdev_profile-2czlmr --remote-debugging-pipe --no-startup-window [pid=N/A] starting temporary directories cleanup [pid=N/A] finished temporary directories cleanup ============================================================ at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](String guid, String method, Object args) in //src/Playwright/Transport/Connection.cs:line 164 at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1 action, Boolean isInternal) in //src/Playwright/Transport/Connection.cs:line 475 at Microsoft.Playwright.Core.BrowserType.LaunchAsync(BrowserTypeLaunchOptions options) in /_/src/Playwright/Core/BrowserType.cs:line 61 at PlaywrightTesterLibrary.PlaywrightTester.PlaywrightExecution() in /home/vsts/work/1/application/Projects/PlaywrightTester/PlaywrightTester.cs:line 28
Once deployed this error is thrown.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
Ok! Well we decided to pivot to a javascript verison of playwright which is functioning as intended in Azure! Thank you for the help.
Playwright requires a lot of dependencies to function properly, this includes the driver (shipped with nuget), the browsers (installed with the pwsh command), OS dependencies (they need to be installed manually or pwsh playwright install --with-deps).
Thats why we usually recommend using our official Docker image, which does all of this out of the box: https://playwright.dev/dotnet/docs/docker
Would that work for you? The newly launched Azure Container Apps might be a good fit for that.