Re: WA Evaluate JavaScript in 16.4

2018-12-20 Thread Keisuke Miyako via 4D_Tech
originally designed as a "beginner language"
JS has some tolerant syntax rules,
being OK to omit the line terminator ";" is one of them.

of course, this could only work if the end-of-line can be implied without a ";" 
(for example, by \n)

I can understand the motivation to remove all \n from your script,
based on the observation that "WA Evaluate JS" can only run a single line of 
script.

a line, in this context, is not the line of code (separated by ";"), but 
rather, a line of text (separated by \n).

there was a bug (ACI0092713) in 13.5.HF1,
where the command could not execute code with multiple lines (\n).
it was fixed in  fixed in 13.6, but for WebKit back then and the system Web 
Area.

> The problem was that we assumed there would be no significant differences 
> between 16.4 and 16R6.


the embedded web area engine has changed from WebKit to CEF (Chrome Embedded 
Framework) in 16R 64-bit
http://doc.4d.com/4Dv17/4D/17/Appendix-4D-v16-Rx-Release-Notes.200-3899099.en.html

so are you saying that CEF has a similar problem with \n ?

before you remove all instances of \n (which could simply be inserted for 
legibility or even as a literal),
it would be better to make sure that the code has explicit ";" to indicate an 
end of code.

perhaps a "minification" tool would help.



**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: WA Evaluate JavaScript in 16.4

2018-12-20 Thread Tom DeMeo via 4D_Tech
Hi,


I would suggest constructing an HTML page and loading any javascript libraries 
you need into it. Then load that page into a web area on a form. That will 
allow you to use WA EXECUTE JAVASCRIPT FUNCTION instead to call the functions 
you need from your loaded page. If this has to occur on the server and you 
cannot run a utility client, the NTK plugin 
https://www.pluggers.nl/product/ntk-plugin/ has a javascript interpreter that 
may work for you.

 

Tom DeMeo

> Message: 4
> Date: Thu, 20 Dec 2018 10:21:00 -0800
> From: Noah 
> To: 4D iNug Technical <4d_tech@lists.4d.com>
> Subject: Re: WA Evaluate JavaScript in 16.4
> Message-ID:
>   
> Content-Type: text/plain; charset="UTF-8"
> 
> Thanks for the quick reply!
> 
> We had constructed a minimal test: an external js file that contains
> *alert('hello')* on a single line and nothing else.
> 
> We may have now narrowed the scope of this issue to WA Execute JavaScript's
> ability to handle the '\n' in the javascript that it reads from a file.
> 
> When the file is read into 15.4 or 16.4 the returned text is
> *alert('hello')\n*. This was not a problem in 15.4, but the \n creates a
> problem with WA Evaluate JavaScript in v16.4.
> 
> Overcoming the bug by processing the read JS (to remove the \n) does the
> trick for our very simple test case (JavaScript in external files that are
> only a single line). Web areas in v16.4 will now 'alert' as expected.
> 
>$tJS_path:=Get 4D folder(Current resources folder)+"ncs_test.js"
>DOCUMENT TO BLOB($tJS_path;$bDoc)
>$test_js:=BLOB to text($bDoc;UTF8 text without length)
>  // replace the carriage return \n with ''
>$codeBody:=Replace string($test_js;Char(10);"")
>WA Evaluate JavaScript(wa;$codeBody)
> 
> However, this is obviously not going to solve our larger problem of being
> able to load JavaScript libraries to scrape a web page.
> 
> The JavaScript code in the external files contains comments... and perhaps
> other nuances that would render the above solution insufficient.
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: WA Evaluate JavaScript in 16.4

2018-12-20 Thread Noah via 4D_Tech
Thanks for the quick reply!

We had constructed a minimal test: an external js file that contains
*alert('hello')* on a single line and nothing else.

We may have now narrowed the scope of this issue to WA Execute JavaScript's
ability to handle the '\n' in the javascript that it reads from a file.

When the file is read into 15.4 or 16.4 the returned text is
*alert('hello')\n*. This was not a problem in 15.4, but the \n creates a
problem with WA Evaluate JavaScript in v16.4.

Overcoming the bug by processing the read JS (to remove the \n) does the
trick for our very simple test case (JavaScript in external files that are
only a single line). Web areas in v16.4 will now 'alert' as expected.

