playwright-dotnet icon indicating copy to clipboard operation
playwright-dotnet copied to clipboard

[BUG] Not able to use Playwright on macOS Catalyst

Open lk-code opened this issue 1 year ago • 5 comments

System info

  • Playwright Version: 1.41.2
  • Operating System: macOS 14.3
  • Browser: All
  • Other info:

Source code

i use the sample code from playwright on macOS and got an exception at the following line (the logic is in a .NET 8 Class Library):

using var playwright = await Playwright.CreateAsync();
...

EXCEPTION:

Microsoft.Playwright.PlaywrightException: Unknown platform
   at Microsoft.Playwright.Helpers.Driver.GetPath(String driversPath) in /_/src/Playwright/Helpers/Driver.cs:line 119
   at Microsoft.Playwright.Helpers.Driver.GetExecutablePath() in /_/src/Playwright/Helpers/Driver.cs:line 82
   at Microsoft.Playwright.Transport.StdIOTransport.GetProcess(String driverArgs) in /_/src/Playwright/Transport/StdIOTransport.cs:line 116
   at Microsoft.Playwright.Transport.StdIOTransport..ctor() in /_/src/Playwright/Transport/StdIOTransport.cs:line 46
   at Microsoft.Playwright.Playwright.CreateAsync() in /_/src/Playwright/Playwright.cs:line 44
   at ArmyPlanner.Admin.Core.WebsiteParsers.CitadelColorSearch.GetImageUrl(String colorName, CancellationToken cancellationToken) in /Users/larskramer/Projects/lk-code/armyplanner-admin-app/source/ArmyPlanner.Admin.Core/WebsiteParsers/CitadelColorSearch.cs:line 90
   at ArmyPlanner.Admin.Maui.ViewModels.ColorManagement.DetailViewModel.OnColorCodeSearchAsync(CancellationToken cancellationToken) in /Users/larskramer/Projects/lk-code/armyplanner-admin-app/source/ArmyPlanner.Admin.Maui/ViewModels/ColorManagement/DetailViewModel.cs:line 41

I followed the code through the StackTrace and came to a place where basically the string "OSX" is compared with the string "MACCATALYST" and "IOS" and therefore fails. The value "OSX" is set in Driver.cs line 107 and compared with the current platform in the if. In the OperatingSystem.cs file, however, only MACCATALAYST and IOS are checked as described.

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool IsOSPlatform(string platform)
    {
      ArgumentNullException.ThrowIfNull((object) platform, nameof (platform));
      return platform.Equals("MACCATALYST", StringComparison.OrdinalIgnoreCase) || platform.Equals("IOS", StringComparison.OrdinalIgnoreCase);
    }

As soon as the platform names for macOS are used correctly everywhere, the bug is fixed and the "Unknown-Platform" exception no longer occurs :)

lk-code avatar Jan 25 '24 14:01 lk-code

In short, Playwright is currently not usable for macOS users :(

lk-code avatar Jan 25 '24 14:01 lk-code

The error gets thrown here:

https://github.com/microsoft/playwright-dotnet/blob/ec7d7fafa34de96c81df188cdc07d5aba411808b/src/Playwright/Helpers/Driver.cs#L119

We do RuntimeInformation.IsOSPlatform(OSPlatform.OSX) inside, which is for some reason not working on your environment. Which TFM are you using? Are you using net6.0-maccatalyst?

mxschmitt avatar Jan 25 '24 14:01 mxschmitt

the class library has net8.0 and the app net8.0-maccatalyst.

I know that the exception is thrown there :)

The if statement in line 107 specifies OSX, but behind it are the values MACCATALYST and IOS. This means that the if fails every time. The string comparison is always wrong on macOS.

lk-code avatar Jan 25 '24 15:01 lk-code

I am experiencing the same issue. I am trying to use this on MacOS in a Blazor MAUI app.

cyrilgupta avatar Apr 16 '24 09:04 cyrilgupta

Here same as @cyrilgupta

erodriguezh avatar May 05 '24 06:05 erodriguezh