Recent

Author Topic: fpwebview - Free Pascal binding for webview  (Read 9021 times)

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
fpwebview - Free Pascal binding for webview
« on: February 14, 2022, 12:52:14 pm »
Hi all,

I'm pleased to announce fpwebview, the Free Pascal binding for webview, the cross-platform library that links with gtk-webkit2 on Linux, Cocoa/WebKit on macOS and Edge on Windows 10 for building desktop web applications.

Supporting shared library, dylib, DLL and import library files for Linux, macOS and Windows for x86_64 are bundled.

Here's a simple Pascal program that uses fpwebview to implement a web browser.

Code: Pascal  [Select][+][-]
  1. program browser_cli;
  2.  
  3. {$linklib libwebview}
  4.  
  5. uses
  6.   {$ifdef unix}cthreads,{$endif}
  7.   math,
  8.   webview;
  9.  
  10. var
  11.   w: PWebView;
  12.  
  13. begin
  14.   { Set math masks. libwebview throws at least one of these from somewhere deep inside. }
  15.   SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]);
  16.  
  17.   writeln('Hello, webview, from Pascal!');
  18.   w := webview_create(WebView_DevTools, nil);
  19.   webview_set_size(w, 1024, 768, WebView_Hint_None);
  20.   webview_set_title(w, PAnsiChar('WebView Free Pascal'));
  21.   webview_navigate(w, PAnsiChar('https://www.freepascal.org/'));
  22.   webview_run(w);
  23.   webview_destroy(w);
  24.   writeln('Goodbye, webview.');
  25. end.
  26.  

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: fpwebview - Free Pascal binding for webview
« Reply #1 on: February 14, 2022, 06:45:22 pm »
hi , it is nice to see this big development for lazarus as it was lacking this power , but we try it didnt work could you please see why, or use in windows application

thanks for your efforts

Thaddy

  • Hero Member
  • *****
  • Posts: 14213
  • Probably until I exterminate Putin.
Re: fpwebview - Free Pascal binding for webview
« Reply #2 on: February 14, 2022, 06:52:04 pm »
This definitely needs some work: C style pointers? PWebView? Certainly that can be done better.
But it is great effort.
Specialize a type, not a var.

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: fpwebview - Free Pascal binding for webview
« Reply #3 on: February 15, 2022, 02:09:11 am »
hi , it is nice to see this big development for lazarus as it was lacking this power , but we try it didnt work could you please see why, or use in windows application

thanks for your efforts

Hi. Assuming you are on Windows, did 'winbuild.bat' fail? That batch file will fail if it cannot invoke fpc.exe to build the program. The location of fpc.exe is set in the %fpcexe% variable in the batch file.

If the failure is something else, please provide more details.

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: fpwebview - Free Pascal binding for webview
« Reply #4 on: February 15, 2022, 02:21:11 am »
This definitely needs some work: C style pointers? PWebView? Certainly that can be done better.
But it is great effort.

Thanks. For now I am focused on working out bidirectional Pascal-Javascript calls for serverless web app using webview's API or websockets. With more experience using the APIs, a TWebView class wrapping those C-style functions and pointers will come.

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: fpwebview - Free Pascal binding for webview
« Reply #5 on: February 15, 2022, 06:04:03 pm »
hi , it is nice to see this big development for lazarus as it was lacking this power , but we try it didnt work could you please see why, or use in windows application

thanks for your efforts

Hi. Assuming you are on Windows, did 'winbuild.bat' fail? That batch file will fail if it cannot invoke fpc.exe to build the program. The location of fpc.exe is set in the %fpcexe% variable in the batch file.

If the failure is something else, please provide more details.
yes it failed through bat file , also i tried building it through IDE also it didn't work it showed only form , and where the exe is saved i dont know
if you could do a browser Gui sample it would be great

thanks


PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: fpwebview - Free Pascal binding for webview
« Reply #6 on: February 16, 2022, 02:10:26 am »
Hi. Assuming you are on Windows, did 'winbuild.bat' fail? That batch file will fail if it cannot invoke fpc.exe to build the program. The location of fpc.exe is set in the %fpcexe% variable in the batch file.

