1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-08-04 21:32:54 +02:00

Added a GlobalCEFApp.OnUncaughtException example to the MiniBrowser demo.

This commit is contained in:
salvadordf
2023-09-24 16:23:36 +02:00
parent 8979dc8078
commit 69adbfb115
8 changed files with 56 additions and 161 deletions

View File

@ -1,41 +1,3 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright � 2018 Salvador D�az Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
program MiniBrowser; program MiniBrowser;
{$I cef.inc} {$I cef.inc}

View File

@ -13,7 +13,6 @@ object DirectorySelectorFrm: TDirectorySelectorFrm
Font.Name = 'Segoe UI' Font.Name = 'Segoe UI'
Font.Style = [] Font.Style = []
Position = poScreenCenter Position = poScreenCenter
PixelsPerInch = 96
TextHeight = 15 TextHeight = 15
object Panel1: TPanel object Panel1: TPanel
Left = 0 Left = 0
@ -27,6 +26,8 @@ object DirectorySelectorFrm: TDirectorySelectorFrm
Padding.Right = 5 Padding.Right = 5
Padding.Bottom = 5 Padding.Bottom = 5
TabOrder = 0 TabOrder = 0
ExplicitTop = 404
ExplicitWidth = 313
object OkBtn: TButton object OkBtn: TButton
Left = 5 Left = 5
Top = 5 Top = 5
@ -46,6 +47,7 @@ object DirectorySelectorFrm: TDirectorySelectorFrm
Caption = 'Cancel' Caption = 'Cancel'
ModalResult = 2 ModalResult = 2
TabOrder = 1 TabOrder = 1
ExplicitLeft = 188
end end
end end
object Panel2: TPanel object Panel2: TPanel
@ -60,6 +62,7 @@ object DirectorySelectorFrm: TDirectorySelectorFrm
Padding.Right = 5 Padding.Right = 5
Padding.Bottom = 5 Padding.Bottom = 5
TabOrder = 1 TabOrder = 1
ExplicitWidth = 313
object DriveComboBox1: TDriveComboBox object DriveComboBox1: TDriveComboBox
Left = 5 Left = 5
Top = 5 Top = 5
@ -68,6 +71,7 @@ object DirectorySelectorFrm: TDirectorySelectorFrm
Align = alClient Align = alClient
DirList = DirectoryListBox1 DirList = DirectoryListBox1
TabOrder = 0 TabOrder = 0
ExplicitWidth = 303
end end
end end
object Panel3: TPanel object Panel3: TPanel
@ -80,6 +84,8 @@ object DirectorySelectorFrm: TDirectorySelectorFrm
Padding.Left = 5 Padding.Left = 5
Padding.Right = 5 Padding.Right = 5
TabOrder = 2 TabOrder = 2
ExplicitWidth = 313
ExplicitHeight = 373
object DirectoryListBox1: TDirectoryListBox object DirectoryListBox1: TDirectoryListBox
Left = 5 Left = 5
Top = 0 Top = 0
@ -87,6 +93,8 @@ object DirectorySelectorFrm: TDirectorySelectorFrm
Height = 374 Height = 374
Align = alClient Align = alClient
TabOrder = 0 TabOrder = 0
ExplicitWidth = 303
ExplicitHeight = 373
end end
end end
end end

View File

@ -1,40 +1,3 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright � 2023 Salvador Diaz Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
unit uDirectorySelector; unit uDirectorySelector;
{$I cef.inc} {$I cef.inc}

View File

@ -143,6 +143,9 @@ object MiniBrowserFrm: TMiniBrowserFrm
'https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input' + 'https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input' +
'_type_file' '_type_file'
'https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_stat' +
'e_throw_error'
'https://www.htmlquick.com/es/reference/tags/input-file.html' 'https://www.htmlquick.com/es/reference/tags/input-file.html'
'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/' + 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/' +
@ -273,6 +276,9 @@ object MiniBrowserFrm: TMiniBrowserFrm
end end
item item
Width = 100 Width = 100
end
item
Width = 50
end> end>
ExplicitTop = 691 ExplicitTop = 691
ExplicitWidth = 1176 ExplicitWidth = 1176
@ -298,6 +304,7 @@ object MiniBrowserFrm: TMiniBrowserFrm
OnTitleChange = Chromium1TitleChange OnTitleChange = Chromium1TitleChange
OnFullScreenModeChange = Chromium1FullScreenModeChange OnFullScreenModeChange = Chromium1FullScreenModeChange
OnStatusMessage = Chromium1StatusMessage OnStatusMessage = Chromium1StatusMessage
OnConsoleMessage = Chromium1ConsoleMessage
OnLoadingProgressChange = Chromium1LoadingProgressChange OnLoadingProgressChange = Chromium1LoadingProgressChange
OnCursorChange = Chromium1CursorChange OnCursorChange = Chromium1CursorChange
OnMediaAccessChange = Chromium1MediaAccessChange OnMediaAccessChange = Chromium1MediaAccessChange

