Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

Migrating from DCEF3, trying again

thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Migrating from DCEF3, trying again

Post by thefunkyjoint »

Hi,

Some weeks ago i tried to migrate my current apps from DCEF3 to CEF4. I managed a test app to work, but i faced some issues and then sticked with DCEF3 until now.

But now i need to migrate ASAP because the main website my apps use are displaying old browser warnings...

So i download the current master branch from github and the DLLS. I'm just trying to make a simple application with TChromiumWindow work by navigating to google.com, but somehow it's not working....

What is happening : I open my app inside Delphi 2007. It will compile and run without errors. But when i try to navigate to any page in TChromiumWindow, the IDE shows a breakpoint in the 'CPU' window. I click on F9 again, my app shows up , but no site is loaded, just a blank page.

I think i'm missing something here... Please help me.

Thanks in advance !

Code: Select all

program chrome;

uses
  Forms,
  uCEFApplication in '..\extras\cef4\source\uCEFApplication.pas',
  princ in 'princ.pas' {Form1};

{$R *.res}

begin
  GlobalCEFApp := TCefApplication.Create;
    if GlobalCEFApp.StartMainProcess then
    begin
    Application.Initialize;
    Application.MainFormOnTaskbar := True;
    Application.CreateForm(TForm1, Form1);
    Application.Run;
    end;
    GlobalCEFApp.Free;
end.
And here is my test app code :

Code: Select all

unit princ;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, uCEFChromium, uCEFWindowParent, ExtCtrls, uCEFChromiumWindow;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Edit1: TEdit;
    Button1: TButton;
    Panel2: TPanel;
    web: TChromiumWindow;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
web.LoadURL(edit1.text);
end;



end.
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Re: Migrating from DCEF3, trying again

Post by thefunkyjoint »

An update about this issue :

Instead of using TChromiumWindow, i edited the code to use an instance of TChromium and one TCEFWindowParent. On FormCreate, i did :

web.CreateBrowser(CEFWindowParent1);

I also set GlobalCEFAPP.SingleProcess to true.

In this way the loadURL worked, but when i close my app, Delphi stills stops on the 'CPU' tab.

Without setting GlobalCEFAPP.SingleProcess to true it won't even navigate. Any hints ?
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Migrating from DCEF3, trying again

Post by salvadordf »

Hi,

Use the demos as a base for your application. If you finally use TChromium and one TCEFWindowParent then take a look at the MiniBrowser demo.

The DPR file is missing a couple of things :
  • Add Windows to the uses section.
  • Add {$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE} just before the "begin".
In the PAS file of the form where you want to add the browser you have to :
  • Use the TChromium.OnAfterCreated to know when the browser is fully initialized and ready for commands. This event is received in the context of another thread so it's safer to send a message to the main form like the MiniBrowser do. In fact, all the TChromium events are executed in the context of another threads or processes so use mutexes or critical sections when necessary.
  • Don't use the SingleProcess mode unless you need to debug some code that normally it's executed in a different process. It's an unsupported mode.
  • You need to add the functions for the WM_MOVE and WM_MOVING messages to call TChromium.NotifyMoveOrResizeStarted in them.
  • Call TCEFWindowParent.UpdateSize before loading the firs web page.
There are more information in this web page :
https://www.briskbard.com/index.php?lang=en&pageid=cef
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Re: Migrating from DCEF3, trying again

Post by thefunkyjoint »

Hello,

Thanks for answering.
Add Windows to the uses section.
Add {$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE} just before the "begin".
Done.
Don't use the SingleProcess mode unless you need to debug some code that normally it's executed in a different process. It's an unsupported mode.
Only with SingleProcess it's working in my case... Without it's stopping on the 'CPU' tab on my IDE...

What is better, to use TChromiumWindow or to use TChromium and TCEFWindowParent ? Is there any difference in terms of stability or performance ?

I'm doing further tests and will keep the thread updated.

Thank you very much for this awesome work ! :)
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Re: Migrating from DCEF3, trying again

Post by thefunkyjoint »

Hi,

I did all changes you suggested. Here are some updates :

