Fix: Resolve Tauri Error 1412 (Chrome_WidgetWin_0) on Windows 11#1152
Fix: Resolve Tauri Error 1412 (Chrome_WidgetWin_0) on Windows 11#1152pranitaurlam wants to merge 4 commits intoAOSSIE-Org:mainfrom
Conversation
Added documentation explaining that the 'Jest did not exit one second after the test run' warning is harmless when all tests pass. This helps new contributors understand the warning is expected behavior and not an indication of a problem. Fixes AOSSIE-Org#1137
- Changed 'async handles' to 'open handles' for accuracy - Added examples of open handles (unclosed servers, DB connections, timers) - Added npx jest --detectOpenHandles command for debugging - Mentioned proper resource cleanup in afterEach/afterAll Addresses code review feedback
- Add tauri-plugin-single-instance to prevent multiple WebView2 instances - Configure single-instance behavior to focus existing window - Add window label and skipTaskbar configuration for proper lifecycle - This fixes the window closing prematurely before connecting to backend Fixes AOSSIE-Org#1147
📝 WalkthroughWalkthroughAdds single-instance handling to the Tauri desktop app (via tauri-plugin-single-instance), configures the main window label and taskbar visibility, and documents a Jest open-handles diagnostic in CONTRIBUTING.md. Changes
Sequence Diagram(s)sequenceDiagram
participant User as User (second launch)
participant OS as OS
participant Plugin as SingleInstancePlugin
participant App as TauriApp
participant Window as MainWindow
User->>OS: launch second instance
OS->>Plugin: detect existing instance
Plugin->>App: invoke callback (with args)
App->>Window: get_webview_window("main")
App->>Window: set_focus()
Plugin-->>OS: prevent new instance
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @tushar1977 @rahulharpal1603! I've implemented a fix for issue #1147. This PR resolves the Tauri Error 1412 that causes the frontend to exit on Windows 11. What I did: Testing needed: The changes are minimal and non-intrusive, using a standard Tauri plugin to address the root cause of the window class conflict. Please let me know if you need any clarification or changes! 🙏 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@frontend/src-tauri/src/main.rs`:
- Around line 193-202: Replace the panicking expect() calls inside the
tauri_plugin_single_instance::init closure with a deterministic lookup and
graceful handling: call app.get_webview_window("main") (instead of
webview_windows().values().next()) to get an Option, match or if-let on that
Option and if Some(window) call window.set_focus() and handle the Result with
map_err/log or an if let Err(e) branch instead of expect; if the window is None
or set_focus() fails, log the condition and return without panicking so the
primary instance stays running.
🧹 Nitpick comments (1)
frontend/src-tauri/tauri.conf.json (1)
51-54: Pre-existing: initial size is smaller than minimum size.
width: 800/height: 600are belowminWidth: 1280/minHeight: 720. Tauri will clamp the window to the minimum, making thewidth/heightvalues misleading. Not introduced by this PR, but worth a follow-up cleanup.
- Replace .expect() calls with if-let pattern to prevent crashes
- Use deterministic get_webview_window("main") instead of .values().next()
- Improves stability by preventing panic on focus failure
Addresses CodeRabbit review feedback
|
Hi @pranitaurlam , can you attach a video before and after the change? |
Overview
Fixes #1147
This PR resolves the issue where the Tauri frontend exits shortly after startup with
Error 1412: Failed to unregister class Chrome_WidgetWin_0on Windows 11.Root Cause
Error 1412 (
ERROR_CLASS_ALREADY_EXISTS) is a Windows 11 WebView2/Chromium issue that occurs when multiple WebView2 instances attempt to register the same window class name. This causes the window to close prematurely before connecting to backend services.Changes
1. Added Single-Instance Plugin
tauri-plugin-single-instance = "2.3.1"2. Registered Single-Instance Behavior
3. Enhanced Window Configuration
"label": "main"for explicit window identification"skipTaskbar": false"for proper Windows 11 taskbar registrationTesting
Checklist
Additional Notes
This is a minimal, non-intrusive fix that:
Summary by CodeRabbit
New Features
Documentation