Cannot disable backwards navigation using backspace

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.

Cannot disable backwards navigation using backspace

Postby jthach » Thu May 25, 2017 6:59 pm

Hello, I have CEF build 3.2526.1347 installed on a Windows 10 machine and have been experiencing trouble with disabling backwards navigation on our application. I know we are running an older build, and are in the process of upgrading to the latest stable version, but need to patch this behavior on 2526 in the meantime.

We have already disabled backspace on non-text input using javascript so that we don't navigate to the previous page of our application. The issue is that our CEF application can load an iframe that we have no control over (so disabling backspace through the javascript won't work here). We don't care if they use backwards navigation to go through the iframe, but if they launch an iframe and hit backspace on the first page of that iframe, they are incorrectly taken to the previous page of our CEF application. I know CEF3 doesn't support disabling history so I have looked through the forums for a couple of different approaches:

1. OnBeforeNavigation: http://www.magpcss.org/ceforum/viewtopi ... =6&t=10780
Tried this: "For CEF3 return true if navigation_type == NAVIGATION_BACK_FORWARD in CefRenderProcessHandler::OnBeforeNavigate." which didn't quite work. The call was being hit and I was returning true, but backwards navigation was still allowed. Here is the actual code used.
Code: Select all
bool SimpleApp::OnBeforeNavigation(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, CefRenderProcessHandler::NavigationType navigation_type, bool is_redirect)
{
   if (navigation_type == NAVIGATION_BACK_FORWARD)
   {
      return true;
   }
   return false;
}


2. OnPreKeyEvent: http://www.magpcss.org/ceforum/viewtopi ... =6&t=10312
Tried to catch the backspace key event, which worked, but have no way of knowing what UI element the focus is on from CEF. While I can disable backspace as a whole, I can't find a good way to allow it on text input or other appropriate places. Was trying to think of ways to get that information from the js, but seemed too hacky for what we wanted.

3. OnBeforeBrowse: http://www.magpcss.org/ceforum/viewtopi ... =6&t=11626
Similar to OnBeforeNavigation, I attempt to disable backwards navigation by returning true.
Code: Select all
bool CefSimpleHandler::OnBeforeBrowse(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, bool is_redirect)
{
   CefRequest::TransitionType type = request->GetTransitionType();
   if ((unsigned int)type & TT_FORWARD_BACK_FLAG)
   {
      return true;
   }

   return false;
}


#3 OnBeforeBrowse is actually the closest one to a working solution that I have tried. If we traverse through the iframe to another page, pressing backspace doesn't trigger backwards navigation. The problem is when we first launch the iframe and hit backspace, we are incorrectly taken to the previous page of our CEF application. Not sure why it works for the first case but not the second, but any insight or advice would be greatly appreciated! Please let me know if there is another approach I can take, if it looks like the above attempts should have worked.

Thanks!
jthach
Newbie
 
Posts: 5
Joined: Fri Jan 06, 2017 2:24 pm

Re: Cannot disable backwards navigation using backspace

Postby Czarek » Fri May 26, 2017 1:09 am

You can inject custom javascript on third party websites using CefLoadHandler::OnLoadStart/OnLoadEnd and overwrite backspace key with onkeydown event.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Cannot disable backwards navigation using backspace

Postby jthach » Fri May 26, 2017 5:45 pm

Do you have an example of injecting custom javascript on third party websites? Not sure what functions would allow me to do so.
jthach
Newbie
 
Posts: 5
Joined: Fri Jan 06, 2017 2:24 pm

Re: Cannot disable backwards navigation using backspace

Postby amaitland » Fri May 26, 2017 6:37 pm

Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1291
Joined: Wed Jan 14, 2015 2:35 am

Re: Cannot disable backwards navigation using backspace

Postby jthach » Tue May 30, 2017 7:05 pm

This worked! Thank you for the guidance!
jthach
Newbie
 
Posts: 5
Joined: Fri Jan 06, 2017 2:24 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 60 guests