salvadordf / WebView4Delphi

WebView4Delphi is an open source project created by Salvador Díaz Fau to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC for Windows.
https://www.briskbard.com/forum/
MIT License
280 stars 56 forks source link

How to get the url in iframe? #54

Closed mytvdat closed 5 months ago

mytvdat commented 5 months ago

code: WVBrowser1.AddWebResourceRequestedFilterWithRequestSourceKinds('', COREWEBVIEW2_WEB_RESOURCE_CONTEXT_IMAGE, COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_ALL); WVBrowser1.AddWebResourceRequestedFilterWithRequestSourceKinds('', COREWEBVIEW2_WEB_RESOURCE_CONTEXT_MEDIA, COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_ALL); but WebResourceRequested event can not get the url if this url open in iframe,why?

salvadordf commented 5 months ago

COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_ALL includes COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_DOCUMENT and the WebView2 documentation states that it should include requests from the main page including dedicated workers and iframes.

I would try this to see if the URL is filtered : WVBrowser1.AddWebResourceRequestedFilterWithRequestSourceKinds('*', COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL, COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_ALL);

If the browser doesn't filter the URL you need with the last code I would report this to the WebView2 project : https://github.com/MicrosoftEdge/WebView2Feedback/issues

salvadordf commented 5 months ago

I forgot the asterisk in the AddWebResourceRequestedFilterWithRequestSourceKinds call. You can test this in the MiniBrowser demo.

mytvdat commented 5 months ago

COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_ALL includes COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_DOCUMENT and the WebView2 documentation states that it should include requests from the main page including dedicated workers and iframes.

I would try this to see if the URL is filtered : WVBrowser1.AddWebResourceRequestedFilterWithRequestSourceKinds('*', COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL, COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_ALL);

If the browser doesn't filter the URL you need with the last code I would report this to the WebView2 project : https://github.com/MicrosoftEdge/WebView2Feedback/issues

WebResourceRequested event can not get the url if this url open in an iframe. try Network.Enable and Network.requestWillBeSent, can't get the url too. uses CEF4delphi,Can it get all links in iFrame?

salvadordf commented 5 months ago

Unless there's a WebView2 issue, the previous code should work. If not, please create an issue in the WebView2Feedback repository because this seems to be an upstream issue.

Please, use our forum for more questions.