Sign in Join
Wiki copytemporary

fpCEF3: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## Description
22
33![](/wiki-images/b/b4/SimpleChromium.png)
44
55Chromium is an open source project (from Google) to create a browser for different platforms. Among other things the browser Chrome is based on it.
66
77The Chromium Embedded Framework (CEF) is an open source framework for embedding Chromium into user applications. It can be used on Linux, macOS and Windows in 32 and 64 bit versions. Originally there were two versions of CEF, CEF1 and CEF3, but CEF1 is no longer maintained.
88
99CEF can be used in Delphi via the Delphi Chromium Embedded Framework (DCEF3). For Lazarus/Free Pascal there is the equivalent framework [fpCEF3](https://github.com/dliw/fpCEF3) (or alternative [CEF4Delphi](https://github.com/salvadordf/CEF4Delphi) with examples for Lazarus including newest versions of Chromium Embedded Framework).
1010
1111## Installation
1212
1313Besides the Lazarus package, the CEF framework itself is needed. It is important to use the correct version of the CEF framework for the fpCEF release used. Further specific installation instructions can be found on Github: [<https://github.com/dliw/fpCEF3>](https://github.com/dliw/fpCEF3)
1414
1515The latest release and its corresponding CEF version can be found on [1](https://github.com/dliw/fpCEF3/releases/latest)
1616
1717CEF releases can be found on <https://cef-builds.spotifycdn.com/index.html> (use the version filter or click "Show more builds" to find the release)
1818
1919### Download Package
2020
2121fpCEF3 with [Git](http://git-scm.com/)
2222
23-[`git://github.com/dliw/fpCEF3.git`](git://github.com/dliw/fpCEF3.git)
23+```text
24+git://github.com/dliw/fpCEF3.git
25+```
2426
2527You can also download a zipped package:
2628
27-[`master.zip`](https://github.com/dliw/fpCEF3/archive/master.zip)
29+```text
30+master.zip
31+```
2832
2933### Package Installation
3034
3135![](/wiki-images/3/33/Chromium.png)
3236
3337After downloading of package fpCEF3, it can be installed in Lazarus:
3438
3539- Start Lazarus and open main menu *Package* -\> *Open package file (.lpk)...*
3640- Select the file *cef3.lpk* in the fpCEF3 subdirectory *Component*
3741- The package editing window will open
3842- Click on *Compile*, the package will be compiled
3943- Click on *Use...*-\> *Install* and confirm the dialog window with *Yes*
4044- Lazarus is now compiling and create a new tab *Chromium* in the component palette
4145
4246### Download Framework CEF3
4347
4448You can now download the framework and made the libraries available for a particular project. You can download it from the following pages:\
4549[<https://cefbuilds.com>](https://cefbuilds.com)\
4650[<http://www.magpcss.net/cef_downloads>](http://www.magpcss.net/cef_downloads) (or a older version from [here](http://www.magpcss.net/cef_downloads/index.php?query=label%3ADeprecated#list))
4751
4852> **Note:** Make sure to use the correct framework version for the fpCEF version! See Installation
4953
5054## Usage
5155
5256### Minimal example
5357
5458A minimal example with a simple browser is created.
5559
5660#### Windows
5761
5862The CEF libraries are needed for loading, so it makes sense to create a new project folder, to save the project and the libraries in it together.
5963
6064- Create a new directory for the project to a location of your choice such as *C:\SimpleBrowser*
6165- Copy the complete CEF3 directory *Resources* to *C:\SimpleBrowser*
6266- Copy the contents of the CEF3 directory *Release* in the directory *C:\SimpleBrowser*
6367
6468The files (*libcef.dll*, *natives_blob.bin*, *icudtl.dat* etc.) are in the same directory as the project and the directory *locales* in *C:\SimpleBrowser\locales*.\
6569To prevent misunderstands, here is a picture how the file and directory structure of the Simplebrowser should look:\
6670
6771![](/wiki-images/a/aa/FilesForSimplebrowser.png)\
6872
6973Now build the project with Lazarus
7074
7175- Create a new empty [[Form Tutorial|GUI application]]
7276- Save the project in the directory you specify for Windows (e.g. under *C:\SimpleBrowser*)
7377- Drop a `TEditButton` on the form
7478- With Object Inspector set the `Name` to `edtURL`, `Align` on `alTop` and `ButtonCaption` to `go`
7579- Put a `TChromium` on the form and set the `Name` to `Chromium` and its `Align` to `alClient`
7680- Create the `OnButtonClick` event handler for the TEditButton `edtURL`. Select the `OnButtonClick` in the Object Inspector tab `events` and click on the button \[...\]
7781- Write following code (chromium should open at each click the URL in the text box):
7882
7983``` pascal
8084procedure TForm1.edtURLClick(Sender: TObject);
8185begin
8286 Chromium.Load(UTF8Decode(edtURL.Text));
8387end;
8488```
8589
8690- `Chromium` must be initialized at the start of the program, you can do this with the `OnCreate` event handler of the form:
8791
8892``` pascal
8993procedure TForm1.FormCreate(Sender: TObject);
9094var
9195 PrjPath: ustring;
9296 Lang, FallbackLang: string;
9397begin
9498 PrjPath := UTF8Decode(GetCurrentDir + PathDelim);
9599 CefLocalesDirPath := PrjPath + 'locales';
96100 GetLanguageIDs(Lang, FallbackLang);
97101 CefLocale := UTF8Decode(FallbackLang);
98102 edtURL.Text:='http://www.lazarus-ide.org/';
99103end;
100104```
101105
102106- If a identifier wouldn't be found, you have to put some units to the uses clause. These units should be in there:
103107
104108``` pascal
105109uses
106110 sysutils, Forms, EditBtn, cef3lcl, cef3intf, cef3types, cef3lib, gettext;
107111```
108112
109113- Run your program, if all goes well it might look like:
110114
111115![](/wiki-images/b/b4/SimpleChromium.png)\
112116
113117### Show URL of loaded page
114118
115119Based on Minimal example
116120
117121- Create the `OnLoadEnd` event handler for `Chromium`
118122- Write following code (URL should be updated after any browsing):
119123
120124``` pascal
121125procedure TForm1.ChromiumLoadEnd(Sender: TObject; const Browser: ICefBrowser;
122126 const Frame: ICefFrame; httpStatusCode: Integer);
123127begin
124128 edtURL.Text:=UTF8Encode(Browser.MainFrame.Url);
125129end;
126130```
127131
128132### Allow downloading of files
129133
130134- Create the `OnBeforeDownload` event handler for `Chromium` and write in it:
131135
132136``` pascal
133137procedure TForm1.ChromiumBeforeDownload(Sender: TObject;
134138 const Browser: ICefBrowser; const downloadItem: ICefDownloadItem;
135139 const suggestedName: ustring; const callback: ICefBeforeDownloadCallback);
136140begin
137141 callback.Cont(suggestedName, True);
138142end;
139143```
140144
141145### Printing per code
142146
143147- Add a `TButton` on your form and write in its `OnClick` event handler:
144148
145149``` pascal
146150procedure TForm1.Button1Click(Sender: TObject);
147151begin
148152 Chromium.Browser.Host.Print;
149153end;
150154```
151155
152156### Creating a pdf
153157
154158- Add a `TSaveDialog` on your form
155159- Add a `TButton` on your form and write in its `OnClick` event handler:
156160
157161``` pascal
158162procedure TForm1.Button1Click(Sender: TObject);
159163var
160164 CefPdfPrintSettings: TCefPdfPrintSettings;
161165 EmptyCefStringUtf16: TCefStringUtf16;
162166begin
163167 SaveDialog1.DefaultExt := 'pdf';
164168 SaveDialog1.Filter := 'Portable Document Format (pdf)|*.pdf';
165169 if SaveDialog1.Execute then
166170 begin
167171 FillByte(EmptyCefStringUtf16, SizeOf(EmptyCefStringUtf16), 0);
168172
169173 CefPdfPrintSettings.backgrounds_enabled := 1;
170174 CefPdfPrintSettings.header_footer_enabled := 0;
171175 CefPdfPrintSettings.header_footer_title := EmptyCefStringUtf16;
172176 CefPdfPrintSettings.header_footer_url := EmptyCefStringUtf16;
173177 CefPdfPrintSettings.landscape := 0;
174178 CefPdfPrintSettings.margin_bottom := 0;
175179 CefPdfPrintSettings.margin_left := 0;
176180 CefPdfPrintSettings.margin_right := 0;
177181 CefPdfPrintSettings.margin_top := 0;
178182 CefPdfPrintSettings.margin_type := PDF_PRINT_MARGIN_DEFAULT;
179183 CefPdfPrintSettings.page_height := 0;
180184 CefPdfPrintSettings.page_width := 0;
181185 CefPdfPrintSettings.selection_only := 0;
182186
183187 Chromium.Browser.Host.PrintToPdf(UTF8Decode(SaveDialog1.FileName), CefPdfPrintSettings, Nil);
184188 end;
185189end;
186190```
187191
188192The description of the `TCefPdfPrintSettings` you will find by the declaration of the `TCefPdfPrintSettings`
189193
190194## Known Problems
191195
192196- If your program doesn't start, maybe a Antivirus program prevent this.
193197- If your program start but your TChromium window keeps empty, maybe a firewall block it (see [Chromium Embedded Framework for Free Pascal (fpCEF3) BRUNCH 2556](http://forum.lazarus.freepascal.org/index.php/topic,31361.0.html)).
194198- If your file structure isn't correct (see Minimal example) and therefore some libraries wouldn't be found, you can get optical errors (see [Fpcef red borders in the browser](http://forum.lazarus.freepascal.org/index.php/topic,30763.0.html)).
195199
196200## Further Information
197201
198202- [Thread in the German Lazarusforum](http://www.lazarusforum.de/viewtopic.php?f=18&t=7676)
199203- [[Webbrowser]]
200204
201205---
202206*From the Free Pascal wiki, page "fpCEF3", as it stood on 2021-01-15 after a change by Michael.vanham, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
203207Category: Components
204208Category: LCL

Back to history