Skip to content

Move LegacyBindingEnabled / JavascriptBindingPropertyName to per browser settings#5231

Open
campersau wants to merge 2 commits intocefsharp:masterfrom
campersau:perbrowserbindingname
Open

Move LegacyBindingEnabled / JavascriptBindingPropertyName to per browser settings#5231
campersau wants to merge 2 commits intocefsharp:masterfrom
campersau:perbrowserbindingname

Conversation

@campersau
Copy link
Copy Markdown
Contributor

@campersau campersau commented Apr 10, 2026

Fixes: Addresses #5229 (comment)

Summary:

  • JavascriptBindingPropertyName / LegacyBindingEnabled are now settings per browser instead of global ones.

Changes:

  • Moved LegacyBindingEnabled / JavascriptBindingPropertyName / JavascriptBindingPropertyNameCamelCase to JavascriptBindingSettings.h
  • Use GetOrAdd to update existing settings
  • Make IsJavascriptBindingApiAllowed static
  • Added test using multiple browsers
  • Added usermessage to Assert.True for better debugging

How Has This Been Tested?
Unittests

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Updated documentation

Checklist:

  • Tested the code(if applicable)
  • Commented my code
  • Changed the documentation(if applicable)
  • New files have a license disclaimer
  • The formatting is consistent with the project (project supports .editorconfig)

Summary by CodeRabbit

  • New Features

    • Support for custom global object names for JavaScript bindings per browser.
  • Improvements

    • Per-browser JavaScript binding settings with caching for more reliable and efficient multi-browser behavior.
    • Legacy binding behavior now respects per-browser configuration.
  • Tests

    • Improved test diagnostics for script evaluations.
    • New test covering custom global names across multiple browsers.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 58eff331-f6d5-47e7-8e61-eeb485d85cb6

📥 Commits

Reviewing files that changed from the base of the PR and between 2d25f26 and 1c471bb.

📒 Files selected for processing (2)
  • CefSharp.BrowserSubprocess.Core/JavascriptBindingSettings.h
  • CefSharp.Test/JavascriptBinding/JavascriptBindingTests.cs
🚧 Files skipped from review as they are similar to previous changes (2)
  • CefSharp.Test/JavascriptBinding/JavascriptBindingTests.cs
  • CefSharp.BrowserSubprocess.Core/JavascriptBindingSettings.h

📝 Walkthrough

Walkthrough

Migrates JavaScript binding configuration from wrapper-level fields to per-browser JavascriptBindingSettings cached via a factory; updates OnBrowserCreated/OnContextCreated to use per-browser settings and makes IsJavascriptBindingApiAllowed static; adds three new settings properties and a multi-browser binding test.

Changes

Cohort / File(s) Summary
Wrapper changes
CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h, CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp
Removed wrapper-level binding fields (_legacyBindingEnabled, _jsBindingPropertyName*), added static JavascriptBindingSettingsFactory, switched to _browserJavascriptBindingSettings->GetOrAdd(...) on creation, and made IsJavascriptBindingApiAllowed static. Binding logic in OnContextCreated now reads from per-browser JavascriptBindingSettings.
Per-browser settings
CefSharp.BrowserSubprocess.Core/JavascriptBindingSettings.h
Added properties: LegacyBindingEnabled (default false), JavascriptBindingPropertyName (default "CefSharp"), and JavascriptBindingPropertyNameCamelCase (default "cefSharp"). Constructor initializes these before existing API-related fields.
Tests
CefSharp.Test/JavascriptBinding/JavascriptBindingTests.cs
Improved assertion diagnostics by including evaluation messages; added ShouldWorkWhenUsingCustomGlobalObjectNameInMultipleBrowsers to verify custom global binding names across multiple browser instances.

Sequence Diagram

