Skip to content

fix(browser): add native-UA session profiles - #12608

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/google-cookie-staleness-investigation
Aug 5, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/google-cookie-staleness-investigation

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

  • let users create an isolated browser profile that keeps Electron's unmodified user agent
  • keep Orca's cleaned Chrome-shaped UA as the default for Cloudflare compatibility
  • preserve a single, stable UA identity for the profile across redirects and subresources
  • expose the opt-out in Settings, the browser toolbar, runtime RPC, and orca tab profile create --no-ua-spoof
  • add a repeatable Google sign-in UA probe for future regression investigation

Google sign-in testing consistently reached /v3/signin/rejected with Orca's cleaned Chrome-shaped UA and reached normal account lookup with the untouched Electron UA. A fresh sign-in under the untouched UA also completed and remained usable for 92 minutes. This PR therefore adds a narrow opt-out rather than changing the default or switching identity by destination host.

Closes #11518

Screenshots

Profile creation option:

New browser profile dialog with Use unmodified user agent option

Persisted profile label:

Browser settings showing an Unmodified user agent profile

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test — 9 focused files / 166 tests passed instead
  • pnpm build — no dependency or packaging changes
  • Added or updated high-quality tests that would catch regressions

Additional validation:

  • Google UA probe: cleaned UA rejected; untouched Electron UA reached account lookup
  • probe syntax: node --check tests/tools/google-signin-ua-probe.cjs
  • Electron QA: option defaults off, toggles, resets after creation, persists userAgentMode: "native", and appears on the profile row

AI Review Report

Reviewed the user-agent precedence and lifecycle end to end: persisted imported-browser UA first, then the profile's native/clean fallback choice before first navigation. Checked metadata hydration and validation, profile creation through trusted local IPC and remote runtime RPC, CLI parsing, deletion cleanup, UI state reset, and client-hint behavior. The review rejected destination-host UA switching because it would create one session under inconsistent request and JavaScript-visible identities.

Cross-platform review: production changes add no OS-specific paths, shell commands, shortcuts, or labels. The profile option flows through local IPC and runtime RPC, so it applies to local, SSH, and folder-workspace use without assuming a git worktree. Behavior is the same on macOS, Linux, and Windows; the live Google measurement and Electron screenshot QA were run on macOS.

Security Audit

The new mode is a closed enum validated at RPC and registry boundaries, and persisted profiles still pass the owned-partition allowlist before hydration. Local profile creation remains restricted to the trusted browser renderer. No cookies, auth tokens, or secrets are logged; no dependency, command-execution, or new filesystem-path input is introduced in production code. The diagnostic probe accepts a test account identifier and records navigation/request metadata, but does not accept or store passwords.

Notes

  • Existing profiles and newly created profiles keep today's cleaned UA unless the user explicitly opts out.
  • A UA persisted by native browser import still wins over the fallback mode, preserving source-browser fidelity.
  • Native mode also avoids Orca's client-hint override, keeping the request headers consistent with Electron's UA.
  • Google embedded-browser policy and detection behavior are external and undocumented; this is a compatibility option, not a guarantee.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@brennanb2025, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 4 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1485f904-d2ed-48a3-a055-ad06a1fa2e27

📥 Commits

Reviewing files that changed from the base of the PR and between 3feec07 and 358ca6e.

📒 Files selected for processing (6)
  • src/main/browser/browser-manager.test.ts
  • src/main/browser/browser-manager.ts
  • src/main/browser/browser-session-registry.test.ts
  • src/main/browser/browser-session-registry.ts
  • src/main/browser/offscreen-browser-backend.ts
  • src/main/ipc/browser.ts
📝 Walkthrough

Walkthrough

Browser profiles now support optional clean or native user-agent modes. The setting persists through profile creation, validation, hydration, IPC, RPC, preload APIs, and renderer state. Browser dialogs and CLI commands expose native user-agent selection. Profile listings and rows display native-mode metadata. Tests cover registry behavior, persistence, API forwarding, CLI handling, and UI interaction. A standalone Electron probe logs user-agent and Client Hint behavior during Google sign-in navigation.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: adding browser session profiles with native user-agent support.
Description check ✅ Passed The description covers the required summary, screenshots, testing, AI review, security audit, and platform notes.
Linked Issues check ✅ Passed The changes satisfy issue #11518 by adding opt-out native UA profiles while preserving the cleaned UA default and stable session identity.
Out of Scope Changes check ✅ Passed All changes support the linked issue objectives, including the explicitly requested Google sign-in UA probe and related regression tests.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b07a93cc-8103-4afe-a1f5-0e0b4f88ad10

