question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Playwright and Azure Function Deployment Issues

See original GitHub issue

There 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:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Pieeer1commented, May 27, 2022

Ok! Well we decided to pivot to a javascript verison of playwright which is functioning as intended in Azure! Thank you for the help.

1reaction
mxschmittcommented, May 27, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to install Playwright on an Azure Function using ...
I am trying to install playwright for python on an Azure function, deploying via github actions.
Read more >
Running Playwright e2e tests on Azure Functions
I tried to deploy with Azure DevOps pipelines and manually from VS2019. It doesn't matter, obviously. I understand it's probably a security ...
Read more >
Deploy azure function with pipeline and build on server. ...
I'm using puppeteer in a node.js function app on a linux machine successfully. Currently I'm deploying it directly from VS Codee !
Read more >
Running Playwright on Azure Functions
This post is about Running Playwright on Azure Functions and deploying it to Azure. Playwright is a Node.js library to automate Chromium, ...
Read more >
Azure Function (Python Consumption Plan) & Playwright ...
We are trying to build a function in Azure that does some browser automation steps using playwright. Our troubles are that we cannot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found