Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
Priyalakshmi193 opened this issue Oct 7, 2024 · 2 comments

Comments

@Priyalakshmi193
Copy link

Is there an existing issue for this?

  • I have searched both open/closed issues, no issue already exists.

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
Copy link
Member

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
Copy link
Member

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

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

No branches or pull requests

2 participants