-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
boundEvent Error #2715
Comments
You can only use See #2246 You can use http://cefsharp.github.io/api/71.0.0/html/M_CefSharp_JavascriptBindingExtensions_EnsureObjectBoundAsync.htm to register an object in |
Really I didn't understand anything. Can't I use for more than one pages? I have to do this. Isn't there another way? If there is any way can you write a sample code related with this? |
Alex, can you add such a feature. I want able to use this at every domain. |
The
Yes, use the newer
The source contains one example already see CefSharp/CefSharp.Example/ScriptedMethods.cs Line 124 in bef5dd3
The newer |
Hello Again, I removed package files frome here. And this is more small size file. This is contains all package files. You can open whichever you want. Thanks in advance for your interest. |
As per https://github.com/cefsharp/CefSharp/blob/master/ISSUE_TEMPLATE.md#bug-report please no binaries. You will have to provide an example in an open way, github, pastebin, etc.
What don't you understand? Did you read https://github.com/cefsharp/CefSharp/wiki/General-Usage#3-how-do-you-expose-a-net-class-to-javascript For reference this issue will be closed as |
For general advice please use https://gitter.im/cefsharp/CefSharp as per https://github.com/cefsharp/CefSharp#contact |
You might find https://gist.github.com/amaitland/48adad9c7f2c57f6c17fad39b2747d00 useful also. |
Hello Alex, //Javascript Codes
(async function()
{
await CefSharp.BindObjectAsync("boundAsync");
var message="This is a test";
boundAsync.div(message);
})(); //C# Codes
ChromiumWebBrowser browser;
bool status = false;
public class BoundObject
{
public class AsyncBoundObject
{
//We expect an exception here, so tell VS to ignore
[DebuggerHidden]
public void Error()
{
throw new Exception("This is an exception coming from C#");
}
//We expect an exception here, so tell VS to ignore
[DebuggerHidden]
public string Div(string message)
{
return message;
}
}
}
public void InitCefBrowser()
{
if (!status)
{
browser = new ChromiumWebBrowser(textBox1.Text)
{
BrowserSettings =
{
DefaultEncoding = "UTF-8"
},
JsDialogHandler = new JsDialogHandler(),
Dock = DockStyle.Fill,
};
panel1.Controls.Add(browser);
browser.FrameLoadEnd += Browser_FrameLoadEnd;
status = true;
}
else
{
browser.Load(textBox1.Text);
}
var eventObject = new ScriptedMethodsBoundObject();
eventObject.EventArrived += OnJavascriptEventArrived;
try
{
browser.JavascriptObjectRepository.Register("boundAsync", new BoundObject(), isAsync: true, options: BindingOptions.DefaultBinder);
}
catch (Exception) { }
browser.JavascriptObjectRepository.ResolveObject += (sender, e) =>
{
var repo = e.ObjectRepository;
if (e.ObjectName == "boundAsync2")
{
BindingOptions bindingOptions = null; //Binding options is an optional param, defaults to null
bindingOptions = BindingOptions.DefaultBinder; //Use the default binder to serialize values into complex objects, CamelCaseJavascriptNames = true is the default
bindingOptions = new BindingOptions { CamelCaseJavascriptNames = false, Binder = (IBinder)BindingOptions.DefaultBinder }; //No camelcase of names and specify a default binder
repo.Register("boundAsync2", new AsyncBoundObject(), isAsync: true, options: bindingOptions);
}
};
}
private void button1_Click(object sender, EventArgs e)
{
InitCefBrowser();
} |
Try boundAsync.Div(message); |
I tried and I getting same error. |
I guess you already did try removing the |
I didn't try yet. I will try. So, did you try such a this? |
Now I tried, not working. I getting same error. |
Try interactive with developer tools what functions/properties you can find on |
I've created a working example at https://github.com/cefsharp/CefSharp.MinimalExample/tree/demo/javascriptbinding You can review commit cefsharp/CefSharp.MinimalExample@2febd68 to see what changes I made. There are two html pages, in the |
@ByErdem Your binding |
It looks like an example I want. I'il check this out. Thank you. |
When I first open WebBrowser, I can catch any javascript event on the browser side, but when I go to another address I can't add the boundEvent event again and I get a javascript error on the console side:
Cannot read property 'raiseEvent' of undefined.
Can you show me a solution, thanks in advance for your interest.Javascript return result:
window.boundEvent.raiseEvent("click", "Test");
The text was updated successfully, but these errors were encountered: