Skip to content

fix(desktop): remove the Electron token from the built-in browser user agent - #55788

Closed
sathwick-p wants to merge 2 commits into
anomalyco:devfrom
sathwick-p:browser-user-agent
Closed

sathwick-p wants to merge 2 commits into
anomalyco:devfrom
sathwick-p:browser-user-agent

Conversation

@sathwick-p

Copy link
Copy Markdown

Issue for this PR

Closes #55730

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The built-in browser's session never set a user agent, so pages got Electron's default, which includes Electron/<version>. Sites that parse the user agent read that as a separate browser. Medium, for example, sends you to "Start writing in the Medium app" instead of opening the editor.

This sets the user agent once on the browser partition, with only the Electron/ token removed. The OpenCode/<version> token and the real Chrome version stay. Tabs and popups share that partition, so they all pick it up. The app window is unchanged.

How did you verify your code works?

  • Ran bun run dev:desktop, opened the browser panel and checked navigator.userAgent: ... OpenCodeDev/2.0.29 Chrome/152.0.7977.130 Safari/537.36, no Electron/.
  • Loaded https://httpbin.org/headers in the built-in browser. The User-Agent header the server received matches, so it holds through the browser proxy.
  • With the token removed, ua-parser-js and Bowser report Chrome instead of Electron.
  • bun run check, bun typecheck and bun test src/browser in packages/gui-extensions, and bun run lint:changed all pass.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent 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.

Looks correct to me. The user agent is set once on the attachment's own opencode-browser-<uuid> partition, so tabs, popups and the proxy's net.request all get it, and the app window is untouched. The regex removes only the Electron/<version> token from Electron's default user agent. I couldn't run the desktop browser panel in this sandbox (no Electron or display), so I checked the code and ran typecheck, bun test src/browser (33 pass) and oxlint on pane.ts in packages/gui-extensions; all are clean. A maintainer with Desktop can confirm by checking navigator.userAgent in the panel.

Public API is unchanged.

No blocking concerns.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove Electron token from built-in browser user agent

1 participant