Skip to content

feat: add branch support to browser extension plugin#3513

Merged
dkrizan merged 4 commits into
mainfrom
dkrizan/chrome-plugin-branching
Mar 19, 2026
Merged

feat: add branch support to browser extension plugin#3513
dkrizan merged 4 commits into
mainfrom
dkrizan/chrome-plugin-branching

Conversation

@dkrizan

@dkrizan dkrizan commented Mar 16, 2026

Copy link
Copy Markdown
Member

Summary

  • Add branch to DevCredentials type so overrideCredentials can pass branch to the SDK
  • Read __tolgee_branch from sessionStorage in BrowserExtensionPlugin and include it in credentials
  • Add branch to LibConfig type so the SDK sends its configured branch in the TOLGEE_READY handshake message
  • Clear __tolgee_branch from sessionStorage on credential reset

Related PRs

Test plan

  • Verify SDK reads branch from sessionStorage when set by chrome extension
  • Verify ?branch=X query parameter is appended to translation API calls
  • Verify SDK's own branch config is not overridden when sessionStorage key is absent
  • Verify branch is included in TOLGEE_READY handshake message to the extension

Summary by CodeRabbit

  • New Features
    • Added an optional "branch" configuration to the SDK and browser extension so users can target specific content branches and have that choice persist across sessions.
  • Tests
    • Expanded test coverage to validate branch handling, propagation, and session persistence.

Read branch from sessionStorage and pass it via overrideCredentials so the
chrome extension can control which branch translations are fetched from.
Also include branch in the LibConfig handshake message.
@coderabbitai

coderabbitai Bot commented Mar 16, 2026

Copy link
Copy Markdown

Walkthrough

Adds an optional branch field to credential/config types, persists branch in sessionStorage via a new BRANCH_LOCAL_STORAGE constant, surfaces branch in BrowserExtensionPlugin credentials/config, and updates tests to cover SDK-provided and sessionStorage-provided branch propagation.

Changes

Cohort / File(s) Summary
Core types
packages/core/src/types/plugin.ts
Added optional branch?: string to the DevCredentials object shape.
Web types
packages/web/src/package/tools/extension.ts
Added optional branch?: string to LibConfig.config.
Browser extension plugin
packages/web/src/package/BrowserExtensionPlugin/BrowserExtensionPlugin.ts
Added export const BRANCH_LOCAL_STORAGE = '__tolgee_branch'; read/write/clear branch from sessionStorage; include branch in credentials and plugin config initialization.
Core tests
packages/core/src/__test__/options.test.ts
Added tests verifying overrideCredentials accepts branch and that overriding credentials updates initial options.branch.
Web tests
packages/web/src/package/__test__/browser.extension.test.ts
Imported BRANCH_LOCAL_STORAGE; added test cleanup; added tests ensuring branch propagation from SDK config and from sessionStorage; adjusted test payloads to include branch.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A tiny branch hops into place,
Stored in session with gentle grace,
From SDK to extension it will stream,
A quiet path for a new branch dream. 🌿

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add branch support to browser extension plugin' directly and concisely summarizes the main change: adding branch support to the browser extension plugin. It matches the primary objectives of the PR.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 dkrizan/chrome-plugin-branching
📝 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/web/src/package/BrowserExtensionPlugin/BrowserExtensionPlugin.ts`:
- Around line 18-22: getCredentials currently always returns { apiKey, apiUrl,
branch } which can overwrite a configured SDK branch with undefined when
__tolgee_branch is missing; update getCredentials so it only includes branch in
the returned object when branch is defined (e.g., conditionally add branch or
filter undefined values) so merging with devCredentials or initial options does
not wipe an existing branch; look for the getCredentials function and the
variables apiKey, apiUrl, branch, and places where devCredentials/initial
options are merged to implement the conditional inclusion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 959cc751-3a7a-4a5e-a43f-827685c958da

📥 Commits

Reviewing files that changed from the base of the PR and between ad3f340 and df7e870.

📒 Files selected for processing (3)
  • packages/core/src/types/plugin.ts
  • packages/web/src/package/BrowserExtensionPlugin/BrowserExtensionPlugin.ts
  • packages/web/src/package/tools/extension.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/web/src/package/__test__/browser.extension.test.ts`:
- Around line 81-91: The test currently only asserts loadInContextLib call count
but must also verify the branch value; update the test so after running tolgee
you assert that loadInContextLib was called with an initializer object whose
credentials.branch equals 'my-branch' (e.g. use
expect(loadInContextLib).toHaveBeenCalledWith(expect.objectContaining({
credentials: expect.objectContaining({ branch: 'my-branch' }) })) so the
BrowserExtensionPlugin/TolgeeCore integration actually consumes
BRANCH_LOCAL_STORAGE.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c0d35c1c-062c-4354-99fd-ab43de72c3ad

📥 Commits

Reviewing files that changed from the base of the PR and between df7e870 and f708990.

📒 Files selected for processing (2)
  • packages/core/src/__test/options.test.ts
  • packages/web/src/package/__test__/browser.extension.test.ts

Comment thread packages/web/src/package/__test__/browser.extension.test.ts
@dkrizan dkrizan force-pushed the dkrizan/chrome-plugin-branching branch from 924b949 to 0283279 Compare March 16, 2026 18:20
JanCizmar pushed a commit to tolgee/tolgee-platform that referenced this pull request Mar 17, 2026
)

## Summary
- Add `branchingEnabled` boolean to `/v2/api-keys/current` response
(`ApiKeyWithLanguagesModel`) so clients can conditionally show
branch-related UI
- Use `ProjectFeatureGuard.isFeatureEnabled(Feature.BRANCHING)` which
checks both org-level feature flag and project-level `useBranching`
setting
- Rename `BRANCHING_NOT_ENABLED_FOR_PROJECT` to generic
`FEATURE_NOT_ENABLED_FOR_PROJECT` with feature name as parameter
- Switch `ProjectFeatureGuard` from `ValidationException` to
`BadRequestException` for consistency with `OrganizationFeatureGuard`
- Add frontend error translation for `feature_not_enabled_for_project`

## Related PRs
- chrome-plugin: tolgee/chrome-plugin#38
- tolgee-js: tolgee/tolgee-js#3513

## Test plan
- [ ] Verify `/v2/api-keys/current` response includes `branchingEnabled:
true` when branching is enabled
- [ ] Verify `branchingEnabled: false` when branching feature is
disabled at org level
- [ ] Verify `branchingEnabled: false` when project has `useBranching =
false`
- [ ] Verify `FEATURE_NOT_ENABLED_FOR_PROJECT` error includes the
feature name
- [ ] Verify frontend displays translated error message for
`feature_not_enabled_for_project`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* API key info now includes whether branching is enabled for the project
(visible in API responses and client schema).

* **Improvements**
* Error reporting for disabled features renamed and clarified; messages
now indicate which feature is unavailable and client error
codes/translations were updated accordingly.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@dkrizan dkrizan requested a review from JanCizmar March 17, 2026 13:15
@dkrizan dkrizan merged commit 81e2164 into main Mar 19, 2026
30 checks passed
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.

2 participants