GetResourceHandler not called

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.

GetResourceHandler not called

Postby rado » Thu Sep 15, 2022 4:45 am

I've got one page where CefRequestHandler::GetResourceHandler() is not called.
First I navigate to main URL, then I invoke POST request, and CefRequestHandler::GetResourceHandler() is invoked.
But when I authorize to the site (just html login form) before sending the POST request, then CefRequestHandler::GetResourceHandler() is NOT invoked.
I've checked the request in the fiddler - the only difference is presence of the session cookie when I'm authorized (and in devtools in my app in latter case network almost no headers are shown with provisional headers warning).
I've tried to simplify the POST request by removing post data and headers, without success.
I can reproduce it also in the cefclient application. I've tried using build cef_binary_105.3.38+g2a6a54b+chromium-105.0.5195.102_windows32, but also 104 and 100.
I guess it is some bug, or maybe am I missing something? Are there some known situations when GetResourceHandler() is not invoked?
rado
Expert
 
Posts: 145
Joined: Wed Oct 05, 2011 3:32 am

Re: GetResourceHandler not called

Postby magreenblatt » Thu Sep 15, 2022 8:32 am

GetResourceHandler will not be called in some cases, like for cached responses or CORS preflight requests. Can you provide a netlog dump for your case?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: GetResourceHandler not called

Postby rado » Thu Sep 15, 2022 10:41 am

I've sent PM, thank you!
rado
Expert
 
Posts: 145
Joined: Wed Oct 05, 2011 3:32 am

Re: GetResourceHandler not called

Postby magreenblatt » Thu Sep 15, 2022 10:56 am

How is this request being sent? It has "Content-Type: application/json" which would be unusual for a form submission. Are you using XMLHttpRequest or fetch API? Is it originating from the browser directly or from a service worker?

You also appear to be using a proxy server. Does it make a difference if you don't use a proxy server?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: GetResourceHandler not called

Postby rado » Thu Sep 15, 2022 11:13 am

Yes it is not form submission, it is API request. This is part of the code for sending the request:

Code: Select all
CefRefPtr<CefRequest> request = CefRequest::Create();
request->SetMethod(L"POST");
request->SetURL(L"https://.......");
request->SetFlags(UR_FLAG_ALLOW_STORED_CREDENTIALS);
browser->GetMainFrame()->LoadRequest(request);


I've omitted parts adding the headers (with content type) and post body, but even when I remove that code (resulting sending the incorrect request) result from the server is error message, but GetResourceHandler is not called anyway.
I need the proxy, because the site has geo restriction, I'll try to set it as default system proxy, not proxy passed by command line argument and will let you know.
rado
Expert
 
Posts: 145
Joined: Wed Oct 05, 2011 3:32 am

Re: GetResourceHandler not called

Postby rado » Thu Sep 15, 2022 12:09 pm

I've used VPN, but it does not make difference.
rado
Expert
 
Posts: 145
Joined: Wed Oct 05, 2011 3:32 am

Re: GetResourceHandler not called

Postby magreenblatt » Thu Sep 15, 2022 1:24 pm

Yes it is not form submission, it is API request. This is part of the code for sending the request:

CODE: SELECT ALL
CefRefPtr<CefRequest> request = CefRequest::Create();
request->SetMethod(L"POST");
request->SetURL(L"https://.......");
request->SetFlags(UR_FLAG_ALLOW_STORED_CREDENTIALS);
browser->GetMainFrame()->LoadRequest(request);

Please explain the reasoning behind this code. You are using LoadRequest to load, in the main frame, a resource that returns JSON?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: GetResourceHandler not called

Postby rado » Thu Sep 15, 2022 4:00 pm

That's the point why I do need the GetResourceHandler(). For some content types (json in this case) It returns my CefResourceHandler implementation which recreates new request instead of original and sends it using the CefURLRequest::Create().
The returned data is converted do HTML (for example converting json into html table) and returned to cef main frame with content type text/html as response to original request so it looks like server returned html.
I know in this case I could skip this step with frame->LoadRequest + CefResourceHandler with converter but sometimes the request to server can be caused also by form submission or javascript code so I have it at one place.
For this particular site I'll use some workaround so as long as it won't be happening on more and more sites I can live with that
rado
Expert
 
Posts: 145
Joined: Wed Oct 05, 2011 3:32 am


Return to Support Forum

Who is online

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