📥 Commits

Reviewing files that changed from the base of the PR and between dc5c5a8 and 3feec07.

📒 Files selected for processing (27)
  • src/cli/browser-format.ts
  • src/cli/browser.test.ts
  • src/cli/handlers/browser-profile.ts
  • src/cli/help.ts
  • src/cli/specs/browser-basic.ts
  • src/main/browser/browser-session-registry.persistence.test.ts
  • src/main/browser/browser-session-registry.test.ts
  • src/main/browser/browser-session-registry.ts
  • src/main/ipc/browser-session-profile-ipc.test.ts
  • src/main/ipc/browser.ts
  • src/main/runtime/orca-runtime-browser.test.ts
  • src/main/runtime/orca-runtime-browser.ts
  • src/main/runtime/rpc/methods/browser-schemas.ts
  • src/main/runtime/rpc/methods/browser.test.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/browser-pane/BrowserToolbarMenu.tsx
  • src/renderer/src/components/browser-pane/browser-toolbar-profile-dialogs.tsx
  • src/renderer/src/components/browser-profile-user-agent-option.test.tsx
  • src/renderer/src/components/browser-profile-user-agent-option.tsx
  • src/renderer/src/components/settings/BrowserNewProfileDialog.tsx
  • src/renderer/src/components/settings/BrowserProfileRow.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/store/slices/browser.test.ts
  • src/renderer/src/store/slices/browser.ts
  • src/shared/types.ts
  • tests/tools/google-signin-ua-probe.cjs

