ExecuteJavaScript Timing with onload

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

ExecuteJavaScript Timing with onload

Postby sirheroics » Wed Nov 15, 2023 12:05 pm

This should be a simple one...My pages run javascript in "<body onload=test()>". My CEF implementation is calling ExecuteJavaScript in OnLoadEnd in order to inject functions into the DOM that the code running in 'onload' (test()) will need.

I was hoping this timing wouldn't be a problem but it is. Is there an earlier point in the load cycle for me to call ExecuteJavaScript so that the DOM is ready in time for scripts running in onload or do I need to delay them?

Thanks!
sirheroics
Techie
 
Posts: 33
Joined: Mon Mar 22, 2021 6:32 am

Re: ExecuteJavaScript Timing with onload

Postby magreenblatt » Wed Nov 15, 2023 12:11 pm

Is there an earlier point in the load cycle for me to call ExecuteJavaScript so that the DOM is ready in time for scripts running in onload or do I need to delay them?

Why not use your ExecuteJavaScript to trigger the logic, instead of onload handler?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: ExecuteJavaScript Timing with onload

Postby sirheroics » Wed Nov 15, 2023 12:15 pm

That's too page-specific. The stuff ExecuteJavaScript is putting in the DOM are generic utilities that all our pages will need however each page will have different logic in how/when they use them.
sirheroics
Techie
 
Posts: 33
Joined: Mon Mar 22, 2021 6:32 am

Re: ExecuteJavaScript Timing with onload

Postby magreenblatt » Wed Nov 15, 2023 12:42 pm

Does the "ExecuteJavaScript stuff" change between page loads, or is it common to all pages loaded in the same browser?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: ExecuteJavaScript Timing with onload

Postby magreenblatt » Wed Nov 15, 2023 12:43 pm

generic utilities that all our pages will need

If all of your pages need it, then just have ExecuteJavaScript call some function that is implemented in the page after adding your "stuff".
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: ExecuteJavaScript Timing with onload

Postby KatrinaS » Wed Nov 15, 2023 2:40 pm

I personally throw some 'buffering time' in (as, as you know the page isn't actually complete OnLoadEnd), like with a 'setTimeout(the_stuff(), 5000)' to (help) make sure the page is completely complete. But yeah, throw what's generic of 'the stuff' in an external file and call it later, and with an external file it means you can edit it on the fly too outside of hard coded, even automatically generate and save it before the 'client' page loads it :)
KatrinaS
Mentor
 
Posts: 83
Joined: Tue Jul 04, 2023 6:30 pm

Re: ExecuteJavaScript Timing with onload

Postby sirheroics » Wed Nov 15, 2023 3:39 pm

magreenblatt wrote:Does the "ExecuteJavaScript stuff" change between page loads, or is it common to all pages loaded in the same browser?


There are some utilities that are common for all and some that are specific.

magreenblatt wrote:
generic utilities that all our pages will need

If all of your pages need it, then just have ExecuteJavaScript call some function that is implemented in the page after adding your "stuff".


I guess I can but I'm trying to limit the amount of custom "process" that the HTML guys need to know.

Am I correct in assuming that OnLoadEnd is the "right" place to be calling ExecuteJavaScript and that everyone's offering workarounds because there's no better place earlier in the load cycle to do it?
sirheroics
Techie
 
Posts: 33
Joined: Mon Mar 22, 2021 6:32 am

Re: ExecuteJavaScript Timing with onload

Postby magreenblatt » Wed Nov 15, 2023 4:30 pm

Am I correct in assuming that OnLoadEnd is the "right" place to be calling ExecuteJavaScript and that everyone's offering workarounds because there's no better place earlier in the load cycle to do it?

Yes, unless you can refactor your app logic to use OnContextCreated (in the renderer process) instead.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: ExecuteJavaScript Timing with onload

Postby KatrinaS » Wed Nov 15, 2023 4:41 pm

Don't forget that you can throw 'eval' at the page / document too and that can contain all kinds of stuff :)
KatrinaS
Mentor
 
Posts: 83
Joined: Tue Jul 04, 2023 6:30 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 164 guests