detached c04ed5c

fix(cef): use DefaultWindowInfo/DefaultBrowserSettings, store client on WebView

- Use purecef.DefaultWindowInfo() and DefaultBrowserSettings() instead of
  manual unsafe.Sizeof, removing unsafe import from factory.go
- Store client on WebView to prevent GC collection
- Move back to async BrowserHostCreateBrowser
commit
c04ed5c151d131c2f0c042229a4cc1b5c55ac88e
author
brice · · 2026-03-19 19:45 UTC
committer
brice · · 2026-03-28 04:36 UTC
parent
577c404
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
2 files · +7 -8
M internal/infrastructure/cef/factory.go +6 -8
@@ -3,7 +3,6 @@ package cef
33 import (
44 "context"
55 "sync/atomic"
6- "unsafe"
76
87 purecef "github.com/bnema/purego-cef/cef"
98
@@ -54,18 +53,17 @@ func (f *WebViewFactory) Create(_ context.Context) (port.WebView, error) {
5453 input.attachTo(pipeline.glArea)
5554 wv.input = input
5655
57- // Build a CEF client backed by our handlerSet. NewClient returns a Client
58- // that wraps the raw CEF struct with refcounting and callback vtable.
56+ // Build a CEF client backed by our handlerSet.
57+ // Store on WebView to prevent GC collection before CEF AddRef's it.
5958 client := purecef.NewClient(wv.handlers)
59+ wv.client = client
6060
6161 // Configure WindowInfo for off-screen rendering (OSR).
62- var windowInfo purecef.WindowInfo
63- windowInfo.Size = unsafe.Sizeof(windowInfo)
62+ windowInfo := purecef.DefaultWindowInfo()
6463 windowInfo.WindowlessRenderingEnabled = 1
6564
66- // Configure BrowserSettings with 60 fps for smooth rendering.
67- var settings purecef.BrowserSettings
68- settings.Size = unsafe.Sizeof(settings)
65+ // Configure BrowserSettings.
66+ settings := purecef.DefaultBrowserSettings()
6967 settings.WindowlessFrameRate = 60
7068
7169 // Create the browser asynchronously. The browser will be nil until
@@ -3,7 +3,6 @@ package cef
3 import (3 import (
4 "context"4 "context"
5 "sync/atomic"5 "sync/atomic"
6- "unsafe"
7 6
8 purecef "github.com/bnema/purego-cef/cef"7 purecef "github.com/bnema/purego-cef/cef"
9 8
@@ -54,18 +53,17 @@ func (f *WebViewFactory) Create(_ context.Context) (port.WebView, error) {
54 input.attachTo(pipeline.glArea)53 input.attachTo(pipeline.glArea)
55 wv.input = input54 wv.input = input
56 55
57- // Build a CEF client backed by our handlerSet. NewClient returns a Client56+ // Build a CEF client backed by our handlerSet.
58- // that wraps the raw CEF struct with refcounting and callback vtable.57+ // Store on WebView to prevent GC collection before CEF AddRef's it.
59 client := purecef.NewClient(wv.handlers)58 client := purecef.NewClient(wv.handlers)
59+ wv.client = client
60 60
61 // Configure WindowInfo for off-screen rendering (OSR).61 // Configure WindowInfo for off-screen rendering (OSR).
62- var windowInfo purecef.WindowInfo62+ windowInfo := purecef.DefaultWindowInfo()
63- windowInfo.Size = unsafe.Sizeof(windowInfo)
64 windowInfo.WindowlessRenderingEnabled = 163 windowInfo.WindowlessRenderingEnabled = 1
65 64
66- // Configure BrowserSettings with 60 fps for smooth rendering.65+ // Configure BrowserSettings.
67- var settings purecef.BrowserSettings66+ settings := purecef.DefaultBrowserSettings()
68- settings.Size = unsafe.Sizeof(settings)
69 settings.WindowlessFrameRate = 6067 settings.WindowlessFrameRate = 60
70 68
71 // Create the browser asynchronously. The browser will be nil until69 // Create the browser asynchronously. The browser will be nil until
M internal/infrastructure/cef/webview.go +1 -0
@@ -31,6 +31,7 @@ type WebView struct {
3131 id port.WebViewID
3232 browser purecef.Browser
3333 host purecef.BrowserHost
34+ client purecef.Client // prevent GC from collecting the client before CEF AddRef's it
3435 pipeline *renderPipeline
3536 input *inputBridge
3637 handlers *handlerSet
@@ -31,6 +31,7 @@ type WebView struct {
31 id port.WebViewID31 id port.WebViewID
32 browser purecef.Browser32 browser purecef.Browser
33 host purecef.BrowserHost33 host purecef.BrowserHost
34+ client purecef.Client // prevent GC from collecting the client before CEF AddRef's it
34 pipeline *renderPipeline35 pipeline *renderPipeline
35 input *inputBridge36 input *inputBridge
36 handlers *handlerSet37 handlers *handlerSet

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close