Skip to content

Share browser context with OAuth popups#1600

Merged
lawrencecchen merged 2 commits intomainfrom
task-google-oauth-shared-popup-context
Mar 20, 2026
Merged

Share browser context with OAuth popups#1600
lawrencecchen merged 2 commits intomainfrom
task-google-oauth-shared-popup-context

Conversation

@lawrencecchen
Copy link
Copy Markdown
Contributor

@lawrencecchen lawrencecchen commented Mar 17, 2026

Summary

  • add regression tests covering browser popup process pool and website data store inheritance
  • configure popup web views to inherit the opener browser context so OAuth popups can use window.opener and postMessage

Testing

  • xcodebuild test -project GhosttyTabs.xcodeproj -scheme cmux-unit -destination 'platform=macOS' -derivedDataPath /tmp/cmux-task-google-oauth-shared-popup-context-tests -only-testing:cmuxTests/BrowserPanelPopupContextTests (fails on the test-only commit, passes with the fix)

Task

  • Google OAuth login does not work in the cmux browser. Clicking Continue with Google on sites like Figma opens the OAuth popup as a separate surface, which breaks window.opener communication and prevents the token from being passed back to the parent window.

Summary by cubic

Fix Google OAuth popups by sharing the opener browser context with popup WKWebViews. OAuth windows now keep cookies/storage and window.opener/postMessage linkage so sign-in flows (e.g., Figma) complete.

  • Bug Fixes

    • Popups inherit the opener processPool and websiteDataStore, preserving cookies/storage and opener linkage required for OAuth.
    • Added regression tests covering process pool and data store inheritance, including remote workspace stores.
    • Aligned popup behavior with main views (theme background, Safari user agent).
  • Refactors

    • Extracted BrowserPanel.configureWebViewConfiguration(...) to centralize and reuse WebView setup across panels and popups.

Written for commit 4c66f46. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes

    • Popup windows now correctly inherit browser context from opener windows, ensuring consistent data storage and process management
    • Popup background color now aligns with the current application theme
  • Tests

    • Added tests for popup context inheritance to verify reliable behavior

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cmux Ready Ready Preview, Comment Mar 17, 2026 11:54am

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

This PR refactors WKWebViewConfiguration setup in BrowserPanel into a reusable static helper method and applies it to browser popups so they inherit the opener's browser context, including process pool and website data store, with supporting tests added.

Changes

Cohort / File(s) Summary
Configuration Centralization
Sources/Panels/BrowserPanel.swift
Extracted web view configuration logic into a new static helper method configureWebViewConfiguration(_:websiteDataStore:processPool:) that centrally manages process pool, user action playback settings, website data store, developer extras, content JavaScript, and user scripts. Refactored makeWebView to delegate configuration to this helper.
Popup Context Inheritance
Sources/Panels/BrowserPopupWindowController.swift
Updated popup creation to compute and inherit the opener's browser context via configureWebViewConfiguration, applying the opener's websiteDataStore and processPool to the popup. Added background color configuration aligned with the current theme.
Test Coverage
cmuxTests/GhosttyConfigTests.swift
Added BrowserPanelPopupContextTests test suite with two tests verifying floating popup inheritance of opener's processPool/websiteDataStore and remote workspace's websiteDataStore. Note: Test suite defined twice in file (duplicate).

Sequence Diagram

sequenceDiagram
    participant Opener as Opener Panel
    participant Popup as BrowserPopupWindowController
    participant Config as BrowserPanel<br/>(Helper)
    participant WebView as WKWebView

    Opener->>Popup: Create popup window
    Popup->>Popup: Compute browserContextSource<br/>from parent/opener
    Popup->>Config: configureWebViewConfiguration<br/>(config, websiteDataStore, processPool)
    Config->>Config: Apply processPool,<br/>settings, scripts
    Popup->>WebView: Create WKWebView<br/>with configured config
    Popup->>WebView: Set background color<br/>from theme
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A helper hops to life, so neat and clean,
Configuration centralized—a rabbit's dream!
Popups inherit their opener's way,
Process pools dance, websites all stay,
One helper rules them all today! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change—enabling OAuth popups to share browser context with their opener for proper window.opener/postMessage communication.
Description check ✅ Passed The description includes a clear Summary section explaining what changed and why, comprehensive Testing section with specific xcodebuild command, and checklist items addressed. Auto-generated cubic summary provides additional context.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task-google-oauth-shared-popup-context
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
Sources/Panels/BrowserPanel.swift (1)

