Skip to content

feat(opencode): support multiple browsers for cookie import#373

Open
houzixiashanxiedaima wants to merge 2 commits intosteipete:mainfrom
houzixiashanxiedaima:feature/opencode-multi-browser-cookie-support
Open

feat(opencode): support multiple browsers for cookie import#373
houzixiashanxiedaima wants to merge 2 commits intosteipete:mainfrom
houzixiashanxiedaima:feature/opencode-multi-browser-cookie-support

Conversation

@houzixiashanxiedaima
Copy link

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

  • Modified OpenCodeCookieImporter.swift to use the default browser import order instead of hardcoded Chrome
  • Changed preferredBrowsers parameter from [.chrome] (required) to nil (optional), which defaults to trying all available browsers in the standard order

Testing

  • Verified that Edge is already supported in SweetCookieKit (BrowserCatalog.swift shows Edge with chromiumProfileRelativePath: "Microsoft Edge")
  • The fix uses Browser.defaultImportOrder which 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 Canary

Related Issue

Fixes: Users with Edge/Safari/Firefox cannot use OpenCode provider - "No OpenCode session cookies found in browsers" error

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
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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

Choose a reason for hiding this comment

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

P1 Badge 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
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