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.

Trouble triggering OnWebResourceResponseReceived in WebView4Delphi's PopupBrowser Demo?

Post Reply
dgs
Posts: 7
Joined: Tue May 21, 2024 4:59 am

Trouble triggering OnWebResourceResponseReceived in WebView4Delphi's PopupBrowser Demo?

Post by dgs »

I'm trying to use the PopupBrowser Demo of WebView4Delphi. In the `OnNewWindowRequested` event of `mainform.WVBrower1`, I'm listening and creating a new child window:

Code: Select all

procedure TMainForm.WVBrowser1NewWindowRequested(Sender: TObject;
  const aWebView: ICoreWebView2;
  const aArgs: ICoreWebView2NewWindowRequestedEventArgs);
var
  TempChildForm: TChildForm;
begin
  TempChildForm := TChildForm.Create(self, aArgs);
  TempChildForm.Show;
end;

And I want to listen to data in `ChildForm.WVBrower1's OnWebResourceResponseReceived`, so I added a listening filter in `ChildForm.WVBrower1`. The code is as follows:

Code: Select all

procedure TChildForm.WVBrowser1AfterCreated(Sender: TObject);
begin
  if assigned(FArgs) and assigned(FDeferral) then
    try
      FArgs.NewWindow := WVBrowser1.CoreWebView2.BaseIntf;
      FArgs.Handled   := True;
      FDeferral.Complete;
    finally
      FreeAndNil(FDeferral);
      FreeAndNil(FArgs);
    end;

// Added code
  WVBrowser1.AddWebResourceRequestedFilterWithRequestSourceKinds('*',
    COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL,
    COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_ALL);

  WVWindowParent1.UpdateSize;
end;
However, in `ChildForm.WVBrowser1's OnWebResourceRequested`, I can listen to data, but the `OnWebResourceResponseReceived` event cannot be triggered. However, if I change the code as follows, I can trigger the listening. But this only works with the GET method. It doesn't work with the payload-carrying POST method. Because I don't know what the access parameters of the new window are.

Code: Select all

procedure TChildForm.WVBrowser1AfterCreated(Sender: TObject);
begin
  if assigned(FArgs) and assigned(FDeferral) then
    try
      FArgs.NewWindow := nil;  // Modification here
      FArgs.Handled   := True;
      FDeferral.Complete;
      
      WVBrowser1.Navigate(EncodeURL(FArgs.URI)); // Directly re-access

    finally
      FreeAndNil(FDeferral);
      FreeAndNil(FArgs);
    end;

// Added code
  WVBrowser1.AddWebResourceRequestedFilterWithRequestSourceKinds('*',
    COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL,
    COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_ALL);

  WVWindowParent1.UpdateSize;
end;
I appreciate any help. Thank you!
User avatar
salvadordf
Posts: 4155
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Trouble triggering OnWebResourceResponseReceived in WebView4Delphi's PopupBrowser Demo?

Post by salvadordf »

Hi,

I can reproduce this issue in my computer but I'm afraid this is a WebView2 feature.

Other developers also requested that event for frames :
https://github.com/MicrosoftEdge/WebView2Feedback/issues/4529
dgs
Posts: 7
Joined: Tue May 21, 2024 4:59 am

Re: Trouble triggering OnWebResourceResponseReceived in WebView4Delphi's PopupBrowser Demo?

Post by dgs »

Thank you very much! Does cef have a similar issue?
User avatar
salvadordf
Posts: 4155
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Trouble triggering OnWebResourceResponseReceived in WebView4Delphi's PopupBrowser Demo?

Post by salvadordf »

I'm not aware of any issue getting the resource responses in CEF.

Try the NetworkTrackerBrowser or ResponseFilterBrowser demos.
dgs
Posts: 7
Joined: Tue May 21, 2024 4:59 am

Re: Trouble triggering OnWebResourceResponseReceived in WebView4Delphi's PopupBrowser Demo?

Post by dgs »

Thanks, I have gone to cef4delphi but I am browsing video sites when I get "H5 player not supported by browsing" error, thus not being able to play streaming videos, how can I fix it?
User avatar
salvadordf
Posts: 4155
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Trouble triggering OnWebResourceResponseReceived in WebView4Delphi's PopupBrowser Demo?

Post by salvadordf »

The CEF binaries only include open source videos and audio codecs.

You can build them yourself with proprietary codecs support following this guide :
https://www.briskbard.com/forum/viewtopic.php?t=1097
dgs
Posts: 7
Joined: Tue May 21, 2024 4:59 am

Re: Trouble triggering OnWebResourceResponseReceived in WebView4Delphi's PopupBrowser Demo?

Post by dgs »

Thank you very much!
Post Reply