[Lazarus] Let's make a web browser

Anthony Walter sysrpl at gmail.com
Fri May 18 14:36:56 CEST 2018


My plan is to finish the JavaScript Core package first, test on Windows,
Mac, and Linux, create some compelling demos, record a few videos, and
publish it on Github.

Then integrate the final published API of the JSC into the Webkit browser
package, and again test on Windows, Mac, and Linux, create some compelling
demos, record a few videos, and publish it on Github.

*In JSC what's currently working*

JSC ability to work on all platforms. Run any JavaScript plus latest ES6
support. Create Pascal callbacks for JavaScript. Call JavaScript
functions/methods from Pascal. Create JavaScript objects dynamically from
Pascal. Fully documented.

*In JSC what needs work:*

JSC ability to define native JavaScript classes in Pascal. testing, demos,
and videos. Synchronize changes from the JSC package back into the Webkit
browser package.

*In Webkit browser package what's currently working:*

Gtk2 and Gtk3 bindings. Custom controls working independently of bindings.
Some designers and component editors. A lot of functionality has been
included beyond what was shown in the demo, including browser element hit
testing, intercepting resources before they load, custom
alert/confirm/prompt handling. Mostly documented.

*In Webkit browser what needs work:*

Needs download manager code for handling what to do when links that want to
download files. Cocoa/Carbon and Qt4/5 all have a paths forward and I have
the sources ready. They use the same basic API so changes should be minimal
and mostly related to WSClass details. Windows has not been researched yet,
but should be possible. I need to implement a few more helper
controls. Testing,
demos, and videos. Synchronize changes from the JSC package into the Webkit
browser package.

*So in summary:*

I will finish the JSC package first, publish it, then do more work on the
Webkit browser. The JSC package code is close to done, but demos will needs
some time. Everything should work on all major platforms when complete and
offer similar experiences.

*Notes about Gtk2:*

Continued Gtk2 support for Webkit was stopped a few years ago. It works,
but there have been no updates by the Webkit team for a few years and there
are some security holes that won't be patched. Also it does not have the
same performance enhancements or improvements as the Gtk3/Mac/Qt versions.
I have made some improvements tot the LCL Gtk3 units which I will publish
to Mantis as a patch when the Webkit web browser package is published.

*Contributions:*

I am going to be looking for ideas and testing with the JSC package
relatively soon. The system I've come up with is very easy to use, and also
quite powerful. Before publishing I want to create some demos, record a few
videos, and of course test all platforms. The basic getting starting with
JSC is this easy:

uses
  JavaScript.Core;

var
   Context: JSContext;
begin
  Context := JSContext.Create;
  Context.ScriptRun(SomeJavaScriptString);
end;

Note, JSContext and all related JS types (JSValue, JSObject, JSString) are
all managed for you, meaning you do not need to free them. To create a
JevaScript object in Pascal you can use code like:

O := Context.CreateObject('RegExp');

To define a callback for JavaScript to invoke your Pascal code you would
write:

function PascalHello(Context: JSContext; Args: JSValueArray; var Error:
JSValue): JSValue;
begin
  if Length(Args) > 0 then
    Result := Context.CreateString('Hi there ' + Args[0].AsString)
  else
    Result := Context.CreateString('Pascal says hello');
end;

...

Context.GlobalObject.CreateFunction('hello', PascalHello);

And in JavaScript you might write:

console.log(hello("i am javascript"));

I also provide a way to define and load entire Pascal modules in
JavaScript. A Pascal module is a set of objects/functions that add
functionality to JavaScript through native Pascal code. To use a Pascal
module you write:

JSEnabledModuleSystem(Context);

And in JavaScript you might write:

system.modules.load('file', 'process');
file.writeText('hello.txt', 'hello world');
let s = process.execute('ls', '-al');
console.log(s);

Note, the module system provides a default console object even if you are
operating outside a web browser. Also, the module system is available even
if you are executing the JavaScript inside a web page. I will provide a
reference on how to write your own modules.

Finally, I have included with JSC a demo application named jsc. The jsc
application is a scripting program that allows you to run scripts on
Mac/Linux via shebangs:

#!/home/user/bin/jsc
console.log("Hello World");

You can load modules in jsc scripts as well. To run your script, assuming
it is called hello.js, from a terminal:

chmod +x hello.js
./hello.js
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20180518/9f784839/attachment-0001.html>


More information about the Lazarus mailing list