Discussion:
[Lazarus] Let's make a web browser
Michael Van Canneyt via Lazarus
2018-05-18 08:46:36 UTC
Permalink
how-to instructions
<https://www.getlazarus.org/learn/tutorials/examples/webbrowser/>
Pretty neat ! Deceptively easy to do :)
Question: Where are the components you used, and where can I find the demo
source code ?
Is this embedded Gecko engine ?
I thought it was perhaps chrome embedded ?

Michael.
--
Anthony Walter via Lazarus
2018-05-18 12:36:56 UTC
Permalink
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
Torsten Bonde Christiansen via Lazarus
2018-05-18 07:56:04 UTC
Permalink
Question: Where are the components you used, and where can I find the
demo source code ?
+1

-Torsten.
--
Torsten Bonde Christiansen via Lazarus
2018-05-18 12:25:16 UTC
Permalink
As for chrome embedding;
https://github.com/dliw/fpCEF3
I used it couple years ago and it worked very
well.https://github.com/zbyna/vcfToGigaset
FpCEF3 is maintained so far.
Even fpCEF3 has problems running well under linux - so I would love to
see (and help) with an approach like this :)

Best regards,
Torsten.
--
Michael Van Canneyt via Lazarus
2018-05-18 10:09:08 UTC
Permalink
This is an open source set of controls I am working on which will be
released soon on gtihub. The browser is based on the wekbit engine, and
it's accompanied by a collection of native controls and other code to make
working with related materials easy/easier.
A related portion I am working on in parallel is an interface to the webkit
javascript core engine. Although it is in a separate package, the jsc tools
I am working on provide the ability to intermix pascal code and javascript
in your applications. But also, you can use the jsc tools to take to talk
your application from inside a webpage, and your application can call
javascript to interact with a webpage.
Or, you can not use a web browser at all, and just work with javascript
inside your pascal apps.
Stay tuned. If you want to help me test or give me feedback (forum linked
below) on some demo ideas or the programming interface (code design) before
I publish, let me know.
Great news !

It means we can create native embedded pas2js applications:
a "Phonegap" (think cordova, native react etc.) like approach for lazarus !
This is going to be heaps of fun... :)

Keep up the good work, I look forward to seeing the final product :)

Michael.
--

Continue reading on narkive:
Loading...