LoadRequest in Cef simple apllication

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

LoadRequest in Cef simple apllication

Postby chayal » Sat Oct 02, 2021 5:41 pm

Hi ,
I am new to CEF3. I want to load a simple request using loadRequest in CEF simple application.
I saw that in cef client project there is RunRequesTest API to call loadRequest but thats just dummy request.
Can you please help me with sample code as to how and where to call LoadRequest.
chayal
Techie
 
Posts: 25
Joined: Sat Oct 02, 2021 4:50 pm

Re: LoadRequest in Cef simple apllication

Postby magreenblatt » Sun Oct 03, 2021 3:00 am

You can call LoadRequest at any time after a page from the same origin has been loaded (for example, from OnLoadEnd). See https://bitbucket.org/chromiumembedded/ ... m-requests
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: LoadRequest in Cef simple apllication

Postby chayal » Sun Oct 03, 2021 3:54 am

Does it has to be called on the same frame on which LoadURL has been called.
Also is there any sample testcase for this..I know of cefsimple app. Is there any running example of loadrequest
chayal
Techie
 
Posts: 25
Joined: Sat Oct 02, 2021 4:50 pm

Re: LoadRequest in Cef simple apllication

Postby magreenblatt » Sun Oct 03, 2021 4:34 am

It can be called on any frame with the same origin. It sounds like you’ve found the examples.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: LoadRequest in Cef simple apllication

Postby chayal » Mon Oct 04, 2021 11:21 am

Hi magreenblatt
I tried to load my custom request in test_runner.cc and ran the "request" from cefclient . But no request is sent from the application. I further confirmed it using fiddler. Can you suggest me if there is anything wrong with loadrequest in CEF3.
Also is there any alternate of using loadrequest. My aim is basically to load a request which has some headers as well.
chayal
Techie
 
Posts: 25
Joined: Sat Oct 02, 2021 4:50 pm

Re: LoadRequest in Cef simple apllication

Postby magreenblatt » Mon Oct 04, 2021 12:04 pm

Show code. Where are you calling LoadRequest? What URL is loaded currently?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: LoadRequest in Cef simple apllication

Postby chayal » Tue Oct 05, 2021 6:54 am

I am trying to call loadrequest from the cefsimple application. I follow following steps:
1. Load a URL from SimpleApp::OnContextInitialized().
2. Implement OnLoadEnd inSimpleHelper.
3. call LoadRequest from OnLoadEnd()
In file SimpleHandler.cc:
I create a simple GET request in function CreateGETRequest :
CefRefPtr<CefRequest>SimpleHandler::CreateGETRequest()
{
CefRefPtr<CefRequest> request(CefRequest::Create());
request->SetURL("https://www.facebook.com");
request->SetMethod(CefString("GET"));

return request;
}

And implement OnLoadEnd ad follows:
void SimpleHandler::OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode)
{
CefRefPtr<CefRequest> request = CreateGETRequest();
//CefRefPtr<MyRequestClient> client = new MyRequestClient();
//CefRefPtr<CefURLRequest> url_request = CefURLRequest::Create(request, client.get(), nullptr);
browser->GetMainFrame()->LoadRequest(request);
}


If I try to call the same request using CefURLRequestClient method, I am able to send my request and verified it using Fiddler.
I am using cef_binary_92.0.27+g274abcf+chromium-92.0.4515.159_windows32.tar
chayal
Techie
 
Posts: 25
Joined: Sat Oct 02, 2021 4:50 pm

Re: LoadRequest in Cef simple apllication

Postby magreenblatt » Tue Oct 05, 2021 7:20 am

You need to navigate the browser to https://www.facebook.com (same origin as the request) before you can call LoadRequest. Since you're using a basic GET request, and you're already on the same page, it's probably having no visible effect.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: LoadRequest in Cef simple apllication

Postby chayal » Thu Oct 07, 2021 5:13 pm

Hi magreenblatt,
Thanks for the prompt response.
I have some questions though:
Lets take example of hostname as abc.com and port 8080. So I called APIs as follows:
LoadURL("http://www.abc.com:8080")
I created the POST request from the above URL and called LoadRequest on it. I was able to load the post request successfully.

Ques 1: Can't we use "about:blank" to load URL and then call the LoadRequest on the above server. I did try this but did not get the result . So just confirming.

Ques 2: If we can't use "about:blank" , then I have to first load URL to the server for which I get an intermediate response and a webpage is loaded before I could I get the actual LoadRequest response. My problem is that I don't want to display that intermediate webpage. What should I do to directly display request response.

Thanks in advance :)
chayal
Techie
 
Posts: 25
Joined: Sat Oct 02, 2021 4:50 pm

Re: LoadRequest in Cef simple apllication

Postby amaitland » Thu Oct 07, 2021 5:50 pm

about:blank is a special case, from memory chromium doesn't actually render a html page, it simply displays a blank page.

You can add post data to a request in CefResourceRequestHandler::OnBeforeResourceLoad, simply call LoadUrl as normal and using CefRequestHandler/CefResourceRequestHandler You can modify the request.

https://github.com/cefsharp/CefSharp/wi ... h-postdata has a CefSharp specific example written in c# which should give you a rough guide.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Next

Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 23 guests