Re: XPA 4.8 Browser Control and JSON


Keith Canniff
 

https://jsonlint.com/ is also a great validator and formatter. 


From: main@magicu-l.groups.io <main@magicu-l.groups.io> on behalf of Todd Baremore <tbaremor@...>
Sent: Sunday, May 22, 2022 10:26:39 PM
To: main@magicu-l.groups.io <main@magicu-l.groups.io>
Subject: Re: [magicu-l] XPA 4.8 Browser Control and JSON
 
Craig Et al,

Switching from using the .NET browser control to the XPA 4.8 CefSharp browser control using JScript and JSON has been a learning experience.  Here is what I have learned so far in the hope that it will save you some time and pain.

1.  Do not attempt to include html links in your JSON, instead include the relevant info and build the link in JScript.  The double quotes in the html link are problematic in JSON.

2.  The JSON data must not contain line feeds and carriage returns.
      Virtual   A   JSONString    Alpha     10000
      Remove line feeds and carriage returns using:
      RepStr(A,ASCIIChr(10),'')
      RepStr(A,ASCIIChr(13),'')

3.  JSON must be passed to BrowserScriptExecute() function enclosed in single quotes.    '[{"id":"456","lat":44.397990,"lon":-75.868030,"icon":"nIcon"},{"id":"788","lat":44.367890,"lon":-78.16930,"icon":"sIcon"}]'
       Assuming you have valid* JSON in JSONString, add single quotes using  Update A = ''''&Trim(A)&''''
       *You can check your JSON here:  https://jsononline.net/json-validator

4.  Combine the JScript function you are calling and the JSON text in to an ANSI BLOB
      Virtual  B   FunctionAndJSON     BLOB
      Assuming  the script function I want to call  is:    function updatecustomer(jsontext)
      Update B = 'updatecustomer('&A&')'

5.  Assuming the browser control name is MyBrowser
     Evaluate the expression BrowserScriptExecute('MyBrowser',B,'FALSE'LOG)

The steps above work for me in XPA4.8.1.   No idea if this works in 4.7, 4.6, 4.5.........

Always interested in other developers' experiences.
Todd
On 1/18/2022 8:52 AM, Todd Baremore wrote:
Removing the outer double quotes has rid me of the outer parenthesis error. Thank you!
Now getting a JSON parsing error which I can deal with. I like the idea of using an alert to see what is being received.  

I'll keep the Zoom offer in my back pocket.
Todd
On 1/18/2022 12:45 AM, Craig Martin wrote:
It's difficult to debug from only that fragment but are you sure you need the array in quotes?
Should the second parameter be 'vehicleupdate([{"id":"456","lat":42.397990,"lon":-74.868030,"icon":"nIcon"}])'

I would create a dummy page you can interact with the same function name and signature - vehicleupdate() I mean - and then just use alerts to see what gets to the page and what works, step by step. I don't have your version of Magic or any way to recreate your setup.
Happy to Z-z-z-oom sometime to help you resolve it.



From: main@magicu-l.groups.io <main@magicu-l.groups.io> on behalf of Todd Baremore <tbaremor@...>
Sent: Monday, January 17, 2022 9:17 PM
To: main@magicu-l.groups.io <main@magicu-l.groups.io>
Subject: Re: [magicu-l] XPA 4.7.2 crashing
 
Thanks for your example.  It is using the .NET browser, which I have working.   The problem I have is with the XPA Browser Control and using BrowserScriptExecute() to call a javascript function that accepts a JSON array argument. 
I keep getting  "Error:  Expected ')' "
If I pass "Testing"  I don't get the error above, but it fails later on when trying to parse the JSON which is what should happen.
As soon as I try to pass a json object or array I get the error above.  

Here is a simplified version of the json I'm sending that gives me  "Error:  Expected ')' "
BrowserScriptExecute('Browser','vehicleupdate("[{"id":"456","lat":42.397990,"lon":-74.868030,"icon":"nIcon"}]")','TRUE'LOG)
I'm either missing something glaringly obvious or XPA is modifying the argument.

Microsoft.mshtml is my Composite Resource Repository

Any ideas Master Luke?
Todd
On 1/17/2022 7:13 PM, Craig Martin wrote:
Nah, it's appendix 1 of Craig's Playbook. It says: see Kobayashi Maru.

Your thing with injecting json or data generally into an old IE embedded browser I did cover in an archived blog:


More up to date, both webView2 and CEFSharp have webView2.CoreWebView2.ExecuteScriptAsync() and cef.EvaluateScriptAsync() methods.
However to use those async calls you'll have to play around a bit in c# snippets.



From: main@magicu-l.groups.io <main@magicu-l.groups.io> on behalf of Todd Baremore <tbaremor@...>
Sent: Monday, January 17, 2022 4:02 PM
To: main@magicu-l.groups.io <main@magicu-l.groups.io>
Subject: Re: [magicu-l] XPA 4.7.2 crashing
 
Sounds like a government solution.  I try to avoid those.
Todd
On 1/17/2022 3:43 PM, Craig Martin wrote:
Todd, one more idea, if it happens every 15 minutes, can you force a swing task exit/reentry every 10 minutes 😀


On Jan 17, 2022, at 12:19 PM, Steven Blank <sgblank@...> wrote:

 Todd,

I suggest you enable logging in the broker's MGRB.INI file.

A while back, Hilco was having problems with their network security scanner hitting on the broker and causing it to crash. I tried to find the logs and Windows Event viewer files to see if they cited the same exception code, but couldn't – I deleted a lot of old stuff when I retired.

But I did find the following excerpt from an email message at the time:
— — — — — — — — — — — — — —
John,

I note the following entries from the broker log file on H17V, aps_mrb.log:

...
2460   23:43:48,82587  04/12/2020   Error: "TCP/IP: Connection reset" (-144)  (/0)
2460           ,82587  04/12/2020   Request 0 wasn't found in the history log
3648   23:44:52,45986  04/12/2020   Error: "Invalid server accessed or mismatched EncryptedCommunication setting" (-211)  (/0)
3648           ,45986  04/12/2020   Error: "Invalid server accessed or mismatched EncryptedCommunication setting" (-211)  (/0)
720            ,45986  04/12/2020   Error: "Invalid server accessed or mismatched EncryptedCommunication setting" (-211)  (/0)
3648           ,46735  04/12/2020   Error: "TCP/IP: Connection reset" (-144)  (/0)
3648           ,46735  04/12/2020   Request 0 wasn't found in the history log
720    23:44:54,47999  04/12/2020   Request 0 wasn't found in the history log
1188   23:45:29,83504  04/12/2020   Error: "Invalid server accessed or mismatched EncryptedCommunication setting" (-211)  (/0)
1188           ,83504  04/12/2020   Error: "Invalid server accessed or mismatched EncryptedCommunication setting" (-211)  (/0)
4640   12:34:53,42343  06/12/2020 Startup  (Version uniPaaS 1.9p, build Oct  7 2014)
...

The above are all of the entries from Friday, 04-Dec; the last entry is the beginning of the restart on Sunday.

The (-144) errors happen a lot and present an ongoing problem of their own, but the (-211) errors provide the smoking gun in this case. From the uniPaaS help:

-211 RQMRILOW ERR NOT MRI

An internal error was caught while receiving a message from a peer.

Scenario #1:  The peer was not a uniPaaS module; a message was sent by another TCP/IP module, such as Internet Explorer.

Scenario #2:  The peer did not set the EncryptedCommunication keyword in the Mgreq.ini file or set a mismatched value in the keyword.


Notice scenario #1: the broker is complaining that something foreign was attempting to connect.
— — — — — — — — — — — — — —

Steven G. Blank
SGBlank Consulting

BTW, if you're a member of Facebook, please consider joining the Magic Development Community group:

https://www.facebook.com/groups/magic/

Many wonderful and interesting things are in the works there ...


On 1/17/2022 11:49 AM, Todd Baremore wrote:
Actian Zen 15.01
MySQL 8.0.27

A program using a top and bottom frame that has the following:
Top Frame:  Using  System.Windows.Forms.WebBrowser  to display a map of vehicles using Lealetjs.  
Bottom Frame:  A list of vehicles with the last time their position was received.
Both frames are updated when new position data is received.  Data is written to and read from MySQL each time a new position is received.

On Windows 10 and 2016  the program is bullet proof.  On Windows 2019 it crashes after 15-20 minutes.

These are the entries in the Windows 2019 Application Event Log




I found the following description for "Exception code: 0xc0000005":   The exception code 0xc0000005 indicates a memory access violation.       I'm an administrator on the server.
The registries keys for the browser to run JavaScript are set.
The odd thing is the program will run for 15-20 minutes before crashing.   Has anyone else come across "Exception code: 0xc0000005"?  

Todd







Join main@magicu-l.groups.io to automatically receive all group messages.