sequenceDiagram
    participant Browser as Browser Instance
    participant Cache as Per-Browser Cache
    participant Factory as Settings Factory
    participant Context as JS Context
    participant Binder as Binding Logic

    Browser->>Cache: OnBrowserCreated(browserId) -> GetOrAdd(browserId, factory)
    Cache->>Factory: invoke JavascriptBindingSettingsFactory(int)
    Factory-->>Cache: return JavascriptBindingSettings
    Cache-->>Browser: cached settings associated with browserId

    Browser->>Context: OnContextCreated(frame)
    Context->>Cache: TryGetValue(browserId)
    Cache-->>Context: JavascriptBindingSettings (or null)
    Context->>Binder: If settings != null -> evaluate settings (names, legacy flag)
    Binder-->>Context: Apply global property / legacy root bindings as per settings
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • GoutamSarkarHyland
  • amaitland

Poem

🐰 A little rabbit sings:

Per-browser nests for bindings made,
A factory seeds each cozy glade.
No more shared names hopping about,
Each context finds its binding sprout—
Hooray, the JavaScript carrots laid! 🥕

🚥 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 clearly and specifically summarizes the main architectural change: moving per-browser binding configuration from global wrapper fields to per-browser settings.
Description check ✅ Passed The description covers all required template sections including fixes, summary, changes, testing approach, and checklist items. The author clearly explains the architectural refactor and includes relevant details.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
CefSharp.Test/JavascriptBinding/JavascriptBindingTests.cs (1)

91-122: Consider adding isolation assertions to verify per-browser settings don't leak.

The test verifies that each browser has its expected binding object, which is good. However, to fully validate per-browser isolation, consider also verifying that:

  • browser1 does not have window.cefSharp (since it has a custom name)
  • browser1 does not have window.bindingApiObject2
  • browser2 does not have window.bindingApiObject1

This would catch any accidental cross-contamination between browser instances sharing a render process.

💡 Example additional assertions
// After the existing assertions, add isolation checks:
var isolation1 = await browser1.EvaluateScriptAsync("typeof window.cefSharp === 'undefined'");
Assert.True(isolation1.Success, isolation1.Message);
Assert.True((bool)isolation1.Result, "browser1 should not have default cefSharp");

var isolation2 = await browser2.EvaluateScriptAsync("typeof window.cefSharp === 'undefined'");
Assert.True(isolation2.Success, isolation2.Message);
Assert.True((bool)isolation2.Result, "browser2 should not have default cefSharp");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CefSharp.Test/JavascriptBinding/JavascriptBindingTests.cs` around lines 91 -
122, The test ShouldWorkWhenUsingCustomGlobalObjectNameInMultipleBrowsers
currently checks that each browser exposes its expected global, but doesn't
assert that other globals are absent; add additional EvaluateScriptAsync checks
and assertions (using browser1, browser2, browser3 and Assert.True/Assert.False)
after the existing assertions to verify browser1 does not have window.cefSharp
or window.bindingApiObject2, browser2 does not have window.cefSharp or
window.bindingApiObject1, and browser3 does not have the custom names, ensuring
per-browser isolation and no render-process leakage.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@CefSharp.Test/JavascriptBinding/JavascriptBindingTests.cs`:
- Around line 91-122: The test
ShouldWorkWhenUsingCustomGlobalObjectNameInMultipleBrowsers currently checks
that each browser exposes its expected global, but doesn't assert that other
globals are absent; add additional EvaluateScriptAsync checks and assertions
(using browser1, browser2, browser3 and Assert.True/Assert.False) after the
existing assertions to verify browser1 does not have window.cefSharp or
window.bindingApiObject2, browser2 does not have window.cefSharp or
window.bindingApiObject1, and browser3 does not have the custom names, ensuring
per-browser isolation and no render-process leakage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4a007db3-794d-450b-997f-c0d3af1bb52d

📥 Commits

Reviewing files that changed from the base of the PR and between 00c8aa5 and 2d25f26.

📒 Files selected for processing (4)
  • CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp
  • CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h
  • CefSharp.BrowserSubprocess.Core/JavascriptBindingSettings.h
  • CefSharp.Test/JavascriptBinding/JavascriptBindingTests.cs

@AppVeyorBot
Copy link
Copy Markdown

@AppVeyorBot
Copy link
Copy Markdown

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