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

[Feature] Any plans to adapt to net8's AOT

Open hzexe opened this issue 8 months ago • 17 comments

Let us know what functionality you'd like to see in Playwright and what your use case is. Do you think others might benefit from this as well? Might benefit:

  1. run faster first time,and save start time
  2. smaller docker image size
  3. better code protection

hzexe avatar Sep 30 '23 03:09 hzexe

This seems not compatible with Playwrights architecture, since the expenzsivest part happens inside the browser or do you want to compile your app with AOT instead and our Library prevents you from doing that?

mxschmitt avatar Oct 04 '23 13:10 mxschmitt

Json serialization and deserialization , which does not work in.NET full AOT

hzexe avatar Oct 19 '23 06:10 hzexe

Can you provide us a repro in form of a repository of whats not working?

mxschmitt avatar Oct 19 '23 09:10 mxschmitt

Json serialization and deserialization , which does not work in.NET full AOT

Use selenium

NCLnclNCL avatar Dec 29 '23 17:12 NCLnclNCL

Can you provide us a repro in form of a repository of whats not working?

It is bad

NCLnclNCL avatar Dec 29 '23 17:12 NCLnclNCL

I can repro after setting:

<PropertyGroup>
  <PublishAot>true</PublishAot>
</PropertyGroup>

on a new console project as per here and it produces:

❯ ./bin/Release/net8.0/osx-arm64/aot-test 
Unhandled exception. System.InvalidOperationException: Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.
   at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonSerializerIsReflectionDisabled()
   at System.Text.Json.JsonSerializerOptions.ConfigureForJsonSerializer()
   at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions options, Type inputType)
   at System.Text.Json.JsonSerializer.GetTypeInfo[T](JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.SerializeToUtf8Bytes[TValue](TValue value, JsonSerializerOptions options)
   at Microsoft.Playwright.Playwright.<>c__DisplayClass0_0.<CreateAsync>b__3(Object message, Boolean keepNulls) in /_/src/Playwright/Playwright.cs:line 55
   at Microsoft.Playwright.Transport.Connection.<>c__DisplayClass40_0`1.<InnerSendMessageToServerAsync>b__4() in /_/src/Playwright/Transport/Connection.cs:line 206
   at Microsoft.Playwright.Helpers.TaskQueue.EnqueueAsync(Func`1 taskGenerator) in /_/src/Playwright/Helpers/TaskQueue.cs:line 49
   at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](ChannelOwnerBase object, String method, Dictionary`2 dictionary, Boolean keepNulls) in /_/src/Playwright/Transport/Connection.cs:line 193
   at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1 action, Boolean isInternal) in /_/src/Playwright/Transport/Connection.cs:line 535
   at Microsoft.Playwright.Transport.Channels.Root.InitializeAsync() in /_/src/Playwright/Transport/Channels/Root.cs:line 45
   at Microsoft.Playwright.Playwright.CreateAsync() in /_/src/Playwright/Playwright.cs:line 57
   at Program.<Main>$(String[] args) in /Users/maxschmitt/Developer/tmp/aot-test/Program.cs:line 3
   at Program.<Main>(String[] args)
[1]    62788 abort      ./bin/Release/net8.0/osx-arm64/aot-test

mxschmitt avatar Dec 31 '23 13:12 mxschmitt

I don't think it makes sense adding nativeaot to playwright.net (at least not yet). Playwright.net is a layer over the engine that run in node, and where most of the interesting stuff happens. Setting PublishAOT and actually publishing to native executable are two very different things. With the latter being blocked by:

  • NUnit & XUnit not compatible with NativeAOT.
  • MSTest only supporting a subset of functionality in NativeAOT mode.
  • The native build time is long enough to offset the savings in test runs.
  • There is no support in VS to publish and run tests from native.

nohwnd avatar Mar 27 '24 10:03 nohwnd

you can try PuppeteerAot ,this library is support for aot

chenrensong avatar Apr 14 '24 01:04 chenrensong

bạn có thể thử PuppeteerAot , thư viện này hỗ trợ cho aot

thanks

NCLnclNCL avatar Apr 14 '24 02:04 NCLnclNCL

chenrensong Can you convert NewtonSoft.Json to System.Text.Json for selenium?

NCLnclNCL avatar Apr 14 '24 02:04 NCLnclNCL

chenrensong Can you convert NewtonSoft.Json to System.Text.Json for selenium?

Can you provide selenium project url?

chenrensong avatar Apr 14 '24 08:04 chenrensong

chenrensong Can you convert NewtonSoft.Json to System.Text.Json for selenium?

Can you provide selenium project url?

https://github.com/SeleniumHQ/selenium/tree/trunk/dotnet

NCLnclNCL avatar Apr 14 '24 09:04 NCLnclNCL

  • NUnit & XUnit not compatible with NativeAOT.
  • MSTest only supporting a subset of functionality in NativeAOT mode.
  • The native build time is long enough to offset the savings in test runs.
  • There is no support in VS to publish and run tests from native.

Most of these issues are being actively worked on: https://devblogs.microsoft.com/dotnet/introducing-ms-test-runner/

https://github.com/microsoft/testfx/issues/2164

RenderMichael avatar Apr 16 '24 14:04 RenderMichael

@chenrensong Can you please help me understand why you want / need NativeAOT for web testing? What are the benefits we could see in Playwright, when most of the work is offloaded to node.js. Maybe I am missing something here :)

nohwnd avatar Apr 16 '24 14:04 nohwnd

Making the library trim-compatible is good future-proofing hygiene, and ensures consumers know which methods aren't trim- or AOT-safe.

Would the maintainers accept PRs annotating the Playwright libraries for trimming and AOT?

RenderMichael avatar Apr 16 '24 14:04 RenderMichael

This might be my memory playing tricks on me, but when I first used Playwright many moons ago, I was under the impression that it was a more general purpose browser automation, which obviously ideal for testing web apps, but would also be a good fit for the puppeteer use-cases. For example generating images from web assets, turning HTLM into PDFs as part of an invoicing platform, etc...

Today it's very clear on the Playwright website that this is a web testing library, in which case I agree it doesn't make practical sense to make it AOT friendly.

slang25 avatar Apr 16 '24 15:04 slang25

@chenrensong Can you please help me understand why you want / need NativeAOT for web testing? What are the benefits we could see in Playwright, when most of the work is offloaded to node.js. Maybe I am missing something here :)

The. net version of Puppeter or Playwright essentially implements network testing by calling the browser kernel. The purpose of AOT execution is because currently developing Maui Mac version applications or Avalonia applications that wish to use AOT for compilation when released, and if these libraries are used, errors will be reported

chenrensong avatar Apr 21 '24 16:04 chenrensong