mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-06-02 21:57:37 +02:00
Added a GlobalCEFApp.OnUncaughtException example to the MiniBrowser demo.
This commit is contained in:
parent
8979dc8078
commit
69adbfb115
@ -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;
|
||||
|
||||
{$I cef.inc}
|
||||
|
@ -13,7 +13,6 @@ object DirectorySelectorFrm: TDirectorySelectorFrm
|
||||
Font.Name = 'Segoe UI'
|
||||
Font.Style = []
|
||||
Position = poScreenCenter
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 15
|
||||
object Panel1: TPanel
|
||||
Left = 0
|
||||
@ -27,6 +26,8 @@ object DirectorySelectorFrm: TDirectorySelectorFrm
|
||||
Padding.Right = 5
|
||||
Padding.Bottom = 5
|
||||
TabOrder = 0
|
||||
ExplicitTop = 404
|
||||
ExplicitWidth = 313
|
||||
object OkBtn: TButton
|
||||
Left = 5
|
||||
Top = 5
|
||||
@ -46,6 +47,7 @@ object DirectorySelectorFrm: TDirectorySelectorFrm
|
||||
Caption = 'Cancel'
|
||||
ModalResult = 2
|
||||
TabOrder = 1
|
||||
ExplicitLeft = 188
|
||||
end
|
||||
end
|
||||
object Panel2: TPanel
|
||||
@ -60,6 +62,7 @@ object DirectorySelectorFrm: TDirectorySelectorFrm
|
||||
Padding.Right = 5
|
||||
Padding.Bottom = 5
|
||||
TabOrder = 1
|
||||
ExplicitWidth = 313
|
||||
object DriveComboBox1: TDriveComboBox
|
||||
Left = 5
|
||||
Top = 5
|
||||
@ -68,6 +71,7 @@ object DirectorySelectorFrm: TDirectorySelectorFrm
|
||||
Align = alClient
|
||||
DirList = DirectoryListBox1
|
||||
TabOrder = 0
|
||||
ExplicitWidth = 303
|
||||
end
|
||||
end
|
||||
object Panel3: TPanel
|
||||
@ -80,6 +84,8 @@ object DirectorySelectorFrm: TDirectorySelectorFrm
|
||||
Padding.Left = 5
|
||||
Padding.Right = 5
|
||||
TabOrder = 2
|
||||
ExplicitWidth = 313
|
||||
ExplicitHeight = 373
|
||||
object DirectoryListBox1: TDirectoryListBox
|
||||
Left = 5
|
||||
Top = 0
|
||||
@ -87,6 +93,8 @@ object DirectorySelectorFrm: TDirectorySelectorFrm
|
||||
Height = 374
|
||||
Align = alClient
|
||||
TabOrder = 0
|
||||
ExplicitWidth = 303
|
||||
ExplicitHeight = 373
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -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;
|
||||
|
||||
{$I cef.inc}
|
||||
|
@ -143,6 +143,9 @@ object MiniBrowserFrm: TMiniBrowserFrm
|
||||
|
||||
'https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input' +
|
||||
'_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://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/' +
|
||||
@ -273,6 +276,9 @@ object MiniBrowserFrm: TMiniBrowserFrm
|
||||
end
|
||||
item
|
||||
Width = 100
|
||||
end
|
||||
item
|
||||
Width = 50
|
||||
end>
|
||||
ExplicitTop = 691
|
||||
ExplicitWidth = 1176
|
||||
@ -298,6 +304,7 @@ object MiniBrowserFrm: TMiniBrowserFrm
|
||||
OnTitleChange = Chromium1TitleChange
|
||||
OnFullScreenModeChange = Chromium1FullScreenModeChange
|
||||
OnStatusMessage = Chromium1StatusMessage
|
||||
OnConsoleMessage = Chromium1ConsoleMessage
|
||||
OnLoadingProgressChange = Chromium1LoadingProgressChange
|
||||
OnCursorChange = Chromium1CursorChange
|
||||
OnMediaAccessChange = Chromium1MediaAccessChange
|
||||
|
@ -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;
|
||||
|
||||
{$I cef.inc}
|
||||
@ -192,6 +155,7 @@ type
|
||||
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 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 ForwardBtnClick(Sender: TObject);
|
||||
@ -234,6 +198,7 @@ type
|
||||
FSelectCertCallback : ICefSelectClientCertificateCallback;
|
||||
FCertificates : TCefX509CertificateArray;
|
||||
FAllowDownloads : boolean;
|
||||
FJSException : integer;
|
||||
|
||||
FMediaAccessCallback : ICefMediaAccessCallback;
|
||||
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.
|
||||
// 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;
|
||||
begin
|
||||
GlobalCEFApp := TCefApplication.Create;
|
||||
GlobalCEFApp.cache := 'cache';
|
||||
GlobalCEFApp.EnablePrintPreview := True;
|
||||
GlobalCEFApp.EnableGPU := True;
|
||||
GlobalCEFApp.LogFile := 'debug.log';
|
||||
GlobalCEFApp.LogSeverity := LOGSEVERITY_INFO;
|
||||
GlobalCEFApp := TCefApplication.Create;
|
||||
GlobalCEFApp.cache := 'cache';
|
||||
GlobalCEFApp.EnablePrintPreview := True;
|
||||
GlobalCEFApp.EnableGPU := True;
|
||||
GlobalCEFApp.LogFile := 'debug.log';
|
||||
GlobalCEFApp.LogSeverity := LOGSEVERITY_INFO;
|
||||
GlobalCEFApp.UncaughtExceptionStackSize := 50;
|
||||
GlobalCEFApp.OnUncaughtException := GlobalCEFApp_OnUncaughtException;
|
||||
//GlobalCEFApp.ChromeRuntime := True;
|
||||
end;
|
||||
|
||||
@ -525,6 +505,17 @@ begin
|
||||
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;
|
||||
const browser: ICefBrowser; const frame: ICefFrame;
|
||||
const params: ICefContextMenuParams; commandId: Integer;
|
||||
|
@ -17,9 +17,7 @@ object PreferencesFrm: TPreferencesFrm
|
||||
Padding.Top = 10
|
||||
Padding.Right = 10
|
||||
Padding.Bottom = 10
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
object GroupBox1: TGroupBox
|
||||
Left = 10
|
||||
@ -29,6 +27,7 @@ object PreferencesFrm: TPreferencesFrm
|
||||
Align = alTop
|
||||
Caption = ' Proxy '
|
||||
TabOrder = 0
|
||||
ExplicitWidth = 404
|
||||
object ProxyTypeLbl: TLabel
|
||||
Left = 12
|
||||
Top = 27
|
||||
@ -180,6 +179,7 @@ object PreferencesFrm: TPreferencesFrm
|
||||
Align = alTop
|
||||
Caption = ' Custom header '
|
||||
TabOrder = 1
|
||||
ExplicitWidth = 404
|
||||
object HeaderNameLbl: TLabel
|
||||
Left = 12
|
||||
Top = 26
|
||||
@ -219,7 +219,8 @@ object PreferencesFrm: TPreferencesFrm
|
||||
Padding.Left = 30
|
||||
Padding.Right = 30
|
||||
TabOrder = 2
|
||||
ExplicitTop = 373
|
||||
ExplicitTop = 352
|
||||
ExplicitWidth = 404
|
||||
object Button1: TButton
|
||||
Left = 30
|
||||
Top = 0
|
||||
@ -239,7 +240,7 @@ object PreferencesFrm: TPreferencesFrm
|
||||
Caption = 'Cancel'
|
||||
ModalResult = 2
|
||||
TabOrder = 1
|
||||
ExplicitLeft = 278
|
||||
ExplicitLeft = 254
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -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;
|
||||
|
||||
{$I cef.inc}
|
||||
|
@ -2,7 +2,7 @@
|
||||
"UpdateLazPackages" : [
|
||||
{
|
||||
"ForceNotify" : true,
|
||||
"InternalVersion" : 518,
|
||||
"InternalVersion" : 519,
|
||||
"Name" : "cef4delphi_lazarus.lpk",
|
||||
"Version" : "117.1.4"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user