cefsharp / CefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework
http://cefsharp.github.io/
Other
9.88k stars 2.92k forks source link

JavaScript object binding issue with CefSharp when opening a new page in winform application #4950

Closed Priyalakshmi193 closed 1 week ago

Priyalakshmi193 commented 1 month ago

Is there an existing issue for this?

CefSharp Version

117.2.20

Operating System

Windows 10

Architecture

x64

.Net Version

.NET 4.8

Implementation

WinForms

Reproduction Steps

I'm using CefSharp to bind objects via currentBrowser.JavascriptObjectRepository. The object is correctly bound and accessible on the initial page, but when I navigate to a new page in the same browser instance, the object becomes undefined. I'm using a custom life span handler to handle new page creation and re-register the object, but the issue persists.

Register CallbackObj in Mainform.

image

Re-Register the CallbackObj in CustomLifeSpanHandler

image

Expected behavior

The registered object should be accessible after opening a new page.

Actual behavior

The registered object is undefined after opening a new page.

Regression?

No response

Known Workarounds

Delay Method Calls: Add a slight delay before calling the JavaScript object to ensure it’s fully registered. You can use setTimeout in JavaScript to introduce a small pause.

Check Frame Load Event: Ensure that JavascriptObjectRepository is re-registered after each new page load, especially in multi-frame scenarios. Handle this in the FrameLoadEnd event.

Does this problem also occur in the CEF Sample Application

Yes using WPF/OffScreen command line args

Other information

No response

amaitland commented 1 month ago

CefSharp Version

117.2.20

This is an old unsupported version. Does the problem reproduce with the current supported version? (M129 at time of writing).

I'm using CefSharp to bind objects via currentBrowser.JavascriptObjectRepository. The object is correctly bound and accessible on the initial page, but when I navigate to a new page in the same browser instance, the object becomes undefined. I'm using a custom life span handler to handle new page creation and re-register the object, but the issue persists.

Please no images of code see https://idownvotedbecau.se/imageofcode

Does the problem reproduce using the MinimalExample? You can fork the MinimalExample and use this as a base for your example.

Please fork the MinimalExample and create an example that reproduces the problem. Keep the example to just the base minimum of code required to reproduce the issue. Push a copy of your branch to GitHub.

amaitland commented 1 month ago

Alternatively create a failing unit test. There are already some that could be used as a base.

https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Test/JavascriptBinding/JavascriptBindingTests.cs#L174

amaitland commented 1 week ago

Closing due to lack of feedback