2376-2391: Make user-script registration idempotent for popup-provided configurations.

When WKUIDelegate.webView(_:createWebViewWith:for:windowFeatures:) is called, the provided WKWebViewConfiguration inherits the opener's user scripts. Calling configureWebViewConfiguration() at lines 97–101 in BrowserPopupWindowController unconditionally appends the telemetry and address-bar-focus scripts again, causing duplication on popup creation.

Proposed fix
+        let existingSources = Set(configuration.userContentController.userScripts.map(\.source))
+        if !existingSources.contains(Self.telemetryHookBootstrapScriptSource) {
+            configuration.userContentController.addUserScript(
+                WKUserScript(
+                    source: Self.telemetryHookBootstrapScriptSource,
+                    injectionTime: .atDocumentStart,
+                    forMainFrameOnly: false
+                )
+            )
+        }
         // Track the last editable focused element continuously so omnibar exit can
         // restore page input focus even if capture runs after first-responder handoff.
+        if !existingSources.contains(Self.addressBarFocusTrackingBootstrapScript) {
+            configuration.userContentController.addUserScript(
+                WKUserScript(
+                    source: Self.addressBarFocusTrackingBootstrapScript,
+                    injectionTime: .atDocumentStart,
+                    forMainFrameOnly: false
+                )
+            )
+        }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Sources/Panels/BrowserPanel.swift` around lines 2376 - 2391, Make user-script
registration idempotent by checking for existing user scripts before adding the
telemetry and focus scripts: when configuring a WKWebViewConfiguration (the call
site that currently calls configuration.userContentController.addUserScript with
Self.telemetryHookBootstrapScriptSource and
Self.addressBarFocusTrackingBootstrapScript), inspect
configuration.userContentController.userScripts and skip adding if a
WKUserScript exists with the same source, injectionTime and forMainFrameOnly for
each of Self.telemetryHookBootstrapScriptSource and
Self.addressBarFocusTrackingBootstrapScript; apply this change where
configureWebViewConfiguration is invoked (including BrowserPopupWindowController
handling of WKUIDelegate.webView(_:createWebViewWith:for:windowFeatures:)) so
popup-created configurations don’t accumulate duplicates.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@Sources/Panels/BrowserPanel.swift`:
- Around line 2376-2391: Make user-script registration idempotent by checking
for existing user scripts before adding the telemetry and focus scripts: when
configuring a WKWebViewConfiguration (the call site that currently calls
configuration.userContentController.addUserScript with
Self.telemetryHookBootstrapScriptSource and
Self.addressBarFocusTrackingBootstrapScript), inspect
configuration.userContentController.userScripts and skip adding if a
WKUserScript exists with the same source, injectionTime and forMainFrameOnly for
each of Self.telemetryHookBootstrapScriptSource and
Self.addressBarFocusTrackingBootstrapScript; apply this change where
configureWebViewConfiguration is invoked (including BrowserPopupWindowController
handling of WKUIDelegate.webView(_:createWebViewWith:for:windowFeatures:)) so
popup-created configurations don’t accumulate duplicates.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9a7e338d-42b6-4d4e-b10b-136bc192956a

📥 Commits

Reviewing files that changed from the base of the PR and between 8d8fadb and 4c66f46.

📒 Files selected for processing (3)
  • Sources/Panels/BrowserPanel.swift
  • Sources/Panels/BrowserPopupWindowController.swift
  • cmuxTests/GhosttyConfigTests.swift

@lawrencecchen lawrencecchen merged commit cc0fc55 into main Mar 20, 2026
16 checks passed
bn-l pushed a commit to bn-l/cmux that referenced this pull request Apr 3, 2026
* Add popup browser context regression tests

* Share browser context with OAuth popups

---------

Co-authored-by: Lawrence Chen <lawrencecchen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant