« Xojo Tips | Home | WebView2 and Cookies … »

Using JavaScript with WebKit on FileMaker Server on Linux

You may know our JavaScriptWebKit functions for macOS and iOS. But with the upcoming 13.1 release, you can use those functions on Windows and Linux, too. It's up to you to provide the library, so we go through this step by step for Linux. Here is the screenshot with the trace output on Linux:

You should have a recent FileMaker Server installed on Linux with Ubuntu in a recent version. Please open a terminal connection either by doing so on the server directly or via ssh connection.

First we go to refresh the package directory on Linux by running the following command:

sudo apt-get update

Next we can search JavaScript Core library:

apt-cache search javascriptcore

Which may find packages like "libjavascriptcoregtk-4.0-bin". The exact version doesn't matter and you may find 4.0 or 4.1 here. Next we install the package we found:

sudo apt-get install libjavascriptcoregtk-4.0-bin

Now you should find a libjavascriptcoregtk-4.0.so.18 file in /usr/lib/x86_64-linux-gnu (or /usr/lib/aarch64-linux-gnu) and you construct the path for later:

/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.0.so.18

Since we don't want to run blind, we call MBS("Trace") in the script on the top. And then we run tail command in a Terminal window connected to our linux server to see live logs:

tail -f /opt/FileMaker/FileMaker\ Server/Logs/StdErrServerScripting.log

We build a test script like the one here:

 

Set Variable [ $r ; Value: MBS("Trace") & MBS("Version") ] 

# load library if needed

If [ MBS( "JavaScript.Available" ) = 0 and MBS("IsLinux") ] 

Set Variable [ $r ; Value: MBS("JavaScript.LoadLibrary"; "/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.0.so.18") ] 

If [ MBS("IsError") ] 

Exit Script [ Text Result: $r ] 

End If

End If

# Start a new JavaScript session

Set Variable [ $js ; Value: MBS("JavaScript.New") ] 

If [ MBS("IsError") ] 

Exit Script [ Text Result: $js ] 

End If

# use JavaScript

Set Variable [ $result ; Value: MBS("JavaScript.EvaluateScript"; $js; "const greeting = ' Hello world! '; greeting.trimStart();") ] 

# cleanup

Set Variable [ $r ; Value: MBS("JavaScript.Release"; $js) ] 

Exit Script [ Text Result: $result ] 

 

Now we can run this via Perform Script on Server. The JavaScript.LoadLibrary function loads the library the first time you use the function. If that doesn't produce an error like an invalid path, we can continue. We start a new JavaScript session and then do various things on it like running scripts, get and set global properties or call a function. 

 

The initialization needs only to run first time you use JavaScript, so you may do that in a script triggered from your start script (on first window open). The JavaScript engine can stay alive for longer, like from user opening your solution to the user ending the solution to do various JavaScript tasks over time.

 

If you like to try to use this on Windows, you may need to find a JavaScriptCore.dll and all related DLLs it references. 

Alternatively check our JavaScript functions using Duktape as local JavaScript engine, which also runs cross platform on client and server.

 

Please try it and let us know how it works for you.

05 03 23 - 10:46