Some questions of CEF4Delphi lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- maurobio · 2023-07-16 13:07 Dear ALL, CEF4Delphi is really a great component. But as I am still learning to use it, I naturally have a few questions (none of them seemingly critical). Let's see: 1) Is there a way of getting the URL of a link when the cursor hovers over it? 2) Is there a way of programmatically obtaining the version number of CEF currently being used in an application? 3) The "BrowserWindow" demo in the "Lazarus_any_OS" demo folder, calls some procedures (Chromium1BeforePopup, Chromium1OpenUrlFromTab, WMEnterMenuLoop, WMExitMenuLoop, these last two specific to MS- Windows) which are not clear to me; I just didn't called them in my application (which has no menu and no tabs) and it runs fine anyway, so are these procedure calls really required? 4) To run my application successfully, I just copied the contents of the "Resources" and "Release" folders to the application folder, but I would prefer to keep these files in their own folders, inside my application folder, as follows: MyApp\    MyApp.exe    MayApp.txt    MayApp.html (etc. etc.)    Release\ (or any other name for the CEF folder)    Resources\ (including the "locales" folder) Is there a simple way of getting the CEF files being found by my application in a folder structure as shown above? 5) In my application, I get some data from external URL's and I would like to show a message on the status bar as data from each URL is fetched, but even calling Application.ProcessMessages at the start of the process, no message is displayed; I do understand that this question may not be related to CEF, but is there a way to get messages being displayed in the status bar? Thanks in advance for any assistance you can provide! With warmest regards, ---------------------------------------------------------------------- salvadordf · 2023-07-16 15:42 Hi, Please, read this document : https://www.briskbard.com/index.php?lang=en&pageid=cef Quote from: maurobio on July 16, 2023, 03:07:59 pm1) Is there a way of getting the URL of a link when the cursor hovers over it? Yes but it's necessary to register a "JavaScript extension" to send that information from the JavaScript code in the browser to the Pascal code in Lazarus. See the demo in the "CEF4Delphi\demos\Lazarus_Windows\JavaScript\JSExtension" directory and read the code comments. If you're beginning to learn about CEF I would recommend that you familiarize with it first because this demo is one of the most complicated. Quote from: maurobio on July 16, 2023, 03:07:59 pm2) Is there a way of programmatically obtaining the version number of CEF currently being used in an application? GlobalCEFApp.LibCefVersion returns the current CEF version in string format. If you need integer values then use CEF_SUPPORTED_VERSION_MAJOR, CEF_SUPPORTED_VERSION_MINOR, CEF_SUPPORTED_VERSION_RELEASE and CEF_SUPPORTED_VERSION_BUILD. They are defined in uCEFApplicationCore. Quote from: maurobio on July 16, 2023, 03:07:59 pm3) The "BrowserWindow" demo in the "Lazarus_any_OS" demo folder, calls some procedures (Chromium1BeforePopup, Chromium1OpenUrlFromTab, WMEnterMenuLoop, WMExitMenuLoop, these last two specific to MS- Windows) which are not clear to me; I just didn't called them in my application (which has no menu and no tabs) and it runs fine anyway, so are these procedure calls really required? The procedures handling those messages set the GlobalCEFApp.OsmodalLoop property value which has this meaning : QuoteSet to true (1) before calling Windows APIs like TrackPopupMenu that enter a modal message loop. Set to false (0) after exiting the modal message loop.https://bitbucket.org/chromiumembedded/cef/src/1353 677a983fb36b9fad46fddad33c8c0ff60330/include/internal/cef_app_win.h#li nes-90 Check that your application works fine when the user clicks in popup menus before removing it. Quote from: maurobio on July 16, 2023, 03:07:59 pm4) To run my application successfully, I just copied the contents of the "Resources" and "Release" folders to the application folder, but I would prefer to keep these files in their own folders, inside my application folder, as follows: MyApp\    MyApp.exe    MayApp.txt    MayApp.html (etc. etc.)    Release\ (or any other name for the CEF folder)    Resources\ (including the "locales" folder) Is there a simple way of getting the CEF files being found by my application in a folder structure as shown above? Read this : https://www.briskbard.com/index.php?lang=en&pageid=cef#builddemo You can move the CEF files to another directory if you set the GlobalCEFApp properties right. This is the usual layout in Windows : https://www.briskbard.com/images/ceflayout.png Quote from: maurobio on July 16, 2023, 03:07:59 pm5) In my application, I get some data from external URL's and I would like to show a message on the status bar as data from each URL is fetched, but even calling Application.ProcessMessages at the start of the process, no message is displayed; I do understand that this question may not be related to CEF, but is there a way to get messages being displayed in the status bar? Are you trying to set the status bar text inside a CEF event? Please, remember that the default browser mode executes most of the CEF events in the context of a CEF thread and you should handle the user interface in the main application thread only. The CEF4Delphi demos are oversimplified and sometimes they don't follow this rule. ---------------------------------------------------------------------- maurobio · 2023-07-16 18:56 Hi, @salvadordf! Thanks a lot for taking the time to reply to my rather naive questions! QuoteYes but it's necessary to register a "JavaScript extension" to send that information from the JavaScript code in the browser to the Pascal code in Lazarus. Too complicated, and as it happens, I don't like JavaScript! No problem, I can live without that feature! QuoteGlobalCEFApp.LibCefVersion returns the current CEF version in string format This will do QuoteCheck that your application works fine when the user clicks in popup menus before removing it. My application does not have any menus nor uses tabs either, and it runs just fine without that procedure calls. QuoteYou can move the CEF files to another directory if you set the GlobalCEFApp properties right. This is the usual layout in Windows : I will take at look at these properties. The usual layout in Windows is what I already have. But the way, just after posting my original questions, I found a "README.txt" file which comes with the CEF binary distribution package. This file says that only five files ate absolutely required for running a CEF application (libcef.dll, chrome_elf.dll, icudtl.dat, snapshot_blob.bin, v8_context_snapshot.bin), however if I remove all other files in the "Release" directory, excepting these five, the application does not run, complaining that the remove files are missing. What are really the minimum required files for running a CEF application? Also, the "README.txt" says that "Locale file loading Pack file loading can be disabled completely using   CefSettings.pack_loading_disabled". Where exactly can I do that disabling? I am not developing yet another web browser, just a simple application which builds and displays (using CEF) a dynamic HTML page with links retrieved from the Web, so I need just minimum functionality. QuoteAre you trying to set the status bar text inside a CEF event? No, it happens entirely outside CEF, therefore I will not proceed with that question. Again, thank you very much! With warmest regards, ---------------------------------------------------------------------- salvadordf · 2023-07-19 10:19 Quote from: maurobio on July 16, 2023, 08:56:59 pmWhat are really the minimum required files for running a CEF application? cef_sandbox.lib and libcef.lib can be deleted safely. You can also delete unused language pak files in the "locales" directory but you always have to keep en-US.pak. Quote from: maurobio on July 16, 2023, 08:56:59 pmAlso, the "README.txt" says that "Locale file loading Pack file loading can be disabled completely using   CefSettings.pack_loading_disabled". Where exactly can I do that disabling? Set GlobalCEFApp.PackLoadingDisabled before the GlobalCEFApp.StartMainProcess call. ---------------------------------------------------------------------- maurobio · 2023-07-20 21:07 Hi, @salvadordf! QuoteYou can also delete unused language pak files in the "locales" directory but you always have to keep en-US.pak. Deleting all unused language files (except en-US.pak) from the "locales" directory caused CEF4Delphi to complain that the deleted files were missing. With best regards, ---------------------------------------------------------------------- salvadordf · 2023-07-21 13:12 Sorry. I forgot that you have to set GlobalCEFApp.CheckCEFFiles to false. Use the following functions in the uCEFMiscFunctions unit to check the CEF files manually : CheckLocalesCheckResourcesCheckDLLs Set the aLocalesRequired parameter in CheckLocales to a comma separated list of language codes that you use with your application. ---------------------------------------------------------------------- maurobio · 2023-07-22 22:15 Hi, @salvadordf! QuoteI forgot that you have to set GlobalCEFApp.CheckCEFFiles to false. I just uncommented this statement: GlobalCEFApp.CheckCEFFiles := False in the GlobalCefApplication unit, deleted all .pak files from the locales folder (except en-us.pak) and everything worked fine. I also noticed that if I remove entirely the locales folder and place the en-us.pak file in the main application directory, it also works but an empty locales folder is created anyway. I have already not understood how: (i) to set the location of the CEF DLL's; (ii) to set the location of the (required) locale .pak file (preventing the creation of an empty locales folder). Could you please provide some examples? BTW, where should these be set - should it be in the GlobalCefApplication unit? With warmest regards, ---------------------------------------------------------------------- salvadordf · 2023-07-25 15:19 You need to set GlobalCEFApp.FrameworkDirPath, GlobalCEFApp.ResourcesDirPath and GlobalCEFApp.LocalesDirPath before the GlobalCEFApp.StartMainProcess call in the project file because those properties are used during CEF initialization. The SimpleBrowser demo has an example here : https://github.com/salvadordf/CEF4Delphi/blob/1aae8fcb16304ca165a7a19e 2209d28eac8c22b6/demos/Lazarus_Windows/SimpleBrowser/SimpleBrowser.lpr #L59 The meaning of those properties are here : https://cef- builds.spotifycdn.com/docs/115.3/structcef__settings__t.html The CEF binaries have some hardcoded dependencies and you are not fully free to have a different file layout. You can move all the CEF binaries to another directory but I would suggest that you keep the same layout. ---------------------------------------------------------------------- egsuh · 2023-07-26 02:10 Please write some tutorial about this, based on your experiences. ---------------------------------------------------------------------- maurobio · 2023-07-26 23:53 Hi, salvadordf! Thanks a lot! I followed your latest instructions and everything worked fine! I have now been able to organize the directory structure of my application as follows:       MyApp.exe (my application binary executable)       (the CEF DLL's and other required files)       (the localization files, just en-US.pak for the time being)       (specific files used by my application) Thank you very much for your precious help! With warmest regards, ---------------------------------------------------------------------- maurobio · 2023-07-27 20:11 Hi, @salvadordf! But I still have a problem! My application runs fine under Windows, but it fails when I attempt to run it under Linux! It compiles without errors, but when I try and execute it, it simply does not start, without any warning or error message. It seems that the SimpleBrowser example on which I have based part of my code, is a Windows-only application. May this be the source of the problem? With best regards, ---------------------------------------------------------------------- rca · 2023-07-27 22:00 Quote from: maurobio on July 27, 2023, 10:11:21 pmIt seems that the SimpleBrowser example on which I have based part of my code, is a Windows-only application. May this be the source of the problem? With best regards, Please read this topic: https://forum.lazarus.freepascal.org/index.php /topic,62987.msg476859.html#msg476859, where @salvadordf explains how it works inside Linux. At that time, I followed those guidelines and checked within Ubuntu x86_64bit , the SimpleBrowser and Minibrowser examples worked Ok. ---------------------------------------------------------------------- maurobio · 2023-07-27 22:07 Hi, @rca! Thanks. In fact, I had already looked at that topic, but found it a little bit confuse. I am now working on the basis of the "BrowserWindow" demo in the "Lazarus_any_OS" folder which comes with the CEF demos. I hoped it worked without major modifications both in Windows and Linux, but have yet not been able to run it under Linux (Mint Linux in my case). With best regards, ---------------------------------------------------------------------- maurobio · 2023-07-28 12:03 Dear ALL, Unfortunately, I can confirm that neither the MiniBrowser nor the SimpleBrowser demos work under Linux Mint They work fine under Windows, but under Mint they simply do nothing, although compiling without errors. The BrowserWindow demo in the Lazarus_any_OS folder does not work either under Linux. Best regards, ---------------------------------------------------------------------- salvadordf · 2023-07-28 12:30 Use this CEF4Delphi release to avoid the GTK2 issue in Linux : https://github.com/salvadordf/CEF4Delphi/releases/tag/106.0.5249.119