How to handle failed downloads

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

How to handle failed downloads

Postby michaelb » Thu May 20, 2021 7:48 am

We are having failed image downloads sporadically very rarely from CEF, although not from the browser, from an aws url that works all the time from the browser. We are thinking the issue is that upon failed download, CEF does not reattempt to download the images and thus for the duration of the browser the images don't display.
Using CefDownloadHandler OnDownloadUpdated, and looking at the CefDownloadItem API, how do I know if the download failed? Or does this callback never get called? I would want to retrigger a download to that browser element upon a failed download attempt, to always try to redownload in case of sporadic failure. I see IsCancelled, IsInProgress, IsComplete, and IsValid, but which one of them let me know that it's a failed download (404? I assume), and is this whole attempt to redownload in case of failure a valid paradigm for embedded browser images which would then display in case of redownload?
michaelb
Techie
 
Posts: 21
Joined: Thu May 20, 2021 7:38 am

Re: How to handle failed downloads

Postby magreenblatt » Thu May 20, 2021 9:26 am

How are you downloading the images? Are you using different code in CEF and “browser” (whatever that is?). Have you checked the DevTools Network tab or server logs for related errors?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: How to handle failed downloads

Postby michaelb » Sun May 23, 2021 3:16 am

The images are being downloaded using a 3rd party javascript file (https://app.singular.live/libs/singular ... rplayer.js)
I looked into using ResourceRequestHandler OnResourceResponse, but not sure if this is the correct approach yet. The other browser is regular Google Chrome. The logs from our server just say failed to download image, and there are no other related errors. I am not aware yet of any other low level consoles to debug the actual CEF application, if there is a way to do this (in live) please direct me to that as well.
michaelb
Techie
 
Posts: 21
Joined: Thu May 20, 2021 7:38 am

Re: How to handle failed downloads

Postby michaelb » Sun May 23, 2021 4:19 am

The ResourceRequestHandler OnResourceResponse method does not seem to be hit, according to my logs, so I am not sure which handler to use to handle the downloads of images in the browser.
michaelb
Techie
 
Posts: 21
Joined: Thu May 20, 2021 7:38 am

Re: How to handle failed downloads

Postby magreenblatt » Sun May 23, 2021 2:01 pm

If an image is failing to load you should see that in the DevTools Network tab. You can also use chrome://net-internals to log and debug network connections.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: How to handle failed downloads

Postby michaelb » Mon May 24, 2021 3:03 am

The image does not fail to load using google chrome, just in our CEF application. Is there a way to hook up dev tools to our specific cef application (it's a headless browser)? I am aware of how to use in google chrome in general.
michaelb
Techie
 
Posts: 21
Joined: Thu May 20, 2021 7:38 am

Re: How to handle failed downloads

Postby ndesktop » Mon May 24, 2021 3:26 am

CefDownloadItem::IsCanceled states in documentation "Returns true if the download has been canceled or interrupted."
CefDownloadItem::IsCanceled|InProgress|Complete simply follows the download::DownloadItem possible states.

I would say there is a missing method from CefDownloadItem, IsInterrupted, which will simply be
Code: Select all
bool CefDownloadItemImpl::IsInterrupted() {
  CEF_VALUE_VERIFY_RETURN(false, false);
  return const_value().GetState() == download::DownloadItem::INTERRUPTED;
}

Maybe this is the state hit by the underlying DownloadItem but not exposed via CefDownloadItem.
ndesktop
Master
 
Posts: 750
Joined: Thu Dec 03, 2015 10:10 am

Re: How to handle failed downloads

Postby michaelb » Mon May 24, 2021 3:34 am

I'm not sure it hits any of the DownloadHandler lifecycle methods. The only lifecycle method I see it hitting so far in my debugging is OnLoadEnd for the whole browser and it returns 200, and there is just a console message (info not error) that an image download failed, so it's not hitting a failed download, unless if further debugging will reveal it does. I think it is coming from some third party javascript library. I wonder if there is a way to programmatically handle the html elements using c++ cef library to refresh individual items?
michaelb
Techie
 
Posts: 21
Joined: Thu May 20, 2021 7:38 am

Re: How to handle failed downloads

Postby ndesktop » Mon May 24, 2021 4:16 am

michaelb wrote:I'm not sure it hits any of the DownloadHandler lifecycle methods. The only lifecycle method I see it hitting so far in my debugging is OnLoadEnd for the whole browser and it returns 200, and there is just a console message (info not error) that an image download failed, so it's not hitting a failed download, unless if further debugging will reveal it does. I think it is coming from some third party javascript library. I wonder if there is a way to programmatically handle the html elements using c++ cef library to refresh individual items?

Sure you can execute scripts or install V8 extensions to detect load end and image missing to check to trigger a custom script execution, but that would be something to do at application level.
As I think now, you get a 200 for the (correct) page load, and in background there are either XHRs performing image download, or simply an <img> element with a src that fails to download.
It can also be a base64 image exceeding browser limitations perhaps.

But as @magreenblatt said, checking in DevTools > Network is the way to go for diagnose.
ndesktop
Master
 
Posts: 750
Joined: Thu Dec 03, 2015 10:10 am

Re: How to handle failed downloads

Postby michaelb » Mon May 24, 2021 4:23 am

ndesktop wrote:
michaelb wrote:I'm not sure it hits any of the DownloadHandler lifecycle methods. The only lifecycle method I see it hitting so far in my debugging is OnLoadEnd for the whole browser and it returns 200, and there is just a console message (info not error) that an image download failed, so it's not hitting a failed download, unless if further debugging will reveal it does. I think it is coming from some third party javascript library. I wonder if there is a way to programmatically handle the html elements using c++ cef library to refresh individual items?

Sure you can execute scripts or install V8 extensions to detect load end and image missing to check to trigger a custom script execution, but that would be something to do at application level.
As I think now, you get a 200 for the (correct) page load, and in background there are either XHRs performing image download, or simply an <img> element with a src that fails to download.
It can also be a base64 image exceeding browser limitations perhaps.

But as @magreenblatt said, checking in DevTools > Network is the way to go for diagnose.


Yes, it is probably some XHR or img element. Which lifecycle methods would handle that in the C++ api? ResourceRequestHandler onResourceReponse didn't seem to catch it. And in our specific case, not sure how I would use DevTools since it is a headless browser, but I can look into it. I think we also have the output at a localhost port but not sure.
Also it is not a consistent error - it only happens on certain machines randomly. So it's probably not because of the base64 image. Might it be some sporadic caching issue with CEF?
michaelb
Techie
 
Posts: 21
Joined: Thu May 20, 2021 7:38 am

Next

Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 34 guests