Closed datauduong closed 2 months ago
I am testing out the Microsoft.Playwright, but I couldn't work out where the issue is, deployed to local docker linux host. .playwright have been installed to /home/site/wwwroot/bin/Debug/net8.0/.playwright/node/linux-x64/node where as the application expecting /home/site/wwwroot/bin/Debug/.playwright/node/linux-x64/node
I've try to print out from the program. The path is correct: /home/site/wwwroot/bin/Debug/net8.0/.playwright/node/linux-x64/node var playwrightPath = Path.Combine(Environment.GetEnvironmentVariable("PLAYWRIGHT_BROWSERS_PATH"), "node", "linux-64", "node");
The error seem to happen here: driver not found: /home/site/wwwroot/bin/Debug/.playwright/node/linux-x64/node
var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = true, // Set to false if you want to see the browser UI Args = new[] { "--no-sandbox", "--disable-setuid-sandbox" }, ExecutablePath = playwrightPath });
The code did not reach this line: Console.WriteLine($"ExecutablePath: {playwrightPath}");
Function1.cs
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Playwright; // Ensure correct namespace
namespace FunctionApp1
{
public static class Function1
{
[FunctionName("TestPlaywright")]
public static async Task<IActionResult> TestPlaywright(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "test-playwright")] HttpRequest req,
ILogger log)
{
log.LogInformation("Testing Microsoft.Playwright installation...");
try
{
// Launch Playwright
using var playwright = await Playwright.CreateAsync();
var playwrightPath = Path.Combine(Environment.GetEnvironmentVariable("PLAYWRIGHT_BROWSERS_PATH"), "node", "linux-64", "node");
var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = true, // Set to false if you want to see the browser UI
Args = new[] { "--no-sandbox", "--disable-setuid-sandbox" },
ExecutablePath = playwrightPath
});
Console.WriteLine($"ExecutablePath: {playwrightPath}");
Console.WriteLine("Code passed this point");
var context = await browser.NewContextAsync();
// Create a new page
var page = await context.NewPageAsync();
// Navigate to the PatentScope website
await page.GotoAsync($"https://www.google.com.au", new PageGotoOptions
{
WaitUntil = WaitUntilState.NetworkIdle
});
log.LogInformation("Microsoft.Playwright is installed and working correctly.");
return new OkObjectResult("Playwright test successful!");
await page.CloseAsync();
}
catch (Exception ex)
{
log.LogError(ex, "Error testing Microsoft.Playwright installation.");
return new BadRequestObjectResult("Playwright test failed: " + ex.Message);
}
}
}
}
hostfile { "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" }, "enableLiveMetricsFilters": true } }, "environmentVariables": { "PLAYWRIGHT_BROWSERS_PATH": "/home/site/wwwroot/bin/Debug/net8.0/.playwright" } }
local.settings.json { "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "FUNCTIONS_INPROC_NET8_ENABLED": "1", "FUNCTIONS_WORKER_RUNTIME": "dotnet" } }
Dockerfile
FROM mcr.microsoft.com/azure-functions/dotnet:4.0 AS base WORKDIR /home/site/wwwroot EXPOSE 8080
RUN apt-get update && apt-get install -y wget RUN wget -qO- https://deb.nodesource.com/setup_16.x | bash - && \ apt-get install -y nodejs RUN npm install -g playwright ENV PLAYWRIGHT_BROWSERS_PATH=/home/site/wwwroot/bin/Debug/net8.0/.playwright RUN echo $PLAYWRIGHT_BROWSERS_PATH
RUN npx playwright install chromium firefox webkit
RUN ls /home/site/wwwroot/bin/Debug/net8.0/.playwright
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src COPY ["FunctionApp1/FunctionApp1.csproj", "FunctionApp1/"] RUN dotnet restore "./FunctionApp1/FunctionApp1.csproj" COPY . . WORKDIR "/src/FunctionApp1" RUN dotnet build "./FunctionApp1.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish ARG BUILD_CONFIGURATION=Release RUN dotnet publish "./FunctionApp1.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final WORKDIR /home/site/wwwroot COPY --from=publish /app/publish . ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ AzureFunctionsJobHostLoggingConsole__IsEnabled=true \ PLAYWRIGHT_BROWSERS_PATH=/home/site/wwwroot/bin/Debug/net8.0/.playwright
Please help, I am running out of idea where to point the Microsoft.Playwright to Read from /home/site/wwwroot/bin/Debug/net8.0 Instead of /home/site/wwwroot/bin/Debug/
PLAYWRIGHT_BROWSERS_PATH
is an alternative location of the browser binaries, normally you don't need it at all. Moreover, you seem to be misusing it to get locations of node
.
This doesn't sound like a bug or feature request, please use our community resources for general questions. If you think this is a bug in Playwright, please open a new issue and follow the bug template when describing exact reproduction steps and expected behavior.
Please do not submit this issue.