-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Feature Request - Add Javascript CefSharp.PostMessage #2775
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
Comments
Use Cases:
Details:
//In Javascript you call CefSharp.PostMessage or cefSharp.PostMessage
//Either case is supported
//You can post a primitive type like int, string or a complex type like below
CefSharp.PostMessage({ "Type": "Update", Data: { "Property": 123 }, "Callback": responseFunc }); browser.JavascriptMessageReceived += OnBrowserJavascriptMessageReceived;
private void OnBrowserJavascriptMessageReceived(object sender, JavascriptMessageReceivedEventArgs e)
{
//Complext objects are initially expresses as IDicionary
//You can use dynamic to access properties (the IDicionary is an ExpandoObject)
//dynamic msg = e.Message;
//Alternatively you can use the built in Model Binder to convert to a custom model
var msg = e.ConvertMessageTo<PostMessageExample>();
var callback = (IJavascriptCallback)msg.Callback;
var type = msg.Type;
var property = msg.Data.Property;
//Call a javascript function with your response data
callback.ExecuteAsync(type);
} |
The How do you handle a Javascript event in C#? of the |
This comment was marked as off-topic.
This comment was marked as off-topic.
@woth2k3 Please no images of code, see https://github.com/cefsharp/CefSharp/wiki/Questions-&-Support#no-images-of-code I'd suggest you try casting |
Sorry for the image. I've edited the message and made it as it's supposed to be. Worked like a charm with casting. Many thanks! |
This comment has been minimized.
This comment has been minimized.
@gf21T You don't appear to be using CefSharp.PostMessage, I'd suggest you ask for help on stackoverflow. |
Предлагаю добавить ещё в таком стиле написания функцию "CefSharp.PostMessage" => "CefSharp.postMessage" |
There are lots of cases when you don't need to explicitly bind an object, you just wish to pass some message data back to the browser. This will be added to every
V8Context
, so will be immediately available for javascript execution..Net
eventCefSharp.PostMessage
javascript method.I'm thinking we won't impose a strict message structure, will use the current conversion from
Javascript->C#
so whatever data types you can transfer now will be supported.The text was updated successfully, but these errors were encountered: