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.

Get all links

Vaytl
Posts: 22
Joined: Tue Jan 04, 2022 12:52 pm

Get all links

Post by Vaytl »

Hi, Salvadordf.
Can you please tell me how can I get a list of all the loaded links on a web page?
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Get all links

Post by salvadordf »

Hi,

Use the code in the MiniBrowser demo.

Modify the TMiniBrowserFrm.WVBrowser1AfterCreated procedure to filter all resources instead of images and media :

Code: Select all

WVBrowser1.AddWebResourceRequestedFilter('*', COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL);
Then modify TMiniBrowserFrm.WVBrowser1WebResourceRequested and read the URL from the request :

Code: Select all

var
  TempRequest : TCoreWebView2WebResourceRequestRef;
begin
  [...]
  TempRequest := TCoreWebView2WebResourceRequestRef.Create(TempArgs.Request);
  My_URI_copy := TempRequest.URI;
  TempRequest.Free;
end;
Vaytl
Posts: 22
Joined: Tue Jan 04, 2022 12:52 pm

Re: Get all links

Post by Vaytl »

Thank you very much, it works great.
nanaksr
Posts: 7
Joined: Wed Mar 25, 2020 6:05 am

Re: Get all links

Post by nanaksr »

This not get Links + Preflight

Image

is there a solution?
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Get all links

Post by salvadordf »

nanaksr wrote: Mon Mar 27, 2023 7:49 am This not get Links + Preflight
is there a solution?
Try using the DevTools methods.

Enable the network tracking with "Network.enable" and events like "Network.requestWillBeSent" will be delivered to the client.

Run the SubscribeToDevToolsProtocolEventBrowser demo to see how to use the DevTools methods and read this for more information :
https://chromedevtools.github.io/devtools-protocol/1-3/Network/
nanaksr
Posts: 7
Joined: Wed Mar 25, 2020 6:05 am

Re: Get all links

Post by nanaksr »

Please give me example, I am still confused.
nanaksr
Posts: 7
Joined: Wed Mar 25, 2020 6:05 am

Re: Get all links

Post by nanaksr »

nanaksr wrote: Mon Mar 27, 2023 8:19 am Please give me example, I am still confused.
I have successfully tried it.

The next problem, the link still can not be displayed. From a web link structure loaded by an Iframe from a third party.

Source : https://www.xm.com/research/economicCalendar
I want to get link : https://api.tradingcentral.com/permissions/v3/self?token=xxxxxxxxxxxxxxxxxxxxxxxxxx

I just need "token" :D
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Get all links

Post by salvadordf »

The two methods commented in this thread are he only way I know to get the a list of loaded resources in WebView2.
I'm sorry but I can't help you.
nanaksr
Posts: 7
Joined: Wed Mar 25, 2020 6:05 am

Re: Get all links

Post by nanaksr »

Thank you for the help.

Again :D , how do set active frames in DevTools? like the image below.

Image
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Get all links

Post by salvadordf »

The WebView2 API doesn't have any method or property to set the active frames in the DevTools.

Perhaps there's a DevTools method to do that but I've never done that :
https://chromedevtools.github.io/devtools-protocol/1-3/
Post Reply