Skip to content

macOS: the first browser source created off the main thread (obs-websocket) never renders: CEF initializes on that thread #2387

Closed

Description

@vpacher

Summary

On macOS, when the first browser source of a session is created outside the Qt main thread, for example by obs-websocket's CreateInput, CEF initializes on that thread and no browser source renders for the rest of the session. A first browser source added in the UI (on the main thread) renders. Seen with a local build of master f598d234d (obs-browser 4583599 plus the #2386 fix), CEF 7871, macOS 26.7.1, Apple Silicon.

Cause

On macOS obs-browser runs CEF on Qt's main loop (ENABLE_BROWSER_QT_LOOP). The browser source's create callback calls obs_browser_initialize(), which then calls BrowserInit() and so CefInitialize() directly, on the calling thread (obs-browser-plugin.cpp, obs_browser_initialize() and RegisterBrowserSource()). Without the Qt loop (Linux, Windows) it starts its own CEF thread instead. When obs-websocket creates the first source, the calling thread is its IO thread, so CEF's UI thread is one that never pumps CEF's message loop.

What I saw

  • First source through obs-websocket CreateInput (local file or https://example.com): only the GPU process starts, no renderer, the source stays black. CEF's log stops after the profile is created (ProfileManager ... ClearFirstBrowserWindowKeepAlive(Default)), and 15 s later the started helpers exit: Terminating current process after 15 seconds with no connection. BrowserApp::OnContextInitialized() never runs.
  • The same with the source created 20 s after startup, and with OBS the active app: not a timing or App Nap effect.
  • First source added in the UI with https://example.com: it renders; the GPU, two utility and two renderer processes start.
  • Source created through obs-websocket first, then Properties → OK, and then a new URL, in the UI: still black, still only the GPU process. CEF stays unusable for the whole session.
  • obs-rust/obs-browser 0c3b700 is not the cause: setting cef_started_event right after CefInitialize() again does not change it.

Fix

In the Qt-loop build, run BrowserInit() on the Qt main thread whatever thread calls obs_browser_initialize() (for example QMetaObject::invokeMethod(qApp, ..., Qt::BlockingQueuedConnection) when not on the main thread). This code path is the same as upstream's, so upstream OBS is likely affected too.

Acceptance criteria

  • RED then GREEN: a test where the first browser source is created off the main thread on macOS, and it renders.
  • On macOS, a first browser source created through obs-websocket renders, and so do later ones.

Suggested: P2, size:S.

Activity

  1. changed the title [-]macOS: browser sources never render: CEF's message pump does not run on the Qt loop[/-] [+]macOS: the first browser source created off the main thread (obs-websocket) never renders: CEF initializes on that thread[/+] on Oct 25, 2026
  2. vpacher commented on Oct 25, 2026

    @vpacher
    MemberAuthor

    Correction: the first version of this issue said browser sources never render on macOS. That was wrong. With the helper names of #2386 fixed, a browser source added in the UI renders. The failure only happens when the first browser source of a session is created off the main thread (obs-websocket in my tests), so I rewrote the title and description with the narrowed cause and the tests that show it.

  3. vpacher commented on Oct 25, 2026

    @vpacher
    MemberAuthor

    Claiming: investigation

    The cause is in the description; this claim covers the fix. Plan:

    1. RED in obs-rust/obs-browser: a local test in tests/ (macOS, like the other local tests there that run real CEF) that starts OBS, creates the first browser source through obs-websocket, and requires it to render. It fails today.
    2. GREEN: in the Qt-loop build, obs_browser_initialize() runs BrowserInit() on the Qt main thread when it is called from another thread (QMetaObject::invokeMethod(..., Qt::BlockingQueuedConnection)).
    3. A real run on macOS: a first source through obs-websocket renders, and a first source added in the UI still does. Then the submodule bump here.
  4. added
    needs-investigation
    on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

needs-investigation

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions