7

I am embedding a webapp using CefSharp which is all working fine. However, when logging into the app, CEF doesn't offer to remember the username and password like it does when opening the app in normal Chrome.

Is there a way in CefSharp to get cef to ask to remember usernames/password so that when uses go back to the app, they will be able to sign in quicker ?

I have tried using some command line args e.g.

CefSettings cs = new CefSettings();
cs.CefCommandLineArgs.Add("enable-automatic-password-saving", "enable-automatic-password-saving");
cs.CefCommandLineArgs.Add("enable-password-save-in-page-navigation", "enable-password-save-in-page-navigation");
Cef.Initialize(cs);

but so far, cef has not prompted me to save the username/password.

SteveP
  • 18,840
  • 9
  • 47
  • 60

2 Answers2

4

I had the same issue and resolved it by injecting some javascript from the FrameLoadEnd event. Something like:

void wb_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
{
  if (e.Url.Equals(@"https://yyy.zzz.com/"))
  {
    var wb = sender as ChromiumWebBrowser;
    wb.EvaluateScriptAsync
        (@"document.querySelector('input#username').value='steve';");
   }
}
chris
  • 96
  • 5
  • That's a good idea if I wanted to default the username etc. However, I want the browser to remember the password as different users will be using the app, and I don't always have control of the HTML displayed (it can come from third-party websites). – SteveP Apr 09 '15 at 12:45
  • You could make this code more generic by adding javascript code that triggers when forms are submitted and loaded and offers to save to local storage or something. It might also be possible to [use](https://github.com/cefsharp/CefSharp/issues/2497) one of the extensions already doing this like [LastPass](https://chrome.google.com/webstore/detail/lastpass-free-password-ma/hdokiejnpimakedhajhdlcegeplioahd). – Arne S Jan 08 '20 at 01:12
2

CefSharp doesn't support remember password prompt. I don't believe that CEF does either, though it's probably worth asking on http://magpcss.org/ceforum/ for a definitive answer (There's no reference in the API for the current version).

I'll also point of that unless explicitly told CEF will use an in memory cookie store, so session cookies won't be persisted. You need to specify CefSettings.CachePath to persist cookies (and other cache able data).

amaitland
  • 4,073
  • 3
  • 25
  • 63
  • Thanks for the answer. I found the CachePath setting for the cookies, but I was hoping that the commandLineArgs would have some options to allow the remember password functionality. – SteveP Apr 09 '15 at 12:43
  • `CEF` is no frills when it comes to that sort of thing, there's no download manager either. My guess is that some of these features aren't part of the core `Chromium` open source project. If you haven't already it's probably still worth asking on the `ceforum`, see if anyone there has any pointers. – amaitland Apr 09 '15 at 15:55
  • 1
    No plans for CEF support see https://magpcss.org/ceforum/viewtopic.php?f=7&t=17293 for official response. – amaitland Jan 07 '20 at 03:54