View File

@ -1,40 +1,3 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright � 2023 Salvador Diaz Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
unit uMiniBrowser; unit uMiniBrowser;
{$I cef.inc} {$I cef.inc}
@ -192,6 +155,7 @@ type
procedure Chromium1CanDownload(Sender: TObject; const browser: ICefBrowser; const url, request_method: ustring; var aResult: Boolean); procedure Chromium1CanDownload(Sender: TObject; const browser: ICefBrowser; const url, request_method: ustring; var aResult: Boolean);
procedure Chromium1MediaAccessChange(Sender: TObject; const browser: ICefBrowser; has_video_access, has_audio_access: Boolean); procedure Chromium1MediaAccessChange(Sender: TObject; const browser: ICefBrowser; has_video_access, has_audio_access: Boolean);
procedure Chromium1RequestMediaAccessPermission(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const requesting_origin: ustring; requested_permissions: Cardinal; const callback: ICefMediaAccessCallback; var aResult: Boolean); procedure Chromium1RequestMediaAccessPermission(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const requesting_origin: ustring; requested_permissions: Cardinal; const callback: ICefMediaAccessCallback; var aResult: Boolean);
procedure Chromium1ConsoleMessage(Sender: TObject; const browser: ICefBrowser; level: Cardinal; const message_, source: ustring; line: Integer; out Result: Boolean);
procedure BackBtnClick(Sender: TObject); procedure BackBtnClick(Sender: TObject);
procedure ForwardBtnClick(Sender: TObject); procedure ForwardBtnClick(Sender: TObject);
@ -234,6 +198,7 @@ type
FSelectCertCallback : ICefSelectClientCertificateCallback; FSelectCertCallback : ICefSelectClientCertificateCallback;
FCertificates : TCefX509CertificateArray; FCertificates : TCefX509CertificateArray;
FAllowDownloads : boolean; FAllowDownloads : boolean;
FJSException : integer;
FMediaAccessCallback : ICefMediaAccessCallback; FMediaAccessCallback : ICefMediaAccessCallback;
FRequestingOrigin : string; FRequestingOrigin : string;
@ -315,14 +280,29 @@ uses
// 2. TChromium.OnClose sends a CEFBROWSER_DESTROY message to destroy CEFWindowParent1 in the main thread, which triggers the TChromium.OnBeforeClose event. // 2. TChromium.OnClose sends a CEFBROWSER_DESTROY message to destroy CEFWindowParent1 in the main thread, which triggers the TChromium.OnBeforeClose event.
// 3. TChromium.OnBeforeClose sets FCanClose := True and sends WM_CLOSE to the form. // 3. TChromium.OnBeforeClose sets FCanClose := True and sends WM_CLOSE to the form.
procedure GlobalCEFApp_OnUncaughtException(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context; const exception: ICefV8Exception; const stackTrace: ICefV8StackTrace);
begin
// This code runs in the render process and we can't set a breakpoint to debug it from the main application process.
// Read this for more information about debugging CEF subprocesses :
// https://www.briskbard.com/index.php?lang=en&pageid=cef#debugging
// In this example we only use the "console trick" explained in the DOMVisitor demo to send some custom text to the
// main process that will be received in TChromiumCore.OnConsoleMessage
// Load the following page and delete the try..catch lines to test this event :
// https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_state_throw_error
if assigned(frame) and frame.IsValid then
frame.ExecuteJavaScript('console.log("GlobalCEFApp_OnUncaughtException");', '', 0);
end;
procedure CreateGlobalCEFApp; procedure CreateGlobalCEFApp;
begin begin
GlobalCEFApp := TCefApplication.Create; GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.cache := 'cache'; GlobalCEFApp.cache := 'cache';
GlobalCEFApp.EnablePrintPreview := True; GlobalCEFApp.EnablePrintPreview := True;
GlobalCEFApp.EnableGPU := True; GlobalCEFApp.EnableGPU := True;
GlobalCEFApp.LogFile := 'debug.log'; GlobalCEFApp.LogFile := 'debug.log';
GlobalCEFApp.LogSeverity := LOGSEVERITY_INFO; GlobalCEFApp.LogSeverity := LOGSEVERITY_INFO;
GlobalCEFApp.UncaughtExceptionStackSize := 50;
GlobalCEFApp.OnUncaughtException := GlobalCEFApp_OnUncaughtException;
//GlobalCEFApp.ChromeRuntime := True; //GlobalCEFApp.ChromeRuntime := True;
end; end;
@ -525,6 +505,17 @@ begin
end; end;
end; end;
procedure TMiniBrowserFrm.Chromium1ConsoleMessage(Sender: TObject;
const browser: ICefBrowser; level: Cardinal; const message_,
source: ustring; line: Integer; out Result: Boolean);
begin
if (message_ = 'GlobalCEFApp_OnUncaughtException') then
begin
inc(FJSException);
StatusBar1.Panels[4].Text := 'JS exception: ' + inttostr(FJSException);
end;
end;
procedure TMiniBrowserFrm.Chromium1ContextMenuCommand(Sender: TObject; procedure TMiniBrowserFrm.Chromium1ContextMenuCommand(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer; const params: ICefContextMenuParams; commandId: Integer;

View File

@ -17,9 +17,7 @@ object PreferencesFrm: TPreferencesFrm
Padding.Top = 10 Padding.Top = 10
Padding.Right = 10 Padding.Right = 10
Padding.Bottom = 10 Padding.Bottom = 10
OldCreateOrder = False
Position = poScreenCenter Position = poScreenCenter
PixelsPerInch = 96
TextHeight = 13 TextHeight = 13
object GroupBox1: TGroupBox object GroupBox1: TGroupBox
Left = 10 Left = 10
@ -29,6 +27,7 @@ object PreferencesFrm: TPreferencesFrm
Align = alTop Align = alTop
Caption = ' Proxy ' Caption = ' Proxy '
TabOrder = 0 TabOrder = 0
ExplicitWidth = 404
object ProxyTypeLbl: TLabel object ProxyTypeLbl: TLabel
Left = 12 Left = 12
Top = 27 Top = 27
@ -180,6 +179,7 @@ object PreferencesFrm: TPreferencesFrm
Align = alTop Align = alTop
Caption = ' Custom header ' Caption = ' Custom header '
TabOrder = 1 TabOrder = 1
ExplicitWidth = 404
object HeaderNameLbl: TLabel object HeaderNameLbl: TLabel
Left = 12 Left = 12
Top = 26 Top = 26
@ -219,7 +219,8 @@ object PreferencesFrm: TPreferencesFrm
Padding.Left = 30 Padding.Left = 30
Padding.Right = 30 Padding.Right = 30
TabOrder = 2 TabOrder = 2
ExplicitTop = 373 ExplicitTop = 352
ExplicitWidth = 404
object Button1: TButton object Button1: TButton
Left = 30 Left = 30
Top = 0 Top = 0
@ -239,7 +240,7 @@ object PreferencesFrm: TPreferencesFrm
Caption = 'Cancel' Caption = 'Cancel'
ModalResult = 2 ModalResult = 2
TabOrder = 1 TabOrder = 1
ExplicitLeft = 278 ExplicitLeft = 254
end end
end end
end end

View File

@ -1,40 +1,3 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright � 2023 Salvador Diaz Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
unit uPreferences; unit uPreferences;
{$I cef.inc} {$I cef.inc}

View File

@ -2,7 +2,7 @@
"UpdateLazPackages" : [ "UpdateLazPackages" : [
{ {
"ForceNotify" : true, "ForceNotify" : true,
"InternalVersion" : 518, "InternalVersion" : 519,
"Name" : "cef4delphi_lazarus.lpk", "Name" : "cef4delphi_lazarus.lpk",
"Version" : "117.1.4" "Version" : "117.1.4"
} }