Trouble triggering OnWebResourceResponseReceived in WebView4Delphi's PopupBrowser Demo?
Posted: Tue May 21, 2024 5:32 am
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:
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:
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.
I appreciate any help. Thank you!
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;
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;