Giter VIP home page Giter VIP logo

Comments (7)

salvadordf avatar salvadordf commented on May 28, 2024

Hi,

I just tested the JSExtension demo with Lazarus 3.2 in Windows 10 (64 bits) and I can't reproduce this issue. I built the demo in 64 bits and I used "Dwarf 2 with sets".
I set a breakpoint here

The same demo also works fine in Delphi with a breakpoint in the same place.

That event is executed in a CEF thread and it shouldn't have any code that modifies Windows controls. However, I added a status bar update because it doesn't create or destroy controls.
Some demos break that rule to make the demos easier to understand but it's not recommended to modify controls outside the main application thread.

from cef4delphi.

salvadordf avatar salvadordf commented on May 28, 2024

In general, it's better if the code in the CEF events is as simple as possible to avoid blocking any CEF thread.
Blocking the main application thread is not recommended either.

from cef4delphi.

sxmxta avatar sxmxta commented on May 28, 2024

Okay, I'll send you an example of the key parts of this code


CEF4Delphi 118.7.1

demo: JSExtension

TMyThread = class(TThread)
protected
  procedure Execute; override;
end;

procedure TMyThread.Execute;
var
  i: integer;
begin
 // *Note: Debug and set breakpoints here
  for i := 0 to 100 do 
  begin
    Sleep(20); // Simulate time-consuming operations within threads
  end;
end;
procedure TJSExtensionFrm.Chromium1ProcessMessageReceived(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
  sourceProcess: TCefProcessId; const message: ICefProcessMessage; out Result: boolean);
var
  Thread1: TMyThread;
begin
  Result := False;

  if (message = nil) or (message.ArgumentList = nil) then exit;

  // This function receives the messages with the JavaScript results

  // Many of these events are received in different threads and the VCL
  // doesn't like to create and destroy components in different threads.

  // It's safer to store the results and send a message to the main thread to show them.

  // The message names are defined in the extension or in JS code.

  // For convenience, create a thread directly and start it
  Thread1 := TMyThread.Create(True
  Thread1.FreeOnTerminate := True;
  Thread1.Start;
  if (message.Name = MOUSEOVER_MESSAGE_NAME) then
  begin
    StatusPnl.Caption := message.ArgumentList.GetString(0); // this doesn't create/destroy components
    Result := True;
  end
  else
  if (message.Name = CUSTOMNAME_MESSAGE_NAME) then
  begin
    FText := message.ArgumentList.GetString(0);
    PostMessage(Handle, MINIBROWSER_SHOWTEXTVIEWER, 0, 0);
    Result := True;
  end;
end;

from cef4delphi.

sxmxta avatar sxmxta commented on May 28, 2024

My Lazarus environment is the same as yours

You may need to test this process multiple times, repeating F8 or F9 within the thread
This result may be freezing Lazarus 3.2 IDE or the entire desktop explorer

11111

22222

333333

from cef4delphi.

sxmxta avatar sxmxta commented on May 28, 2024

This problem cannot be reproduced just by debugging a few times.

This problem doesn't recur every time, it may require repeated shutdown, startup, and debugging

from cef4delphi.

salvadordf avatar salvadordf commented on May 28, 2024

I'm sorry but I added exactly the same code and I also put the same breakpoints but I still cannot reproduce this issue.
The IDE stopped in those breakpoints more than 50 times and I clicked F9 each time to keep executing the demo.
I used the latest CEF4Delphi version 123.0.13.

Instead of breakpoints try enabling the debug log and call CefDebugLog with the debug information you need. That function is available in uCEFMiscFunctions.

from cef4delphi.

sxmxta avatar sxmxta commented on May 28, 2024

Alright, thank you.

The issue does not necessarily reproduce 100% of the time on my computer. However, it does indeed exist. It only occurs when breakpoints are set during the debugging process, leading to the entire IDE becoming unresponsive until it is automatically closed. I've asked around, and it's said that it's likely caused by breakpoints during the debugging process, resulting in a soft interrupt.

from cef4delphi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.