edge: don't take the host process down when the WebView2 controller/environment can't be created (session 0) - #87
Open
peterpla wants to merge 1 commit into
Open
Conversation
Owner
|
Woah, I don't think I ever expected anyone to try go-webview2 in Session 0. I don't really have a policy for LLM patches yet but this looks trivial enough that it is probably not worth worrying about. I should probably run this locally before merging it but it does LGTM. |
Author
|
Headless browser-based webcam image captures on a schedule (e.g., sunrise to sunset, every 5 minutes), auto-start as session-0 lets captures continue before the user logs in. Not an obvious scenario :) Thanks for your work on go-webview2! |
…an't be created On a non-visible window station (Windows session 0, no interactive desktop), controller creation completes with a success HRESULT but a nil controller. CreateCoreWebView2ControllerCompleted checked only the HRESULT and then dereferenced the controller, panicking the process inside webview.New; EnvironmentCompleted log.Fatalf'd on its failure path. Guard both pointers, record the failure, unblock Embed's message pump, and return false from Embed so New returns nil and the caller can fall back. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
peterpla
force-pushed
the
fix/session0-nil-controller
branch
from
August 17, 2026 21:51
525372f to
d46c29b
Compare
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.
What
On a non-visible window station — a process in Windows session 0 with no
interactive desktop (a service, an S4U scheduled task, a boot task) — WebView2
controller creation completes with a success HRESULT but a nil controller.
CreateCoreWebView2ControllerCompletedguards only the HRESULT, then dereferencesthe controller, so the host process panics on a nil pointer inside
webview.New.EnvironmentCompletedhas the same shape vialog.Fatalf, which also exits theprocess. Neither lets the caller fall back to a non-GUI path.
Fixes #86.
Change
pkg/edge/chromium.go— wire the async failures into the nil-return contractNewalready has (New→ nil whenCreateWithOptions→Embedreturns false),with no public signature change:
int32(res) < 0(HRESULT is signed 32-bit) and guardcontroller/envfor nil in the two completion callbacks; on failure, record anembedErrand setinitedto unblockEmbed's message pump instead oflog.Fatalf/dereferencing nil.Embedreturns false whenembedErris set (matching its existinglog.Printf(...); return falsefor other setup failures), soNewreturns nil.Note on the width: the observed failure HRESULT is
0x8000401a, which is negativeas
int32but not asint64— so the originalint64(res) < 0never fired fora real failure code. Narrowing to
int32makes the HRESULT branch work; the nilguard additionally covers a nil out-pointer returned alongside a success HRESULT.
Verification
Standalone program calling only
webview.New(false), launched on a session-0window station (over PowerShell Direct), Windows 10 + WebView2 Evergreen
151.0.4129.86:chromium.go:190, process exit 2.webview.Newreturns nil, process exit 0.Both runs confirmed a non-visible (session-0) window station.
Scope
A smaller change is possible if preferred: the controller nil-guard alone fixes the
crash, and the
log.Fatalf→ error-return part can be dropped.