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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

How to edit source HTML code before render

Student
Posts: 73
Joined: Tue Aug 07, 2018 9:20 am

Re: How to edit source HTML code before render

Post by Student »

Thanks Salvador, I'm still experimenting myself and will wait for your demo.
In dcef3 i used solve, if in short

Code: Select all

type
  TWebInterceptHandler = class(TCefResourceHandlerOwn)
  private
    FDataStream: TMemoryStream;
    FResponseHeadersReadyCallback: ICefCallback;
    FOffsetRead: NativeUInt;
    FResponse: ICefResponse;
  protected
    function ProcessRequest(const Request: ICefRequest;
      const Callback: ICefCallback): Boolean; override;
    procedure GetResponseHeaders(const Response: ICefResponse;
      out ResponseLength: Int64; out RedirectUrl: ustring); override;
    function ReadResponse(const DataOut: Pointer; BytesToRead: Integer;
      var BytesRead: Integer; const Callback: ICefCallback): Boolean; override;
  public
    constructor Create(const Browser: ICefBrowser; const Frame: ICefFrame;
      const SchemeName: ustring; const Request: ICefRequest); override;
    destructor Destroy; override;
  end;
  
  type
  TWebInterceptHandlerClient = class(TCefUrlRequestClientOwn)
  private
    FResourceHandler: TWebInterceptHandler;
  protected
    procedure OnDownloadData(const Request: ICefUrlRequest; Data: Pointer;
      DataLength: NativeUInt); override;
    procedure OnRequestComplete(const Request: ICefUrlRequest); override;
  end;
  
 procedure TWebInterceptHandlerClient.OnDownloadData(const Request
  : ICefUrlRequest;  Data: Pointer; DataLength: NativeUInt);
begin
  inherited;
    if (Request.GetRequest.ResourceType = RT_IMAGE) then
    begin
      if Request.GetRequest.Url='http://site.com/1.gif' then
      FDataStream.LoadFromFile(pathtofile + '1.gif') else
      FDataStream.Write(Data^, DataLength);
    end else
      FDataStream.Write(Data^, DataLength);
end; 
Work nice, and now translate project on a new chromium using your component and this way to leads to hang render processes.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to edit source HTML code before render

Post by salvadordf »

The modified ResponseFilterBrowser demo is already available at https://github.com/salvadordf/CEF4Delphi

Please, download CEF4Delphi again.

CEF4Delphi doesn't have any demo that uses TCefUrlRequestClientOwn and right now I'm very busy to create one.
Please, modify ResponseFilterBrowser to your needs according to the comments in my previous post.
Student
Posts: 73
Joined: Tue Aug 07, 2018 9:20 am

Re: How to edit source HTML code before render

Post by Student »

Nice work Salvador! I long thinking about how to optimize your code for yourself, solve in Chromium1GetResourceResponseFilter to specify the my resource in FStream, FRscSize := FStream.Size; after in Filter_OnFilter

Code: Select all

		if (data_out <> nil) then
                begin
                  data_out_written := min(data_in_size, data_out_size);
                  if FStream.Position<FRscSize then
                  FStream.ReadData(data_out,data_out_written);
                end;

                if not(FRscCompleted) and (FRscSize <> -1) and (FRscSize = FStream.Position) then
                  begin
                    FRscCompleted := PostMessage(Handle, STREAM_COPY_COMPLETE, 0, 0);
                    aResult       := RESPONSE_FILTER_DONE;
                  end
                 else
                  aResult := RESPONSE_FILTER_NEED_MORE_DATA;
Thanks retry for your help.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to edit source HTML code before render

Post by salvadordf »

Thanks for your code!!! :D

I'll take a deeper look as soon as I can and add it to the demo.
Student
Posts: 73
Joined: Tue Aug 07, 2018 9:20 am

Re: How to edit source HTML code before render

Post by Student »

Oh sorry, I hurried) after replacing the pictures, through some time all page becomes white.
Either I did wrong, or the resources in this place cannot be replaced.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to edit source HTML code before render

Post by salvadordf »

Use a custom HTTP header to download the resources ignoring the cache. The filter only works if your app downloads the resources, not if it reads them from cache.

Use TChromium.CustomHeaderName and TChromium.CustomHeaderValue like this :

Code: Select all

    chromium1.CustomHeaderName := 'Cache-Control';
    chromium1.CustomHeaderValue := 'no-cache';
Student
Posts: 73
Joined: Tue Aug 07, 2018 9:20 am

Re: How to edit source HTML code before render

Post by Student »

Recorded the effect, I changed the logo on your website.
Image
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to edit source HTML code before render

Post by salvadordf »

The render process may have crashed.

Read the 'Debugging' section in :
https://www.briskbard.com/index.php?lang=en&pageid=cef
Student
Posts: 73
Joined: Tue Aug 07, 2018 9:20 am

Re: How to edit source HTML code before render

Post by Student »

Disable cache and add this code in formcreate, nothing has changed.

Code: Select all

 chromium1.CustomHeaderName := 'Cache-Control';
 chromium1.CustomHeaderValue := 'no-cache';
Student
Posts: 73
Joined: Tue Aug 07, 2018 9:20 am

Re: How to edit source HTML code before render

Post by Student »

In debug.log writed
[0808/131537.947:ERROR:url_request_context_getter_impl.cc(129)] Cannot use V8 Proxy resolver in single process mode.
[0808/131538.514:WARNING:histograms.cc(40)] Started multiple compositor clients (Browser, Renderer) in one process. Some metrics will be disabled.
[0808/131539.095:WARNING:angle_platform_impl.cc(59)] compileToBinary(228):
C:\fakepath(46,8-58): warning X3571: pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them
C:\fakepath(54,9-43): warning X3571: pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them

[0808/131539.116:WARNING:angle_platform_impl.cc(59)] compileToBinary(228):
C:\fakepath(29,8-58): warning X3571: pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them
C:\fakepath(37,9-43): warning X3571: pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them

[0808/131541.440:WARNING:angle_platform_impl.cc(59)] compileToBinary(228):
C:\fakepath(46,8-58): warning X3571: pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them
C:\fakepath(54,9-43): warning X3571: pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them

[0808/131541.504:WARNING:angle_platform_impl.cc(59)] compileToBinary(228):
C:\fakepath(65,10-42): warning X3571: pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them
C:\fakepath(87,10-42): warning X3571: pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them
Under debugging stop on
Image
Image
URL on screenshots
http://pixs.ru/showimage/err1jpg_9212251_30637548.jpg
http://pixs.ru/showimage/err2jpg_6396805_30637549.jpg
Post Reply