Reputation: 359
i'm using geckofx 29. how i can call c# function on javascript event ?
i search and find this solution, but its not working:
public void AddEventListener_JScriptFiresEvent_ListenerIsCalledWithMessage()
{
string payload = null;
browser.AddMessageEventListener("callMe", ((string p) => payload = p));
browser.LoadHtml(
@"<!DOCTYPE html>
<html><head>
<script type='text/javascript'>
window.onload= function() {
event = document.createEvent('MessageEvent');
var origin = window.location.protocol + '//' + window.location.host;
event.initMessageEvent ('callMe', true, true, 'some data', origin, 1234, window, null);
document.dispatchEvent (event);
}
</script>
</head><body></body></html>");
browser.NavigateFinishedNotifier.BlockUntilNavigationFinished();
Assert.AreEqual("some data", payload);
}
event.initMessageEvent can not execute ...
please help me
Upvotes: 1
Views: 2668
Reputation: 811
The message event interface has been updated. The initMessageEvent method no longer exists. Look here at bottom of the thread. According to that body of your onload function should be:
var event = new MessageEvent('callMe', { 'view': window, 'bubbles': false, 'cancelable': false, 'data': 'some data' });
document.dispatchEvent(event);
Hope this helps.
Upvotes: 1