Repository navigation
WebView2 based login and launch (#29) - #41
Merged
Merged
Conversation
The only launch profile had jsWebView2Debugging enabled, which makes Visual Studio attach a JavaScript/Edge debug adapter for scripts running inside a WebView2 control. No WebView2 control is instantiated yet - WebView2 is currently only pulled in at runtime by AutoUpdater.NET's changelog viewer - so the adapter has nothing to attach to. It exits with code 0 before connecting, and the debug session reports "could not start the debug adapter" / "cannot launch browser: browser process exited with code 0 before connecting to the debug server ... verify runtimeExecutable". The flag is still wanted for the WebView2-based login work (#29), so rather than dropping it, the default profile is now plain and the WebView2 JS debugging variant is kept as a second profile that can be selected from the Visual Studio launch dropdown once a WebView2 control actually exists. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The handoff patch had never been compiled. It built and passed on the first try, so this only covers the follow-ups that do not need a real Konaste account. Nullable warnings (TODO 1): RunUriActionOnce did not match the EventHandler signature (object? sender) and declared the TryCreate out parameter as non-nullable. Password autofill (TODO 3): WebView2 disables both settings by default, so every login would have required typing the credentials again. Enabled IsPasswordAutosaveEnabled and IsGeneralAutofillEnabled right after EnsureCoreWebView2Async. GameRegistry.GetLauncherPath (TODO 7): OpenSubKey returns null rather than throwing when the scheme is not registered, which is the normal state for a game that is not installed, and the result was dereferenced unguarded. WebLauncher calls this immediately before launching, so the crash sat directly on the new launch path. Also guarded the trailing " \"%1\"" strip, which used a fixed length and would throw on a shorter value, and made the return type nullable to match the caller. Localized messages (TODO 8): moved the hardcoded English WebView2 runtime message into Strings.resx, along with the two other hardcoded messages in WebLauncher for consistency. Note that Strings.Designer.cs is generated by a Visual Studio design time tool and is not regenerated by dotnet build, so the properties had to be added by hand to match the new resx entries. Added tests covering that correspondence, since an entry missing from the resx side returns null at runtime instead of failing the build. Build is clean and all 45 tests pass. TODO 2 and 4 need a real Konaste account and a physical device, and TODO 5 and 6 are gated on TODO 2.
Debug logs from a session on the WebView2 branch show what the adapter actually does: it launches KsGameLauncher2.exe as if it were the browser, polls http://localhost:<port>/json/version for a CDP target, and after a 30 second timeout reports "Could not find any debuggable target" and tears the session down. Because it is configured with cleanUp: "wholeBrowser" and killBehavior: "forceful", that teardown kills the app, which exits with 0xFFFFFFFF. This app creates its WebView2 lazily, only when a game is launched, so with this flag on the default profile the app is killed roughly 30 seconds after every debug start whether or not anything was clicked. The flag is still useful once a WebView2 exists, so the profile stays, but its name now says that a game has to be opened before the adapter gives up. launchSettings.json is strict JSON, so the name is the only place to put that.
3 of 4 tasks
… feature/webview2-login
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the WebView2-based login for #29, from a handoff patch prepared in another session.
What this does
KONAMI's login moved to its own OAuth flow, so the old approach (HttpClient + AngleSharp posting to the login form, credentials in Credential Manager) stopped working. Instead of reproducing that flow, this shows the official login page in a WebView2 and rides the resulting cookie session to open the launch page and read the launch URI.
Web/LaunchPageClassifier.cskonaste.xxx://login,bm2dxinf://login— same condition as the oldLauncherLoginPage)Web/WebLaunchSession.csCoreWebView2. Opens the launch page and reads thelaunch.selectorelement's href from the DOM rather than clicking it. Detects the maintenance banner. If the href never appears, reveals the window so the user can click, and captures the URI viaLaunchingExternalUriSchemeForms/WebViewHostForm.csOpacity = 0and only reveals itself when user interaction is needed or 20s elapse.UserDataFolderis%LocalAppData%\KsGameLauncher\WebView2so single-file publish doesn't try to write next to the exeWeb/WebLauncher.csStartAppAsync(AppInfo)/LogoutAsync(). Launching still goes through the registry andProcess.Start(path, uri)Tests/LaunchPageClassifierTests.csLogin detection deliberately keys on "we are on a different host from the launch page" rather than pinning
AuthorizeDomain(account.konami.net), so it survives changes to the OAuth domain or redirect chain.Program.csalso changes: the URI launch mode (konaste.*://launch/<id>) now runs on the UI thread viaApplication.Idleinstead of a separate STA thread, because WebView2 only works on a thread with a message loop.Follow-ups cleared here
The patch had never been compiled. It built and passed on the first try; the second commit covers the follow-ups that don't need a real Konaste account:
RunUriActionOncedidn't match theEventHandlersignature (object? sender), and theTryCreateout parameter was declared non-nullable.IsPasswordAutosaveEnabled/IsGeneralAutofillEnabled.GameRegistry.GetLauncherPath(TODO 7) —OpenSubKeyreturns null rather than throwing when the scheme isn't registered, which is the normal state for a game that isn't installed, and the result was dereferenced unguarded.WebLaunchercalls this immediately before launching, so the crash sat directly on the new launch path. Also guarded the trailing" \"%1\""strip, which used a fixed length and would throw on a shorter value, and made the return type nullable to match the caller.Strings.resx, along with the two other hardcoded messages inWebLauncherfor consistency.Note:
Strings.Designer.csis generated by a Visual Studio design-time tool and is not regenerated bydotnet build, so the properties were added by hand to match the new resx entries. Added tests covering that correspondence — an entry missing on the resx side returns null at runtime rather than failing the build, so nothing else would catch it.Still open — needs your machine
[WebLaunch] navigate:/page:debug output for whether login returns to the launch page, whether the#login>div>a.link-btnselector is still valid, and whether the flow depends on popups orwindow.opener. If it useswindow.opener+ postMessage,NewWindowRequestedneeds to assign a separate WebView2 toe.NewWindowinstead of navigating in place.https://webauthn.iofirst, and whether the Windows passkey dialog can appear while the host window is still transparent (WebView2Feedback #5460).Launcher.cs's HttpClient login path, the OTP dialog andSettings.Cookiesare all still in place, which also means this can be reverted by pointing the two call sites back.Test plan
dotnet build KsGameLauncher.sln— 0 errors, no warnings in the new codedotnet test— 45/45 passed (25 existing + 14 from the patch + 6 added here)