If the failure is something else, please provide more details.
yes it failed through bat file , also i tried building it through IDE also it didn't work it showed only form , and where the exe is saved i dont know
if you could do a browser Gui sample it would be great

thanks

See the 'fpcexe' variable in winbuild.bat:

Code: Text  [Select][+][-]
  1. @echo off
  2.  
  3. echo Set up FPC executable path.
  4. set fpcexe=c:fpc.exe                       <==== Change this

Change the variable to the full path of fpc.exe on your machine. E.g. on my machine, I installed Lazarus into c:\pkg\lazarus, so the fpc.exe path is:

Code: Text  [Select][+][-]
  1. set fpcexe=c:\pkg\lazarus\fpc\3.2.2\bin\x86_64-win64\fpc.exe

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: fpwebview - Free Pascal binding for webview
« Reply #7 on: February 16, 2022, 02:48:45 am »
I've just put up two more demos:
  • js_eval.lpr - run Javascript from Pascal
  • js_bidir.lpr - bidirectional Javascript-Pascal calls
Planned:
  • i18n
  • embedded web server
Edit: Demos fully working on Linux and macOS, not fully on Windows.
« Last Edit: February 16, 2022, 03:47:13 am by PierceNg »

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: fpwebview - Free Pascal binding for webview
« Reply #8 on: February 16, 2022, 05:28:07 am »
Hi! Tested successfully the three demos on Linux. Good job!
My projects are on Gitlab and on Codeberg.

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: fpwebview - Free Pascal binding for webview
« Reply #9 on: February 16, 2022, 06:08:22 am »
Hi! Tested successfully the three demos on Linux. Good job!

Great! So this isn't just "it works on my computers"TM  :D

On my Windows 10 Home, the js_bidir demo works, but the js_eval doesn't, even though js_bidir also does what js_eval does.  %) And, I copied the two DLLs and three executables to my son's Windows 10 computer, and they all crash! Ok, I need to figure out Windows more...

Edit: Alright, js_eval, as a Pascal program invoking webview.dll, does work. It appears not working due to the behaviour of the Windows web engine's HTML and Javascript execution model. After I added sleep(2) statement between webview_navigate() and webview_eval(), I could see the webview window flash from content inserted by webview_eval() to content inserted by webview_navigate(). 
« Last Edit: February 16, 2022, 07:49:44 am by PierceNg »

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: fpwebview - Free Pascal binding for webview
« Reply #10 on: February 16, 2022, 06:01:28 pm »
Quote
[/code]

Change the variable to the full path of fpc.exe on your machine. E.g. on my machine, I installed Lazarus into c:\pkg\lazarus, so the fpc.exe path is:

Code: Text  [Select][+][-]
  1. set fpcexe=c:\pkg\lazarus\fpc\3.2.2\bin\x86_64-win64\fpc.exe
exe is built but didnt run because stop by windows security
 it can't be used on normal gui application? so we can use edit text to enter any website we want to navigate ?
thanks

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
Re: fpwebview - Free Pascal binding for webview
« Reply #11 on: February 16, 2022, 06:17:32 pm »

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: fpwebview - Free Pascal binding for webview
« Reply #12 on: February 17, 2022, 02:22:13 am »
exe is built but didnt run because stop by windows security

What version of Windows are you running? Is your account an administrator or normal user account?

My computer runs Windows 10 Home 20H2 and I am running as a normal user account.

it can't be used on normal gui application? so we can use edit text to enter any website we want to navigate ?
thanks

This needs more work. By default, webview.dll creates the GUI window and runs its main loop. To embed webview's window as part of a Lazarus application, the Lazarus application has to create the window, get its 'native window handle' - for Windows this is HWND - and invoke webview_create() with said HWND. How the two main loops coexist remains to be seen.

Alternatively, maybe can use HTML frames to split the webview window into sections, one of which becomes the 'browser URL bar' frame.

I'm interested to get this done too but for now my focus is on implementing the embedded web server.


trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: fpwebview - Free Pascal binding for webview
« Reply #14 on: February 17, 2022, 07:46:49 am »
In the demo, nothig is executed after
Code: Text  [Select][+][-]
  1. webview_run(w);
- tested on macOS x86_64.

 

TinyPortal © 2005-2018