- All my apps uses a 'windowstate := wsmaximized' command on FormCreate, to start the main form maximized ; this is not working anymore after i'm using FormCreate also to create TChromium and TCEFWindowParent in runtime.

- Everytime i close my app, the IDE will stop on 'CPU' tab. Then i click F9 a couple of times and it will go back to my code, as it should be. Sometimes however the IDE raises an Access violation, and i have to close and reopen the IDE. After debugging, i found out this is the line who trigger the 'CPU' tab breakpoint : 'GlobalCEFApp.Free;' . Is there any way to avoid the IDE stop on this 'CPU' tab ?

- So far only SingleProcess := true is working, i'm still trying to find why.

Thanks
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Migrating from DCEF3, trying again

Post by salvadordf »

Hi,

There is no performance/stability difference between the TChromiumWindow and the TChromium/TCEFWindowParent combination. In fact, TChromiumWindow is just a TCEFWindowParent with a TChromium child.

I just created TChromiumWindow to add a web browser a little bit more easily.

Several demos use TChromium and TCEFWindowParent. If the MiniBrowser demo has too many extras, then take the FullScreenBrowser demo and delete the following procedures and events :
  • Chromium1PreKeyEvent
  • Chromium1KeyEvent
  • HandleKeyUp
  • HandleKeyDown
You will also need to set the FormStyle, BorderIcons and BorderStyle to the default values.
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Re: Migrating from DCEF3, trying again

Post by thefunkyjoint »

Some updates about the migrating process from DCEF3 :

- I noticed now the browser makes the app steal the focus when finishing loading, in certain websites. Is there a way to prevent this behaviour ?

- Also noticed that when i use this code :
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
Some how it causes problem with functions of the FastStrings unit. Can you tell me exactly what this SetPEFlags do ?

Thank you !
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Migrating from DCEF3, trying again

Post by salvadordf »

Hi,
thefunkyjoint wrote: Thu Oct 05, 2017 1:12 pm Some updates about the migrating process from DCEF3 :
- I noticed now the browser makes the app steal the focus when finishing loading, in certain websites. Is there a way to prevent this behaviour ?
That's a known CEF3 issue:
http://magpcss.org/ceforum/viewtopic.php?f=6&t=12205
https://bitbucket.org/chromiumembedded/cef/issues/1856

You can try to use the TChromium.OnSetFocus event and set Result to True.
thefunkyjoint wrote: Thu Oct 05, 2017 1:12 pm - Also noticed that when i use this code :
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
Some how it causes problem with functions of the FastStrings unit. Can you tell me exactly what this SetPEFlags do ?
That flag allows 32-bit processes to use up to 3GB of RAM. You need it in case you show large images or the render process will crash.
https://github.com/salvadordf/CEF4Delphi/issues/23
https://bitbucket.org/chromiumembedded/ ... -to-binary
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Re: Migrating from DCEF3, trying again

Post by thefunkyjoint »

Another issue i found :

If i call my app EXE inside its directory, it will work ; the framework files are in this same dir.

BUT

If i call my app EXE from OUTSIDE its directory, it won't work showing the error : 'CEF resources missing!'.

The CEF resources are in the same directory as the EXE file. But it if for instance i call my EXE in command prompt, like this :

c:\myapp\myapp.exe

It won't work.

How can i fix this ? Is there any GlobalCEFAPP parameter i should set ? Already tried GlobalCEFApp.FrameworkDirPath, but no change.

Thanks !
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Re: Migrating from DCEF3, trying again

Post by thefunkyjoint »

thefunkyjoint wrote: Thu Oct 05, 2017 6:09 pm Another issue i found :

If i call my app EXE inside its directory, it will work ; the framework files are in this same dir.

BUT

If i call my app EXE from OUTSIDE its directory, it won't work showing the error : 'CEF resources missing!'.

The CEF resources are in the same directory as the EXE file. But it if for instance i call my EXE in command prompt, like this :

c:\myapp\myapp.exe

It won't work.

How can i fix this ? Is there any GlobalCEFAPP parameter i should set ? Already tried GlobalCEFApp.FrameworkDirPath, but no change.

Thanks !
I could fix this by calling Delphi's 'chdir' command before the GlobalCEFApp creation... any other suggestions ?
Post Reply