1. Create Browser with initial "about:blank" page.
2. After browser created and "about:blank" is loaded navigate to let say "google.com".
3. When "google.com: page is loaded run javascript on it and navigate to another page.
4. When this another page is loaded run javascript on it and navigate via post request with params to 3rd one.
So to find out has the page loading been completed - I'm using OnLoadingStateChange with "!isLoading" param. Then when it is ready, I'm trying to call browser->GetMainFrame()->LoadRequest() to navigate to next page(which can be "post" and has headers):
- Code: Select all
void RequestClientHandler::OnLoadingStateChange(CefRefPtr<CefBrowser> browser, bool isLoading, bool canGoBack, bool canGoForward) {
if (!isLoading) {
//Get action object
ActionsInterface * actionObject = GetActionObject(browser->GetIdentifier());
if (actionObject != nullptr) {
//Get Frame
CefRefPtr<CefFrame> frame = browser->GetMainFrame();
//Get action query
ActionQuery query = actionObject->Action();
//Make sure, we are on the right page
std::string url = frame->GetURL();
if (url != query.url && actionObject->Prepare()) {
CefRefPtr<CefRequest> request = CefRequest::Create();
request->SetURL(query.url);
request->SetMethod(query.method);
if (!query.headers.empty()) {
CefRequest::HeaderMap headerMap;
for (auto x : query.headers) {
headerMap.insert(x);
}
request->SetHeaderMap(headerMap);
}
if (query.upload_data != "") {
CefRefPtr<CefPostData> postData = CefPostData::Create();
CefRefPtr<CefPostDataElement> element = CefPostDataElement::Create();
element->SetToBytes(query.upload_data.size(), query.upload_data.c_str());
postData->AddElement(element);
request->SetPostData(postData);
}
frame->LoadRequest(request);
}
else if (query.javascript != "") {
//Run Javascript
RunJavaScript(query.javascript, browser);
}
}
}
}
But the problem is LoadRequest looks like not working. Browser not navigating to the page that has been setup in request, because it is still at "about:blank" again and again. While query.url is "https://www.google.com/"