CEFSharp bound object lost when new website is loaded
I am using CEFSharp in one of my projects and all works perfectly fine so far.
I am still on V63 of CEFSharp (never touch a running system :-) )
I am using it in VB.NET
The bound object is created after CEFSharp initialisation within Public Sub New() as follows:
CefSharpSettings.LegacyJavascriptBindingEnabled = True
Dim obj As New BoundObject()
obj.browser = browser
browser.RegisterJsObject("bound", obj)
AddHandler browser.LoadingStateChanged, AddressOf obj.Browser_LoadingStateChanged
I am then after each "LoadingStateChanged" event of the browser execute a JS script with browser.ExecuteScriptAsync.....its basically an event listner that will fire the bound object when the event occurs (e.g. a mousclick).
This also so far works 100% OK....the event fires and calls the bound object and passes a variable to my VB.NET code via the bound object.
Now my problem is that after I load a new page the bound object is lost.
The event listner will try to call the bound object but I just get an error like "Uncaught ReferenceError: bound is not defined"
Looks like be loading a new page inside CEFSharp the bound object is lost.
I triead the above initialisation code also with FrameLoadEnd event instead, but it behaves exactly the same as LoadingStateChanged event.
Any clue anyone how I can handle (or renew) the bound object whenever I load a new website?
Thanks
Update:
In the meantime I tried the binding method V2 as recommended.
Using the following code for testing purpose:
'########### TEST CODE TEST CODE TEST CODE ##################
'try to use new binding V2 method by calling CefSharp.BindObjectAsync:
browser.ExecuteScriptAsync("CefSharp.BindObjectAsync(""myObject"");")
'now register object:
browser.JavascriptObjectRepository.Register("myObject", New BoundObject(), True)
'now do test execution of myObject:
browser.ExecuteScriptAsync("myObject(""test"");")
But still struggeling to get it working :-(
cefsharp
|
show 5 more comments
I am using CEFSharp in one of my projects and all works perfectly fine so far.
I am still on V63 of CEFSharp (never touch a running system :-) )
I am using it in VB.NET
The bound object is created after CEFSharp initialisation within Public Sub New() as follows:
CefSharpSettings.LegacyJavascriptBindingEnabled = True
Dim obj As New BoundObject()
obj.browser = browser
browser.RegisterJsObject("bound", obj)
AddHandler browser.LoadingStateChanged, AddressOf obj.Browser_LoadingStateChanged
I am then after each "LoadingStateChanged" event of the browser execute a JS script with browser.ExecuteScriptAsync.....its basically an event listner that will fire the bound object when the event occurs (e.g. a mousclick).
This also so far works 100% OK....the event fires and calls the bound object and passes a variable to my VB.NET code via the bound object.
Now my problem is that after I load a new page the bound object is lost.
The event listner will try to call the bound object but I just get an error like "Uncaught ReferenceError: bound is not defined"
Looks like be loading a new page inside CEFSharp the bound object is lost.
I triead the above initialisation code also with FrameLoadEnd event instead, but it behaves exactly the same as LoadingStateChanged event.
Any clue anyone how I can handle (or renew) the bound object whenever I load a new website?
Thanks
Update:
In the meantime I tried the binding method V2 as recommended.
Using the following code for testing purpose:
'########### TEST CODE TEST CODE TEST CODE ##################
'try to use new binding V2 method by calling CefSharp.BindObjectAsync:
browser.ExecuteScriptAsync("CefSharp.BindObjectAsync(""myObject"");")
'now register object:
browser.JavascriptObjectRepository.Register("myObject", New BoundObject(), True)
'now do test execution of myObject:
browser.ExecuteScriptAsync("myObject(""test"");")
But still struggeling to get it working :-(
cefsharp
cefsharp.github.io/api/67.0.0/html/…
– amaitland
Sep 30 '18 at 21:10
github.com/cefsharp/CefSharp/wiki/…
– amaitland
Sep 30 '18 at 21:10
Thanks @amaitland - the first link makes it very clear that its a feature not a bug :-) However I am struggeling to implement this in VB.NET and convert my current legacy method code into a working new method code. Is there a possibility to provide some of those basic examples in VB.NET? I am struggeling to convert it from C# to VB.NET.
– Oscar Diez
Oct 1 '18 at 17:10
Sorry, I don't have anyVB.Net
examples. I avoid the language where possible.
– amaitland
Oct 1 '18 at 21:57
@amaitland - after reading the documentation at least three times it seems that I was trying the wrong thing. If I understand correctly, now in the new way the binding needs to be initiated in JavaScript on the target website? In case I have no control over that website can I then just inject the Async Function using 'browser.ExecuteScriptAsync' to inject it, as I just do with any other JS?
– Oscar Diez
Oct 3 '18 at 11:23
|
show 5 more comments
I am using CEFSharp in one of my projects and all works perfectly fine so far.
I am still on V63 of CEFSharp (never touch a running system :-) )
I am using it in VB.NET
The bound object is created after CEFSharp initialisation within Public Sub New() as follows:
CefSharpSettings.LegacyJavascriptBindingEnabled = True
Dim obj As New BoundObject()
obj.browser = browser
browser.RegisterJsObject("bound", obj)
AddHandler browser.LoadingStateChanged, AddressOf obj.Browser_LoadingStateChanged
I am then after each "LoadingStateChanged" event of the browser execute a JS script with browser.ExecuteScriptAsync.....its basically an event listner that will fire the bound object when the event occurs (e.g. a mousclick).
This also so far works 100% OK....the event fires and calls the bound object and passes a variable to my VB.NET code via the bound object.
Now my problem is that after I load a new page the bound object is lost.
The event listner will try to call the bound object but I just get an error like "Uncaught ReferenceError: bound is not defined"
Looks like be loading a new page inside CEFSharp the bound object is lost.
I triead the above initialisation code also with FrameLoadEnd event instead, but it behaves exactly the same as LoadingStateChanged event.
Any clue anyone how I can handle (or renew) the bound object whenever I load a new website?
Thanks
Update:
In the meantime I tried the binding method V2 as recommended.
Using the following code for testing purpose:
'########### TEST CODE TEST CODE TEST CODE ##################
'try to use new binding V2 method by calling CefSharp.BindObjectAsync:
browser.ExecuteScriptAsync("CefSharp.BindObjectAsync(""myObject"");")
'now register object:
browser.JavascriptObjectRepository.Register("myObject", New BoundObject(), True)
'now do test execution of myObject:
browser.ExecuteScriptAsync("myObject(""test"");")
But still struggeling to get it working :-(
cefsharp
I am using CEFSharp in one of my projects and all works perfectly fine so far.
I am still on V63 of CEFSharp (never touch a running system :-) )
I am using it in VB.NET
The bound object is created after CEFSharp initialisation within Public Sub New() as follows:
CefSharpSettings.LegacyJavascriptBindingEnabled = True
Dim obj As New BoundObject()
obj.browser = browser
browser.RegisterJsObject("bound", obj)
AddHandler browser.LoadingStateChanged, AddressOf obj.Browser_LoadingStateChanged
I am then after each "LoadingStateChanged" event of the browser execute a JS script with browser.ExecuteScriptAsync.....its basically an event listner that will fire the bound object when the event occurs (e.g. a mousclick).
This also so far works 100% OK....the event fires and calls the bound object and passes a variable to my VB.NET code via the bound object.
Now my problem is that after I load a new page the bound object is lost.
The event listner will try to call the bound object but I just get an error like "Uncaught ReferenceError: bound is not defined"
Looks like be loading a new page inside CEFSharp the bound object is lost.
I triead the above initialisation code also with FrameLoadEnd event instead, but it behaves exactly the same as LoadingStateChanged event.
Any clue anyone how I can handle (or renew) the bound object whenever I load a new website?
Thanks
Update:
In the meantime I tried the binding method V2 as recommended.
Using the following code for testing purpose:
'########### TEST CODE TEST CODE TEST CODE ##################
'try to use new binding V2 method by calling CefSharp.BindObjectAsync:
browser.ExecuteScriptAsync("CefSharp.BindObjectAsync(""myObject"");")
'now register object:
browser.JavascriptObjectRepository.Register("myObject", New BoundObject(), True)
'now do test execution of myObject:
browser.ExecuteScriptAsync("myObject(""test"");")
But still struggeling to get it working :-(
cefsharp
cefsharp
edited Nov 21 '18 at 23:33
Oscar Diez
asked Sep 30 '18 at 15:00
Oscar DiezOscar Diez
86
86
cefsharp.github.io/api/67.0.0/html/…
– amaitland
Sep 30 '18 at 21:10
github.com/cefsharp/CefSharp/wiki/…
– amaitland
Sep 30 '18 at 21:10
Thanks @amaitland - the first link makes it very clear that its a feature not a bug :-) However I am struggeling to implement this in VB.NET and convert my current legacy method code into a working new method code. Is there a possibility to provide some of those basic examples in VB.NET? I am struggeling to convert it from C# to VB.NET.
– Oscar Diez
Oct 1 '18 at 17:10
Sorry, I don't have anyVB.Net
examples. I avoid the language where possible.
– amaitland
Oct 1 '18 at 21:57
@amaitland - after reading the documentation at least three times it seems that I was trying the wrong thing. If I understand correctly, now in the new way the binding needs to be initiated in JavaScript on the target website? In case I have no control over that website can I then just inject the Async Function using 'browser.ExecuteScriptAsync' to inject it, as I just do with any other JS?
– Oscar Diez
Oct 3 '18 at 11:23
|
show 5 more comments
cefsharp.github.io/api/67.0.0/html/…
– amaitland
Sep 30 '18 at 21:10
github.com/cefsharp/CefSharp/wiki/…
– amaitland
Sep 30 '18 at 21:10
Thanks @amaitland - the first link makes it very clear that its a feature not a bug :-) However I am struggeling to implement this in VB.NET and convert my current legacy method code into a working new method code. Is there a possibility to provide some of those basic examples in VB.NET? I am struggeling to convert it from C# to VB.NET.
– Oscar Diez
Oct 1 '18 at 17:10
Sorry, I don't have anyVB.Net
examples. I avoid the language where possible.
– amaitland
Oct 1 '18 at 21:57
@amaitland - after reading the documentation at least three times it seems that I was trying the wrong thing. If I understand correctly, now in the new way the binding needs to be initiated in JavaScript on the target website? In case I have no control over that website can I then just inject the Async Function using 'browser.ExecuteScriptAsync' to inject it, as I just do with any other JS?
– Oscar Diez
Oct 3 '18 at 11:23
cefsharp.github.io/api/67.0.0/html/…
– amaitland
Sep 30 '18 at 21:10
cefsharp.github.io/api/67.0.0/html/…
– amaitland
Sep 30 '18 at 21:10
github.com/cefsharp/CefSharp/wiki/…
– amaitland
Sep 30 '18 at 21:10
github.com/cefsharp/CefSharp/wiki/…
– amaitland
Sep 30 '18 at 21:10
Thanks @amaitland - the first link makes it very clear that its a feature not a bug :-) However I am struggeling to implement this in VB.NET and convert my current legacy method code into a working new method code. Is there a possibility to provide some of those basic examples in VB.NET? I am struggeling to convert it from C# to VB.NET.
– Oscar Diez
Oct 1 '18 at 17:10
Thanks @amaitland - the first link makes it very clear that its a feature not a bug :-) However I am struggeling to implement this in VB.NET and convert my current legacy method code into a working new method code. Is there a possibility to provide some of those basic examples in VB.NET? I am struggeling to convert it from C# to VB.NET.
– Oscar Diez
Oct 1 '18 at 17:10
Sorry, I don't have any
VB.Net
examples. I avoid the language where possible.– amaitland
Oct 1 '18 at 21:57
Sorry, I don't have any
VB.Net
examples. I avoid the language where possible.– amaitland
Oct 1 '18 at 21:57
@amaitland - after reading the documentation at least three times it seems that I was trying the wrong thing. If I understand correctly, now in the new way the binding needs to be initiated in JavaScript on the target website? In case I have no control over that website can I then just inject the Async Function using 'browser.ExecuteScriptAsync' to inject it, as I just do with any other JS?
– Oscar Diez
Oct 3 '18 at 11:23
@amaitland - after reading the documentation at least three times it seems that I was trying the wrong thing. If I understand correctly, now in the new way the binding needs to be initiated in JavaScript on the target website? In case I have no control over that website can I then just inject the Async Function using 'browser.ExecuteScriptAsync' to inject it, as I just do with any other JS?
– Oscar Diez
Oct 3 '18 at 11:23
|
show 5 more comments
1 Answer
1
active
oldest
votes
The last sugestion of amaitland solved the problem. it works now nicely across various sites. In principle I just replaced this two lines in my original working code:
Dim obj As New BoundObject()
obj.browser = browser
'browser.RegisterJsObject("bound", obj) 'replaced by next line (JS binding V2)
browser.JavascriptObjectRepository.Register("bound", obj, True, Nothing)
AddHandler browser.LoadingStateChanged, AddressOf obj.Browser_LoadingStateChanged
And then later within the Sub that handles the browser_LoadingStateChangedAsync
event I just added this line beofre any other injected JS:
'use new binding V2 method by calling CefSharp.BindObjectAsync:
browser.ExecuteScriptAsync("CefSharp.BindObjectAsync(""bound"");")
I hope this helps others using CEFsharpin VB.NET if they come across the same problem.
The official documentation is at github.com/cefsharp/CefSharp/wiki/…
– amaitland
Nov 24 '18 at 23:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52579078%2fcefsharp-bound-object-lost-when-new-website-is-loaded%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The last sugestion of amaitland solved the problem. it works now nicely across various sites. In principle I just replaced this two lines in my original working code:
Dim obj As New BoundObject()
obj.browser = browser
'browser.RegisterJsObject("bound", obj) 'replaced by next line (JS binding V2)
browser.JavascriptObjectRepository.Register("bound", obj, True, Nothing)
AddHandler browser.LoadingStateChanged, AddressOf obj.Browser_LoadingStateChanged
And then later within the Sub that handles the browser_LoadingStateChangedAsync
event I just added this line beofre any other injected JS:
'use new binding V2 method by calling CefSharp.BindObjectAsync:
browser.ExecuteScriptAsync("CefSharp.BindObjectAsync(""bound"");")
I hope this helps others using CEFsharpin VB.NET if they come across the same problem.
The official documentation is at github.com/cefsharp/CefSharp/wiki/…
– amaitland
Nov 24 '18 at 23:10
add a comment |
The last sugestion of amaitland solved the problem. it works now nicely across various sites. In principle I just replaced this two lines in my original working code:
Dim obj As New BoundObject()
obj.browser = browser
'browser.RegisterJsObject("bound", obj) 'replaced by next line (JS binding V2)
browser.JavascriptObjectRepository.Register("bound", obj, True, Nothing)
AddHandler browser.LoadingStateChanged, AddressOf obj.Browser_LoadingStateChanged
And then later within the Sub that handles the browser_LoadingStateChangedAsync
event I just added this line beofre any other injected JS:
'use new binding V2 method by calling CefSharp.BindObjectAsync:
browser.ExecuteScriptAsync("CefSharp.BindObjectAsync(""bound"");")
I hope this helps others using CEFsharpin VB.NET if they come across the same problem.
The official documentation is at github.com/cefsharp/CefSharp/wiki/…
– amaitland
Nov 24 '18 at 23:10
add a comment |
The last sugestion of amaitland solved the problem. it works now nicely across various sites. In principle I just replaced this two lines in my original working code:
Dim obj As New BoundObject()
obj.browser = browser
'browser.RegisterJsObject("bound", obj) 'replaced by next line (JS binding V2)
browser.JavascriptObjectRepository.Register("bound", obj, True, Nothing)
AddHandler browser.LoadingStateChanged, AddressOf obj.Browser_LoadingStateChanged
And then later within the Sub that handles the browser_LoadingStateChangedAsync
event I just added this line beofre any other injected JS:
'use new binding V2 method by calling CefSharp.BindObjectAsync:
browser.ExecuteScriptAsync("CefSharp.BindObjectAsync(""bound"");")
I hope this helps others using CEFsharpin VB.NET if they come across the same problem.
The last sugestion of amaitland solved the problem. it works now nicely across various sites. In principle I just replaced this two lines in my original working code:
Dim obj As New BoundObject()
obj.browser = browser
'browser.RegisterJsObject("bound", obj) 'replaced by next line (JS binding V2)
browser.JavascriptObjectRepository.Register("bound", obj, True, Nothing)
AddHandler browser.LoadingStateChanged, AddressOf obj.Browser_LoadingStateChanged
And then later within the Sub that handles the browser_LoadingStateChangedAsync
event I just added this line beofre any other injected JS:
'use new binding V2 method by calling CefSharp.BindObjectAsync:
browser.ExecuteScriptAsync("CefSharp.BindObjectAsync(""bound"");")
I hope this helps others using CEFsharpin VB.NET if they come across the same problem.
answered Nov 24 '18 at 16:06
Oscar DiezOscar Diez
86
86
The official documentation is at github.com/cefsharp/CefSharp/wiki/…
– amaitland
Nov 24 '18 at 23:10
add a comment |
The official documentation is at github.com/cefsharp/CefSharp/wiki/…
– amaitland
Nov 24 '18 at 23:10
The official documentation is at github.com/cefsharp/CefSharp/wiki/…
– amaitland
Nov 24 '18 at 23:10
The official documentation is at github.com/cefsharp/CefSharp/wiki/…
– amaitland
Nov 24 '18 at 23:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52579078%2fcefsharp-bound-object-lost-when-new-website-is-loaded%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
cefsharp.github.io/api/67.0.0/html/…
– amaitland
Sep 30 '18 at 21:10
github.com/cefsharp/CefSharp/wiki/…
– amaitland
Sep 30 '18 at 21:10
Thanks @amaitland - the first link makes it very clear that its a feature not a bug :-) However I am struggeling to implement this in VB.NET and convert my current legacy method code into a working new method code. Is there a possibility to provide some of those basic examples in VB.NET? I am struggeling to convert it from C# to VB.NET.
– Oscar Diez
Oct 1 '18 at 17:10
Sorry, I don't have any
VB.Net
examples. I avoid the language where possible.– amaitland
Oct 1 '18 at 21:57
@amaitland - after reading the documentation at least three times it seems that I was trying the wrong thing. If I understand correctly, now in the new way the binding needs to be initiated in JavaScript on the target website? In case I have no control over that website can I then just inject the Async Function using 'browser.ExecuteScriptAsync' to inject it, as I just do with any other JS?
– Oscar Diez
Oct 3 '18 at 11:23