{"id":27840222,"url":"https://github.com/smourier/webview2aot","last_synced_at":"2025-07-25T06:04:44.129Z","repository":{"id":290229081,"uuid":"966319588","full_name":"smourier/WebView2Aot","owner":"smourier","description":"WebView2 .NET AOT-compatible bindings independent from WinForms or WPF.","archived":false,"fork":false,"pushed_at":"2025-07-11T22:14:59.000Z","size":359,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-12T00:22:18.129Z","etag":null,"topics":["aot","directn","directnaot","dotnet-core","native-aot","webview2"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smourier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-14T18:35:23.000Z","updated_at":"2025-07-11T22:15:03.000Z","dependencies_parsed_at":"2025-06-22T21:20:19.329Z","dependency_job_id":null,"html_url":"https://github.com/smourier/WebView2Aot","commit_stats":null,"previous_names":["smourier/webview2aot"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/smourier/WebView2Aot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smourier%2FWebView2Aot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smourier%2FWebView2Aot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smourier%2FWebView2Aot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smourier%2FWebView2Aot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smourier","download_url":"https://codeload.github.com/smourier/WebView2Aot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smourier%2FWebView2Aot/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266963279,"owners_count":24013020,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aot","directn","directnaot","dotnet-core","native-aot","webview2"],"created_at":"2025-05-03T03:44:27.746Z","updated_at":"2025-07-25T06:04:44.119Z","avatar_url":"https://github.com/smourier.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebView2Aot\n\n[Microsoft WebView2](https://developer.microsoft.com/en-us/microsoft-edge/webview2?form=MA13LH) .NET 9+ AOT-compatible bindings 100% independent from WinForms or WPF.\n\n* **HelloWebView2** is a sample hello world in 40 lignes of C# code (see screenshot below).\n* **WebView2** is the .NET Core 9+ AOT-compatible bindings dll that can be used to use WebView2.\n* **WebView2Aot.InteropBuilder.Cli** is the tool that generates code in the WebView2 dll. This is based on the linked [Win32InteropBuilder](https://github.com/smourier/Win32InteropBuilder) generic project. It also needs Microsoft.Web.WebView2.Win32.winmd which is the WebView2 metadata (check this for more information https://github.com/wravery/webview2-win32md).\n\nWebView2 has a dependency to  [DirectN AOT](https://github.com/smourier/DirectNAot) for some Windows definitions (BOOL, PWSTR, etc.) but has zero dependency on any UI framework.\n\nOf course, all this requires the WebView2 to be installed!\n\n## Deployment\n\nWebView2 comes with a `WebView2Utilities.Initialize` method that will initialize the web view loader WebView2Loader.dll.\n\nTo make it work, you can reference the standard [Microsoft.Web.WebView2 ](https://www.nuget.org/packages/microsoft.web.webview2) nuget package as usual. However, it comes with all pre-built WPF \u0026 Winforms NET dll and xml, while we only need the native *WebView2Loader.dll* file.\n\nSo `WebView2Utilities.Initialize` also supports two other modes: you can extract the file corresponding to your processor architecture (x86, x64, arm4), or even all files from all architectures, as they rarely change, and either:\n1) copy them locally in your app's folder, following the `regular runtimes\\[arch]\\native\\WebView2Loader.dll` relative path\n2) embed them as a .NET resource (from Visual Studio, set \"Build Action\" to \"Embedded resource\"), for example like this:\n\n![image](https://github.com/user-attachments/assets/d08fae48-79d2-4a7c-b693-3bb9be6bcbf6)\n\nWhat's nice with embedding, especially in AOT deployment cases, is you just need to ship one file.\n\n## HelloWebView2 sample\n\n![image](https://github.com/user-attachments/assets/885a9167-885a-435e-ad5b-2b4e91ae610c)\n\n## ScriptHostObjectWebView2 sample\n\nA sample that demonstrates how to add a host object to the WebView2 scripting context, always with AOT publishing:\n\n\u003cimg width=\"740\" height=\"400\" alt=\"image\" src=\"https://github.com/user-attachments/assets/c983d80a-bfa6-413b-ab54-6d7473543245\" /\u003e\n\nThis is the relevant html part:\n\n```\n\u003cbody\u003e\n    \u003cdiv id=\"container\"\u003eWaiting 2000 ms for .NET function to return...\u003c/div\u003e\n    \u003cdiv id=\"clock\"\u003e\u003c/div\u003e\n    \u003cscript type=\"module\"\u003e\n\n        const dotnet = chrome.webview.hostObjects.dotnet;\n        dotnet.getInfoAsync(2000).then((value) =\u003e { document.getElementById('container').innerText = \".NET returned: \" + value; });\n\n        // just show a clock while working...\n        function showClock() { clock.innerText = new Date().toLocaleTimeString(); dotnet.onClockTick(new Date()); }\n        showClock();\n        setInterval(showClock, 1000);\n\n    \u003c/script\u003e\n\u003c/body\u003e\n```\n\nAnd the host object which is named 'dotnet' in the previous javascript code.\n\n```\n[GeneratedComClass]\npublic partial class HostObject : DispatchObject\n{\n    public event EventHandler\u003cstring\u003e? ClockTick;\n\n    // non async method\n    public string GetInfo()\n    {\n        var info = new HostObjectInfo();\n        return JsonSerializer.Serialize(info, JsonSourceGenerationContext.Default.HostObjectInfo);\n    }\n\n    // async method\n    public Task\u003cstring\u003e GetInfoAsync(int delay) =\u003e Task.Run(async () =\u003e\n    {\n        await Task.Delay(delay).ConfigureAwait(false); // simulate some async work\n        return GetInfo();\n    });\n\n    public void OnClockTick(string date) =\u003e ClockTick?.Invoke(this, date);\n\n    // note this is necessary to avoid trimming Task\u003cT\u003e.Result for AOT publishing\n    // all Task\u003cT\u003e results should be unwrapped here, so you can return any type you want (string being by far the most used one)\n    protected override object? GetTaskResult(Task task)\n    {\n        if (task is Task\u003cstring\u003e s)\n            return s.Result;\n\n        return null;\n    }\n}\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmourier%2Fwebview2aot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmourier%2Fwebview2aot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmourier%2Fwebview2aot/lists"}