Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Playwright with Blazor WASM - not for testing

$
0
0

I am new to this so please be patient. I am trying to use playwright with blazor WASM (standalone, not hosted with server) but I dont have any luck. I am trying just to open website in chromium. but I got stuck right at the start. I dont want to use it for testing, only for opening webpage and injecting javascript and then extracting data from there.

Right now I have very simple code barely few lines:@

page "/"@using Microsoft.Playwright<button @onclick="(async()=>await MainProcess())">Start</button>@code {    private async Task MainProcess()    {        try        {            Program.Main(new[] { "install" });            var playwright = await Playwright.CreateAsync();            var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = false });            var page = await browser.NewPageAsync();            await page.GotoAsync("https://www.example.com");        }        catch (Exception ex)        {            Console.WriteLine($"Error initializing Playwright: {ex.Message}");        }    }}

Exception is thrown at line var playwright = await Playwright.CreateAsync();console errors are:

Microsoft.Playwright assembly was found, but is missing required assets. Please ensure to build your project before running Playwright tool.

Error initializing Playwright: The value cannot be an empty string. (Parameter 'path')

I am not getting these errors anymore (dont know why) but I think they are important:Console:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]Unhandled exception rendering component: The value cannot be an empty string. (Parameter 'path')System.ArgumentException: The value cannot be an empty string. (Parameter 'path')at System.ArgumentException.ThrowNullOrEmptyException(String argument, String paramName)at System.ArgumentException.ThrowIfNullOrEmpty(String argument, String paramName)at System.IO.Path.GetFullPath(String path)at System.IO.FileInfo..ctor(String originalPath, String fullPath, String fileName, Boolean isNormalized)at System.IO.FileInfo..ctor(String fileName)at Microsoft.Playwright.Helpers.Driver.GetExecutablePath() in //src/Playwright/Helpers/Driver.cs:line 63at Microsoft.Playwright.Transport.StdIOTransport.GetProcess(String driverArgs) in //src/Playwright/Transport/StdIOTransport.cs:line 116at Microsoft.Playwright.Transport.StdIOTransport..ctor() in //src/Playwright/Transport/StdIOTransport.cs:line 46at Microsoft.Playwright.Playwright.CreateAsync() in //src/Playwright/Playwright.cs:line 43at BlazorTrackerWasmTest.Pages.Home.MainProcess() in -----\Pages\Home.razor:line 20at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

in VS:

NETSDK1022 Duplicate 'Content' items were included. The .NET SDK includes 'Content' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultContentItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'C:----.nuget\packages\microsoft.playwright\1.43.0\buildTransitive...playwright\node\LICENSE' BlazorWasmTrackerTest C:\Program Files\dotnet\sdk\8.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.Shared.targets

I installed script for chromium pwsh bin/Debug/net8.0/playwright.ps1 install I used Program.Main(new[] { "install" }); and also I included this in csproj <PlaywrightPlatform>all</PlaywrightPlatform>

I dont know what else to do and I have feeling I am trying to do something that is not possible beucase its WASM? Its all working with console app or Blazor server app.

Thank you.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>