'Fetching images from the CefBrowser - How many and what is their order?

I'm using the CefSharp browser to grab images off of an Html page and convert them to System.Drawing.Bitmaps. To do so, I've implemented a BrowserRequestHandler and ImageResourceRequestHandler. The ImageResourceRequestHandler.OnResourceLoadComplete() publishes an event which pushes the web page images to my Winforms app. This works very well, but I'm missing 2 pieces of information about the images.

First, the Winforms app doesn't know when it has received the all the images for the page. LoadingStateChanged.IsLoading transitions to false well before all images have been pushed. Is there any way to know when the last image resource has been pushed?

Second, the Winforms app gets the images in a random order. I'd like to know what their position is in document order (e.g. 'image 3, image 4, image 1 ...', regardless of the order in which they are received). Is there any way to fetch this info?



Solution 1:[1]

Take a look to my response in this question: https://stackoverflow.com/a/72011902/18452174

Once you can comunicate from JavaScript to your C# application, you can do that:

  • In JavaScript, search in the DOM all img tags and get the src attribute.
  • Put all Urls in an array.
  • Send that array (JSON encoded) to your C# application.
  • In your C# application decode the JSON and get al Urls (in order).
  • Download with WebRequest, for example

If you want optimize a bit the process, you can use the OffScreen browser and/or configure it to not download images (you are going to download from C#)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Victor