Sign in Join
Wiki copytemporary

fpCEF3: what changed

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

OldNewLine
11## Description
22
3-<img src="SimpleChromium.png" title="SimpleChromium.png" width="320" />
3+![](/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
2323[`git://github.com/dliw/fpCEF3.git`](git://github.com/dliw/fpCEF3.git)
2424
2525You can also download a zipped package:
2626
2727[`master.zip`](https://github.com/dliw/fpCEF3/archive/master.zip)
2828
2929### Package Installation
3030
3131![](/wiki-images/3/33/Chromium.png)
3232
3333After downloading of package fpCEF3, it can be installed in Lazarus:
3434
3535- Start Lazarus and open main menu *Package* -\> *Open package file (.lpk)...*
3636- Select the file *cef3.lpk* in the fpCEF3 subdirectory *Component*
3737- The package editing window will open
3838- Click on *Compile*, the package will be compiled
3939- Click on *Use...*-\> *Install* and confirm the dialog window with *Yes*
4040- Lazarus is now compiling and create a new tab *Chromium* in the component palette
4141
4242### Download Framework CEF3
4343
4444You can now download the framework and made the libraries available for a particular project. You can download it from the following pages:\
4545[<https://cefbuilds.com>](https://cefbuilds.com)\
4646[<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))
4747
4848> **Note:** Make sure to use the correct framework version for the fpCEF version! See Installation
4949
5050## Usage
5151
5252### Minimal example
5353
5454A minimal example with a simple browser is created.
5555
5656#### Windows
5757
5858The 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.
5959
6060- Create a new directory for the project to a location of your choice such as *C:\SimpleBrowser*
6161- Copy the complete CEF3 directory *Resources* to *C:\SimpleBrowser*
6262- Copy the contents of the CEF3 directory *Release* in the directory *C:\SimpleBrowser*
6363
6464The 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*.\
6565To prevent misunderstands, here is a picture how the file and directory structure of the Simplebrowser should look:\
6666
6767![](/wiki-images/a/aa/FilesForSimplebrowser.png)\
6868
6969Now build the project with Lazarus
7070
7171- Create a new empty [[Form Tutorial|GUI application]]
7272- Save the project in the directory you specify for Windows (e.g. under *C:\SimpleBrowser*)
7373- Drop a `TEditButton` on the form
7474- With Object Inspector set the `Name` to `edtURL`, `Align` on `alTop` and `ButtonCaption` to `go`
7575- Put a `TChromium` on the form and set the `Name` to `Chromium` and its `Align` to `alClient`
7676- Create the `OnButtonClick` event handler for the TEditButton `edtURL`. Select the `OnButtonClick` in the Object Inspector tab `events` and click on the button \[...\]
7777- Write following code (chromium should open at each click the URL in the text box):
7878
7979``` pascal
8080procedure TForm1.edtURLClick(Sender: TObject);
8181begin
8282 Chromium.Load(UTF8Decode(edtURL.Text));
8383end;
8484```
8585
8686- `Chromium` must be initialized at the start of the program, you can do this with the `OnCreate` event handler of the form:
8787
8888``` pascal
8989procedure TForm1.FormCreate(Sender: TObject);
9090var
9191 PrjPath: ustring;
9292 Lang, FallbackLang: string;
9393begin
9494 PrjPath := UTF8Decode(GetCurrentDir + PathDelim);
9595 CefLocalesDirPath := PrjPath + 'locales';
9696 GetLanguageIDs(Lang, FallbackLang);
9797 CefLocale := UTF8Decode(FallbackLang);
9898 edtURL.Text:='http://www.lazarus-ide.org/';
9999end;
100100```
101101
102102- If a identifier wouldn't be found, you have to put some units to the uses clause. These units should be in there:
103103
104104``` pascal
105105uses
106106 sysutils, Forms, EditBtn, cef3lcl, cef3intf, cef3types, cef3lib, gettext;
107107```
108108
109109- Run your program, if all goes well it might look like:
110110
111111![](/wiki-images/b/b4/SimpleChromium.png)\
112112
113113### Show URL of loaded page
114114
115115Based on Minimal example
116116
117117- Create the `OnLoadEnd` event handler for `Chromium`
118118- Write following code (URL should be updated after any browsing):
119119
120120``` pascal
121121procedure TForm1.ChromiumLoadEnd(Sender: TObject; const Browser: ICefBrowser;
122122 const Frame: ICefFrame; httpStatusCode: Integer);
123123begin
124124 edtURL.Text:=UTF8Encode(Browser.MainFrame.Url);
125125end;
126126```
127127
128128### Allow downloading of files
129129
130130- Create the `OnBeforeDownload` event handler for `Chromium` and write in it:
131131
132132``` pascal
133133procedure TForm1.ChromiumBeforeDownload(Sender: TObject;
134134 const Browser: ICefBrowser; const downloadItem: ICefDownloadItem;
135135 const suggestedName: ustring; const callback: ICefBeforeDownloadCallback);
136136begin
137137 callback.Cont(suggestedName, True);
138138end;
139139```
140140
141141### Printing per code
142142
143143- Add a `TButton` on your form and write in its `OnClick` event handler:
144144
145145``` pascal
146146procedure TForm1.Button1Click(Sender: TObject);
147147begin
148148 Chromium.Browser.Host.Print;
149149end;
150150```
151151
152152### Creating a pdf
153153
154154- Add a `TSaveDialog` on your form
155155- Add a `TButton` on your form and write in its `OnClick` event handler:
156156
157157``` pascal
158158procedure TForm1.Button1Click(Sender: TObject);
159159var
160160 CefPdfPrintSettings: TCefPdfPrintSettings;
161161 EmptyCefStringUtf16: TCefStringUtf16;
162162begin
163163 SaveDialog1.DefaultExt := 'pdf';
164164 SaveDialog1.Filter := 'Portable Document Format (pdf)|*.pdf';
165165 if SaveDialog1.Execute then
166166 begin
167167 FillByte(EmptyCefStringUtf16, SizeOf(EmptyCefStringUtf16), 0);
168168
169169 CefPdfPrintSettings.backgrounds_enabled := 1;
170170 CefPdfPrintSettings.header_footer_enabled := 0;
171171 CefPdfPrintSettings.header_footer_title := EmptyCefStringUtf16;
172172 CefPdfPrintSettings.header_footer_url := EmptyCefStringUtf16;
173173 CefPdfPrintSettings.landscape := 0;
174174 CefPdfPrintSettings.margin_bottom := 0;
175175 CefPdfPrintSettings.margin_left := 0;
176176 CefPdfPrintSettings.margin_right := 0;
177177 CefPdfPrintSettings.margin_top := 0;
178178 CefPdfPrintSettings.margin_type := PDF_PRINT_MARGIN_DEFAULT;
179179 CefPdfPrintSettings.page_height := 0;
180180 CefPdfPrintSettings.page_width := 0;
181181 CefPdfPrintSettings.selection_only := 0;
182182
183183 Chromium.Browser.Host.PrintToPdf(UTF8Decode(SaveDialog1.FileName), CefPdfPrintSettings, Nil);
184184 end;
185185end;
186186```
187187
188188The description of the `TCefPdfPrintSettings` you will find by the declaration of the `TCefPdfPrintSettings`
189189
190190## Known Problems
191191
192192- If your program doesn't start, maybe a Antivirus program prevent this.
193193- 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)).
194194- 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)).
195195
196196## Further Information
197197
198198- [Thread in the German Lazarusforum](http://www.lazarusforum.de/viewtopic.php?f=18&t=7676)
199199- [[Webbrowser]]
200200
201201---
202202*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).*
203203Category: Components
204204Category: LCL

Back to history