LoadRequest timing issues after 76.1.13 to 80.0.8 upgrade

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.

LoadRequest timing issues after 76.1.13 to 80.0.8 upgrade

Postby shellwig » Wed Apr 08, 2020 8:16 am

Hi all,

I'm new to this forum and I know that the following question is a little bit "odd" but nevertheless I thought I might give this a try... So, I noticed the following:

LoadRequest() requires a previous LoadURL() - or a similar event - to work properly.
Since I need to perform a LoadRequest() as the first and only event, the workaround I used for this was to load a blank page using LoadURL() and then perform the LoadRequest() action.

The following (sample) code worked fine with CEF 76.1.13 and its Chromium version - every time with no problems whatsoever:

Code: Select all
         frame->LoadURL("about:blank");

         CefRefPtr<CefRequest> cefrequest(CefRequest::Create());
         
         cefrequest->SetURL(CefString(url));
         cefrequest->SetMethod("GET");
         cefrequest->SetHeaderByName("x-login-credentials", CefString(accessToken), true);
         cefrequest->SetFlags(UR_FLAG_ALLOW_STORED_CREDENTIALS);

         frame->LoadRequest(cefrequest);


When I upgraded my CEF to 80.0.8 (and its Chromium version, of course) with no other changes involved this no longer worked, at least the first LoadRequest() didn't do anything. Instead, it simply shows the blank page.
A subsequent repeat of the very same LoadRequest() seemed to work nicely as before, though.

After a while I figured out that a sleep of 500ms between LoadURL() and LoadRequest() would also make the first LoadRequest() attempt work, so I modified the code to look like this:

Code: Select all
         frame->LoadURL("about:blank");

         Sleep(500); // workaround so that this still works with CEF 80.0.8

         CefRefPtr<CefRequest> cefrequest(CefRequest::Create());
         
         cefrequest->SetURL(CefString(url));
         cefrequest->SetMethod("GET");
         cefrequest->SetHeaderByName("x-login-credentials", CefString(accessToken), true);
         cefrequest->SetFlags(UR_FLAG_ALLOW_STORED_CREDENTIALS);

         frame->LoadRequest(cefrequest);


So, in essence, this works even though this workaround is certainly not something that I would like to use (permanently).

Is there anyone who might know why this "sleep" is necessary now (is there a timing issue) or - even better - can help me with the "proper" use of a LoadRequest()?

The problem I'm trying to solve is that the LoadRequest() should be the first and only request to be processed; the LoadURL() is just there to make LoadRequest() work at all.
Since log-in credentials are supposed to be transmitted as header data I currently see no other way but using LoadRequest() - or is there another way that I don't see?

Thank you very much in advance & best regards!
shellwig
Newbie
 
Posts: 2
Joined: Wed Apr 08, 2020 7:10 am

Re: LoadRequest timing issues after 76.1.13 to 80.0.8 upgrad

Postby magreenblatt » Wed Apr 08, 2020 10:39 am

LoadURL before LoadRequest is necessary to create the renderer process. Instead of using LoadRequest you can modify the request headers in CefResourceRequestHandler::OnBeforeResourceLoad.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: LoadRequest timing issues after 76.1.13 to 80.0.8 upgrad

Postby shellwig » Mon Apr 27, 2020 4:54 am

LoadURL before LoadRequest is necessary to create the renderer process. Instead of using LoadRequest you can modify the request headers in CefResourceRequestHandler::OnBeforeResourceLoad.


Thank you so much for your prompt response and help regarding my problem! Sorry for my late reply but I was not able to refactor my code earlier to incorporate what you suggested.
The approach you mentioned works perfectly fine; I created my own Resource Request Handler that adds the required header data in its OnBeforeResourceLoad() method. Now I can use a simple LoadURL() as before while the header data is being transmitted properly, so no LoadRequest() needed anymore. Perfect!

Thanks again!
shellwig
Newbie
 
Posts: 2
Joined: Wed Apr 08, 2020 7:10 am


Return to Support Forum

Who is online

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