feat(opencode): support multiple browsers for cookie import#373
Conversation
Previously OpenCode only attempted to import cookies from Chrome, hardcoded as preferredBrowsers: [.chrome]. This caused issues for users who use other browsers like Edge, Safari, or Firefox. Now uses the default browser import order (Safari → Chrome → Edge → Brave → Arc → ...) when no preferred browsers are specified, allowing users to authenticate with OpenCode in any supported browser. Fixes: Users with Edge/Safari/Firefox cannot use OpenCode provider
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d455a408d0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let installedBrowsers = preferredBrowsers.isEmpty | ||
| ? opencodeCookieImportOrder.cookieImportCandidates(using: browserDetection) | ||
| : preferredBrowsers.cookieImportCandidates(using: browserDetection) | ||
| let browsersToTry = preferredBrowsers ?? opencodeCookieImportOrder |
There was a problem hiding this comment.
Fall through to later browsers after invalid credentials
Defaulting preferredBrowsers to the full opencodeCookieImportOrder now makes importSession return the first browser that merely has an auth cookie, even if that cookie is stale; in setups where an earlier browser (for example Safari) has expired OpenCode cookies and a later browser has a valid session, OpenCodeUsageFetchStrategy.fetch will hit invalidCredentials, clear cache, and re-import the same first stale source again, so the request never reaches the valid browser. This breaks the intended multi-browser fallback in exactly the environments this change targets.
Useful? React with 👍 / 👎.
- Add excludeBrowsers parameter to importSession for multi-browser fallback - On invalidCredentials error, exclude the failed browser and retry with next valid browser - This ensures users with stale cookies in one browser can fall back to another browser
Summary
Previously OpenCode only attempted to import cookies from Chrome, hardcoded as
preferredBrowsers: [.chrome]. This caused issues for users who use other browsers like Edge, Safari, or Firefox.Now uses the default browser import order (Safari → Chrome → Edge → Brave → Arc → ...) when no preferred browsers are specified, allowing users to authenticate with OpenCode in any supported browser.
Changes
OpenCodeCookieImporter.swiftto use the default browser import order instead of hardcoded ChromepreferredBrowsersparameter from[.chrome](required) tonil(optional), which defaults to trying all available browsers in the standard orderTesting
chromiumProfileRelativePath: "Microsoft Edge")Browser.defaultImportOrderwhich includes: Safari → Chrome → Edge → Brave → Arc → Dia → ChatGPT Atlas → Chromium → Helium → Vivaldi → Firefox → Zen → Chrome Beta → Chrome Canary → Arc Beta → Arc Canary → Brave Beta → Brave Nightly → Edge Beta → Edge CanaryRelated Issue
Fixes: Users with Edge/Safari/Firefox cannot use OpenCode provider - "No OpenCode session cookies found in browsers" error