Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CefGlue.Common/CommonBrowserAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private void NavigateTo(string url)
// Remove leading whitespace from the URL
url = url.TrimStart();

// to play safe, load url must be called after OnBrowserCreated(CefBrowser) which runs on CefThreadId.UI,
// to play safe, load url must be called after OnBrowserCreated(CefBrowser) which runs on CefThreadId.UI,
// otherwise the navigation will be aborted
ActionTask.Run(() =>
{
Expand Down Expand Up @@ -599,6 +599,8 @@ void ICefBrowserHost.HandleLoadStart(CefBrowser browser, CefFrame frame, CefTran

void ICefBrowserHost.HandleLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode)
{
// Register all objects
_objectRegistry.SetBrowser(browser);
Copy link

@AndreBooysen AndreBooysen Dec 26, 2024

Choose a reason for hiding this comment

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

In my scenario I needed to make sure that the objects are already registered during the page load, so I called this method inside HandleLoadStart instead.

LoadEnd?.Invoke(_eventsEmitter, new LoadEndEventArgs(frame, httpStatusCode));
}

Expand Down
9 changes: 5 additions & 4 deletions CefGlue.Common/ObjectBinding/NativeObjectRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class NativeObjectRegistry : IDisposable
private readonly object _registrationSyncRoot = new object();

/// <summary>
///
///
/// </summary>
/// <param name="obj"></param>
/// <param name="name"></param>
Expand All @@ -24,7 +24,7 @@ public bool Register(object obj, string name, MethodCallHandler methodHandler =
{
return false;
}

var nativeObj = new NativeObject(name, obj, methodHandler);

lock (_registrationSyncRoot)
Expand All @@ -36,8 +36,9 @@ public bool Register(object obj, string name, MethodCallHandler methodHandler =
}

_registeredObjects.Add(name, nativeObj);

if (_browser != null)

// If the browser is loading the object will be registered by CommonBrowserAdapter.HandleLoadEnd
if (_browser != null && !_browser.IsLoading)
{
SendRegistrationMessage(nativeObj);
}
Expand Down
Loading