Comment on lines +46 to +71
it('forwards the user-agent mode from a trusted renderer', () => {
const profile = {
id: 'profile-google',
scope: 'isolated',
partition: 'persist:orca-browser-session-profile-google',
label: 'Google',
source: null,
userAgentMode: 'native'
}
createProfileMock.mockReturnValue(profile)
registerBrowserHandlers()
const createHandler = handleMock.mock.calls.find(
([channel]) => channel === 'browser:session:createProfile'
)?.[1] as (
event: { sender: Electron.WebContents },
args: { scope: 'isolated'; label: string; userAgentMode: 'native' }
) => unknown
const sender = {
id: 91,
isDestroyed: () => false,
getType: () => 'window',
getURL: () => 'file:///renderer/index.html'
} as Electron.WebContents

expect(
createHandler({ sender }, { scope: 'isolated', label: 'Google', userAgentMode: 'native' })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Register the test sender as trusted.

The test resets the trusted renderer ID to null. It never registers sender ID 91 before calling the handler. Set ID 91 before registerBrowserHandlers() so this test proves the permitted trusted-renderer path.

Proposed fix
     }
     createProfileMock.mockReturnValue(profile)
+    setTrustedBrowserRendererWebContentsId(91)
     registerBrowserHandlers()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('forwards the user-agent mode from a trusted renderer', () => {
const profile = {
id: 'profile-google',
scope: 'isolated',
partition: 'persist:orca-browser-session-profile-google',
label: 'Google',
source: null,
userAgentMode: 'native'
}
createProfileMock.mockReturnValue(profile)
registerBrowserHandlers()
const createHandler = handleMock.mock.calls.find(
([channel]) => channel === 'browser:session:createProfile'
)?.[1] as (
event: { sender: Electron.WebContents },
args: { scope: 'isolated'; label: string; userAgentMode: 'native' }
) => unknown
const sender = {
id: 91,
isDestroyed: () => false,
getType: () => 'window',
getURL: () => 'file:///renderer/index.html'
} as Electron.WebContents
expect(
createHandler({ sender }, { scope: 'isolated', label: 'Google', userAgentMode: 'native' })
it('forwards the user-agent mode from a trusted renderer', () => {
const profile = {
id: 'profile-google',
scope: 'isolated',
partition: 'persist:orca-browser-session-profile-google',
label: 'Google',
source: null,
userAgentMode: 'native'
}
createProfileMock.mockReturnValue(profile)
setTrustedBrowserRendererWebContentsId(91)
registerBrowserHandlers()
const createHandler = handleMock.mock.calls.find(
([channel]) => channel === 'browser:session:createProfile'
)?.[1] as (
event: { sender: Electron.WebContents },
args: { scope: 'isolated'; label: string; userAgentMode: 'native' }
) => unknown
const sender = {
id: 91,
isDestroyed: () => false,
getType: () => 'window',
getURL: () => 'file:///renderer/index.html'
} as Electron.WebContents
expect(
createHandler({ sender }, { scope: 'isolated', label: 'Google', userAgentMode: 'native' })

Comment on lines +147 to +158
const window = new BrowserWindow({
show: true,
title: `Google sign-in UA probe: ${mode}`,
width: 980,
height: 840,
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
partition,
sandbox: true
}
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== file outline/stat =="
wc -l tests/tools/google-signin-ua-probe.cjs
echo

echo "== relevant file section =="
sed -n '1,220p' tests/tools/google-signin-ua-probe.cjs | nl -ba | sed -n '1,220p'

echo
echo "== window close / app quit occurrences =="
rg -n "app\.quit|setExitProcess|BrowserWindow|closed|ready|createWindow|quit|allowRendererProcessReuse" tests/tools/google-signin-ua-probe.cjs tests -S || true

Repository: stablyai/orca

Length of output: 287


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== relevant file section =="
sed -n '1,220p' tests/tools/google-signin-ua-probe.cjs | awk '{printf "%5d\t%s\n", NR, $0}'

echo
echo "== window close / app quit occurrences in probe file =="
grep -nE "app\.quit|setExitProcess|BrowserWindow|closed|ready|createWindow|quit|allowRendererProcessReuse|autoLaunch" tests/tools/google-signin-ua-probe.cjs || true

echo
echo "== Electron version hints =="
for f in package.json package-lock.json yarn.lock pnpm-lock.yaml; do
  [ -f "$f" ] && { echo "--- $f ---"; grep -nE '"?electron"?|electron@|electron:' "$f" | head -20 || true; }
done

echo
echo "== all app.quit occurrences in tests/tools =="
grep -R -n "app\.quit" tests/tools || true

Repository: stablyai/orca

Length of output: 11637


🌐 Web query:

Electron BrowserWindow alwaysOnTop macOS app.quit when closing last window default behavior

💡 Result:

In Electron, the default behavior for closing the last window is determined by the window-all-closed event [1][2]. If you do not subscribe to this event, the application will quit automatically when all windows are closed [1][2]. However, it is standard practice in Electron applications to subscribe to this event and specifically prevent the application from quitting on macOS [3][4], as macOS design guidelines prefer that applications remain active even when no windows are open [3][4]. The presence of a BrowserWindow with alwaysOnTop: true does not change the default quit behavior or how the app handles the window-all-closed event [5][2]. Whether a window is always-on-top or not, closing that window triggers the same lifecycle events [5]. If the last window is closed—regardless of its always-on-top status—the window-all-closed event will be emitted [1][2]. Commonly, developers implement this logic to align with macOS conventions: app.on('window-all-closed', => { if (process.platform!== 'darwin') { app.quit; } }); In this implementation: 1. On Windows and Linux, the application quits when all windows are closed [3][4]. 2. On macOS (darwin), the application remains active in the background when the last window is closed, allowing the user to continue using the menu bar or open new windows [3][4]. The application will only quit when the user explicitly triggers a quit (e.g., Cmd + Q) or the developer calls app.quit elsewhere in the application lifecycle [1][3]. If you find that an always-on-top window is preventing the application from quitting during an explicit app.quit call, it is typically because the window has been configured in a way that prevents it from closing (e.g., by overriding the close event or setting the window as un-closable) [6]. The always-on-top status itself is a window-level display property and does not create an inherent dependency that blocks the application from terminating [5].

Citations:


Quit when the probe window closes.

This standalone probe opens a single BrowserWindow, so closing it leaves Electron running on macOS unless the app quits explicitly.

Proposed fix
   const window = new BrowserWindow({
     // ...
   })
+
+  window.once('closed', () => {
+    app.quit()
+  })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const window = new BrowserWindow({
show: true,
title: `Google sign-in UA probe: ${mode}`,
width: 980,
height: 840,
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
partition,
sandbox: true
}
})
const window = new BrowserWindow({
show: true,
title: `Google sign-in UA probe: ${mode}`,
width: 980,
height: 840,
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
partition,
sandbox: true
}
})
window.once('closed', () => {
app.quit()
})

Source: Coding guidelines

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron QA after commit 358ca6e:

  • Confirmed the option defaults off, toggles on, and creates an isolated profile through the visible Settings UI.
  • Confirmed the persisted profile uses native user-agent mode and the profile row reports Unmodified user agent.

Native user-agent profile option enabled

Persisted native user-agent profile in Browser settings

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Exact-head live Google admission test on 358ca6e passed.

Environment: Electron 43.1.0 / Chromium 150.0.7871.47, fresh throwaway partition per arm, unique nonexistent Gmail identifier per arm, CDP attached, no account credentials.

  • Cleaned-UA control: navigated to /v3/signin/rejected and displayed “This browser or app may not be secure.”
  • Native-UA arm: stayed on the normal identifier flow and displayed “Couldn’t find this account,” proving Google performed account lookup instead of rejecting the embedded browser.

Cleaned-UA control:

Google rejects the cleaned-UA control

Native-UA profile:

Google performs normal account lookup with native Electron UA

This verifies the fresh-sign-in admission fix on the final PR head. It does not repeat the earlier real-account credentials/2FA and 92-minute session-duration test.

@brennanb2025
brennanb2025 merged commit 0ce108d into main Aug 5, 2026
48 checks passed
brennanb2025 added a commit that referenced this pull request Aug 9, 2026
…port (STA-3514)

Delete the import-time UA synthesis entirely instead of patching its version
detection. The session now always keeps the engine-derived UA the registry
sets at startup (clean or native), for imported and non-imported profiles
alike.

Why deletion is the fix:
- The synthesis read CFBundleShortVersionString, which on forks is a
  marketing version — Arc imports presented Chrome/1.x and sites rejected
  the browser as ancient (STA-3514).
- Its stated purpose (keep Google-bound cookies valid) is handled by
  isGoogleSourceBoundCookie excluding those cookies since #736, and #12884
  measured that Google rejects re-transplants regardless of UA identity.
- #12608 measured the synthesized Chrome-shaped UA reaching
  /v3/signin/rejected while the engine UA reached account lookup.

Persisted userAgent/userAgentByPartition meta is no longer read; legacy keys
drop off on the next meta write. The #12811 gate existed only to catch bad
synthesized values, so it leaves with the synthesis.
brennanb2025 added a commit that referenced this pull request Aug 10, 2026
…port (STA-3514) (#12849)

* fix(browser): stop impersonating the source browser's UA on cookie import (STA-3514)

Delete the import-time UA synthesis entirely instead of patching its version
detection. The session now always keeps the engine-derived UA the registry
sets at startup (clean or native), for imported and non-imported profiles
alike.

Why deletion is the fix:
- The synthesis read CFBundleShortVersionString, which on forks is a
  marketing version — Arc imports presented Chrome/1.x and sites rejected
  the browser as ancient (STA-3514).
- Its stated purpose (keep Google-bound cookies valid) is handled by
  isGoogleSourceBoundCookie excluding those cookies since #736, and #12884
  measured that Google rejects re-transplants regardless of UA identity.
- #12608 measured the synthesized Chrome-shaped UA reaching
  /v3/signin/rejected while the engine UA reached account lookup.

Persisted userAgent/userAgentByPartition meta is no longer read; legacy keys
drop off on the next meta write. The #12811 gate existed only to catch bad
synthesized values, so it leaves with the synthesis.

* test(browser): catch source UA impersonation regression
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(browser): add native-UA session profiles

* test(browser): add Google sign-in UA probe

* fix(browser): preserve native profile UA identity
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…port (STA-3514) (stablyai#12849)

* fix(browser): stop impersonating the source browser's UA on cookie import (STA-3514)

Delete the import-time UA synthesis entirely instead of patching its version
detection. The session now always keeps the engine-derived UA the registry
sets at startup (clean or native), for imported and non-imported profiles
alike.

Why deletion is the fix:
- The synthesis read CFBundleShortVersionString, which on forks is a
  marketing version — Arc imports presented Chrome/1.x and sites rejected
  the browser as ancient (STA-3514).
- Its stated purpose (keep Google-bound cookies valid) is handled by
  isGoogleSourceBoundCookie excluding those cookies since stablyai#736, and stablyai#12884
  measured that Google rejects re-transplants regardless of UA identity.
- stablyai#12608 measured the synthesized Chrome-shaped UA reaching
  /v3/signin/rejected while the engine UA reached account lookup.

Persisted userAgent/userAgentByPartition meta is no longer read; legacy keys
drop off on the next meta write. The stablyai#12811 gate existed only to catch bad
synthesized values, so it leaves with the synthesis.

* test(browser): catch source UA impersonation regression
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.

[Bug]: Google sign-in is impossible in the in-app browser — the UA laundering added in #885 is what Google rejects

1 participant