First call in form of WA EXECUTE JAVASCRIPT FUNCTION takes 6 seconds


Tested on Windows 10, 4D v17R6

When calling WA EXECUTE JAVASCRIPT FUNCTION the first time in a form for a web area it takes 6 seconds to complete.
However, successive calls run as expected

Does this have something to do with loading certain libraries?
Does anybody know why does this take so long?
Can I do something about this?

I have a javascript function to scroll to a certain element within my html

function scroll_to_id(my_id) {
  var elmnt = document.getElementById(my_id);

and use WA EXECUTE JAVASCRIPT FUNCTION (;$area;“scroll_to_id”;;$element) to execute it

Did you “Use embedded Web rendering engine” checked?

Hi Lutz_Veith, :grinning:

Yes, I forgot to mention this, but “Use embedded Web rendering engine” has been checked


Hi Piotr

When a form load it start new the webengine for a webArea in the form
this need time.

The webengine loads a page-url and its embedded stuffs
this need time.

Parse the sourceCodes and creating HTML-DOM needs time.

To use a jsFunction the jsFunction must declared before by parsed js-script.

To fetch with document.getElementById an element in DOM, the element must before exist in DOM.

Simple use any event when it is sure DOM is ready/loaded.

// OM: "testForm".myAreaWA
Case of 
	: (Form event=On End URL Loading)
		WA EXECUTE JAVASCRIPT FUNCTION(*;"myAreaWA";"scroll_to_id";*;"myLastEl")
End case 

Or embedd js-script with js-event direct in your page-source:

Alternative-1 in JS:
document.addEventListener( “DOMContentLoaded”, function(){ document.getElementById(‘myStartId’).scrollIntoView(); }, false);

Alternative-2 in JS:
window.addEventListener(‘load’, function(){ document.getElementById(‘myStartId’).scrollIntoView(); }, false);

I did a test with v18(and with any older v17 build), when my page is finished loading and than i do a first wa-exec
it got the scroll result in much less than 1sec (maybe 5ms).

Same with this code, i got scroll-result in less than 1sec.
with my first js call after page load:

$funcResult:=WA Evaluate JavaScript(*;$waObjName;"(function(){"+$funcCode+"})();")

Greetings Lutz

A nice new feature in new coming 4Dv18R3 is wa-offscreen (but this belongs not to your question)

Putting it in the form event seems to solve the problem, thanks for that, although I not completely understand the underlying reason