$tJS_path:=Get 4D folder(Current resources folder)+"ncs_test.js"
DOCUMENT TO BLOB($tJS_path;$bDoc)
$test_js:=BLOB to text($bDoc;UTF8 text without length)
  // replace the carriage return \n with ''
$codeBody:=Replace string($test_js;Char(10);"")
WA Evaluate JavaScript(wa;$codeBody)

However, this is obviously not going to solve our larger problem of being
able to load JavaScript libraries to scrape a web page.

The JavaScript code in the external files contains comments... and perhaps
other nuances that would render the above solution insufficient.




On Thu, Dec 20, 2018 at 9:58 AM John DeSoi via 4D_Tech <4d_tech@lists.4d.com>
wrote:

> Try turning 'Use embedded rendering engine' off for the web area. And
> verify your JavaScript code works outside of 4D in Safari when using Mojave.
>
> John DeSoi, Ph.D.
>
>
> > On Dec 20, 2018, at 11:10 AM, Noah via 4D_Tech <4d_tech@lists.4d.com>
> wrote:
> >
> > The parent form:
> > Case of
> >: (Form event=On Load)
> >WA OPEN URL(wa;"https://google.com/;)
> >WA SET PREFERENCE(wa;WA enable JavaScript;True)
> >WA SET PREFERENCE(wa;WA enable Web inspector;True)
> > End case
> >
> > 'Use embedded rendering engine' is checked.
> >
> > Has anyone else experienced this? Any suggestions?
>
> **
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: WA Evaluate JavaScript in 16.4

2018-12-20 Thread John DeSoi via 4D_Tech
Try turning 'Use embedded rendering engine' off for the web area. And verify 
your JavaScript code works outside of 4D in Safari when using Mojave.

John DeSoi, Ph.D.


> On Dec 20, 2018, at 11:10 AM, Noah via 4D_Tech <4d_tech@lists.4d.com> wrote:
> 
> The parent form:
> Case of
>: (Form event=On Load)
>WA OPEN URL(wa;"https://google.com/;)
>WA SET PREFERENCE(wa;WA enable JavaScript;True)
>WA SET PREFERENCE(wa;WA enable Web inspector;True)
> End case
> 
> 'Use embedded rendering engine' is checked.
> 
> Has anyone else experienced this? Any suggestions?

**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

WA Evaluate JavaScript in 16.4

2018-12-20 Thread Noah via 4D_Tech
Good morning!

SUMMARY:
In 16.4 (interpreted mode) we have a web area which displays a web page
that is not under our control. We had devised a way to scrape the webpage
with a custom library of JavaScript files that we kept in the resources
folder. We find that in 16.4 the WA Evaluate JavaScript does not evaluate
the JavaScript from external files.

HISTORY:
We recently moved from 15.4 to 16R6 (which was a mistake, since it is not
Mojave compatible). When we did, we had to update various aspects of our
app to work with the new version. The web area was one area that required
our attention. In the end, it appeared that we just needed to check the
'use embedded webkit'. When a development machine was upgraded to Mojave we
were locked out of developing in 16R6, so (at the advice of 4D support) we
quickly changed to 16.4 (which is actively supported).
The problem was that we assumed there would be no significant differences
between 16.4 and 16R6. There were several changes (method name conversions)
that happened automatically, but (more importantly) the WA Evaluate
JavaScript stopped working with our JS code loaded from external files.

Here is the relevant testing code from the web area:
Case of
: (Form event=On End URL Loading)

  // test the 'fetching' of javascript
$tJS_path:=Get 4D folder(Current resources
folder)+"SciQuest"+<>ktDir_Separator+"ncs_test.js"
DOCUMENT TO BLOB($tJS_path;$bDoc)
$test_js:=BLOB to text($bDoc;UTF8 text without length)
WA Evaluate JavaScript(wa;$test_js)
  // end test
End case

The parent form:
Case of
: (Form event=On Load)
WA OPEN URL(wa;"https://google.com/;)
WA SET PREFERENCE(wa;WA enable JavaScript;True)
WA SET PREFERENCE(wa;WA enable Web inspector;True)
End case

'Use embedded rendering engine' is checked.

Has anyone else experienced this? Any suggestions?
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**