Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 10 2016 09:45
    User @amaitland unbanned @aolko
  • Oct 10 2016 09:36
    @amaitland banned @aolko
  • Feb 11 2016 05:56
    User @amaitland unbanned @miyakedev from this room
  • Feb 10 2016 19:59
    @amaitland banned @miyakedev
Alex Maitland
@amaitland

how to change loading screen background color?

@hongjiapeng You can specify a default background colour via http://cefsharp.github.io/api/86.0.x/html/P_CefSharp_BrowserSettings_BackgroundColor.htm

See https://github.com/cefsharp/CefSharp/wiki/General-Usage#cefsettings-and-browsersettings for an example of setting browser settings in code and via xaml

Anthony
@hongjiapeng
@amaitland Thank you,I try to use set BrowserSettings.BackgroundColor Property ,but the white screen problem still occurs,I saw an article aboult my problem Momentary "white flash" with OSR in cefclient on a browser's first page load but still don't know how to solve­čśé
Alex Maitland
@amaitland
@hongjiapeng What version are you using? What does your code look like?
If there is still a bug in CEF then there's possibly no workaround
Anthony
@hongjiapeng
@hongjiapeng What version are you using? What does your code look like?
I use .NET Framework 4.8´╝îthe package CefSharp.Wpf's version is 84.4.10,and my code is below:
ChromiumWebBrowser browser = new ChromiumWebBrowser()
{
    Address = "http://192.168.1.243:8070/#/log",
    BrowserSettings= new BrowserSettings
    {
        BackgroundColor = ColorToUInt(System.Drawing.Color.FromArgb(255, 27, 40, 56))
    }
};

public static uint ColorToUInt(System.Drawing.Color color)
{
     return (uint)((color.A << 24) | (color.R << 16) | (color.G << 8) | (color.B << 0));
}
Alex Maitland
@amaitland
@hongjiapeng Does the problem reproduce with version 86?
Senthilvel1981
@Senthilvel1981

I have a web page making ActiveX calls. Currently the page is loaded in IE embedded browser. Now I am planning to start using CEF as embedded web browser. I want to achieve this without modifying the existing code.

My Sample web page code:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Test ActiveXObject</title>
</head>
<body onload="myFunction()">

<script type="text/javascript" >

function CallSampleApi()
  {
    var obj = new ActiveXObject("Global.Pref");
    var prefs = obj.Create("Pref.myPref");

    if (prefs != null ) {
        return prefs.SampleAPI();
      }
      else {
        return 'not caught';
      }

}

function myFunction() {

          var message = "<h1 align='center'>Browser is Chrome </h1>" +
                         "<table border='1' width=500>" +
                           "<tr bgcolor='grey'><th width=300>Function Name</th><th width=200>Result</th></tr>" +
                 "<tr><td>Call Sample Api</td><td align='center'>" + CallSampleApi() + "</td></tr>" +
                     "</table>" ;

          document.write(message);

}

</script>
</body>
</html>

I am using WPF cefsharp library for embedded web browser. In my WPF code, i have written a wrapper for this ActiveXObject and adding javascript dynamically using ExecuteJavaScriptAsync() API in OnContextCreated event. This works fine. But the problem is, this code somehow removes all <HEAD> tag in my html file which is strange.

public void OnContextCreated(IWebBrowser browserControl, IBrowser browser, IFrame frame)
{

            if (_script != null && frame.IsMain)
            {

                if (frame.Url.Contains("dev")) // avoid dev tools call

                string script = @"class ActiveXObject {
                                           constructor(name) {
                                        }

                                    Create(nativeObj) {
                                        switch (nativeObj) {
                                            case 'Pref.myPref':
                                                return new Preferences();
                                            default:
                                                return null;
                                        }

                                    }
                                }

                                class Preferences { 
                                    constructor() {
                                    }

                                SampleAPI() {
                                    return 'I am caught';
                                }

                            }";

            frame.ExecuteJavaScriptAsync(script);
    }
}

Source of the page loaded in cef embedded browser:

<html>
<head></head>
<body>
<h1 align="center">Browser is Chrome </h1>
<table border="1" width="500"><tbody><tr bgcolor="grey"><th width="300">Function Name</th><th width="200">Result</th></tr><tr><td>Call Sample Api</td><td align="center">I am caught</td></tr></tbody></table>
</body>
</html>

Not sure how HEAD elements are removed. If i remove onload event from html page and move the content within SCRIPT tag, it works fine.

miriam40
@miriam40

how to set cookie and open browser?

var cookie = new CefSharp.Cookie {
Creation = DateTime.Now,
HttpOnly = false,
Secure = false,
Path = "/",
Domain = "1.1.1.1", //this is sample domain
Name = "sample", // sample name
Value = statictoken, // login token
Expires = DateTime.Now.AddDays(365),
};
var gettedCookie = Cef.GetGlobalCookieManager();
if (gettedCookie.SetCookie("url", cookie))
{
var browser = new ChromiumWebBrowser("");
browser.Load("url");
browser.Dock = DockStyle.Fill;
this.Controls.Add(browser);
}

but this code not work...
my work environment is .net 4.8 winform..
;(
miriam40
@miriam40
sry i've solved. problem is wrong domain... thx
TMOONLIGHT
@tmoonlight
hello´╝î i m using wpfImeKeyboardhandler to fix IME problem´╝łwrong ime position´╝ë´╝îbut its not work with ÔÇťsogou pinyinÔÇŁ´╝îis there any solution´╝č
Alex Maitland
@amaitland

hello´╝î i m using wpfImeKeyboardhandler to fix IME problem´╝łwrong ime position´╝ë´╝îbut its not work with ÔÇťsogou pinyinÔÇŁ´╝îis there any solution´╝č

@tmoonlight Not that I'm aware of currently. There was a discussion previous see cefsharp/CefSharp#3004

You can try switching to https://www.nuget.org/packages/CefSharp.Wpf.HwndHost/ which is a designed as a drop in replacement for the ChromiumWebBrowser. Basically like hosting the WinForms in WPF.

TMOONLIGHT
@tmoonlight
@amaitland hi alex´╝îthank you for your reply´╝îwe have tried the hwndhost project few days ago´╝î but it is very easy to cause our program crash....
Alex Maitland
@amaitland
@tmoonlight Do you have a stack trace for the exception?
You can use the WinForms version hosted in WPF using a WindowsFormsHost
TMOONLIGHT
@tmoonlight
@amaitland i found a bug in wpfimekeyboardhandler.cs. The system caret destoryed too early. i fixed this problem just now´╝îit seems workable.
Alex Maitland
@amaitland
@tmoonlight You are welcome to submit a PR.
TMOONLIGHT
@tmoonlight
Ok ,let me do more test´╝îi will try to submit PR later.
code_wei
@zero1988
@amaitland Excuse me? I have a page named 'PAGE1'´╝î in PAGE1, I register an navtive object named 'OBJ1'. Now, in PAGE1 I open a new page named 'PAGE2'. So PAGE2 also can call OBJ1's method. But how can I hnow which page calls the method?
Gilberto S
@kiewic_twitter
Hello, do you have idea what can cause the exception: new Exception("Not all objects were bound successfully, bound objects were " + string.Join(",", args.ObjectNames))?
Alex Maitland
@amaitland

Now, in PAGE1 I open a new page named 'PAGE2'. So PAGE2 also can call OBJ1's method

@zero1988 What exactly do you mean by open? Have you navigated to a different page? Or have you opened a popup? Or something else?

The generic options are

  • Add a url param to your methods and pass in window.location.href from javascript
  • Pass in a reference to ChromiumWebBrowser in your object constructor and check the Address property in WinForms or use the AddressChanged event in WinForms/WPF to let your object know the address changed.

I'd need to know more about your scenario to make a specific recommendation

do you have idea what can cause the exception: new Exception("Not all objects were bound successfully, bound objects were " + string.Join(",", args.ObjectNames))?

@kiewic_twitter Are some of the objects bound? Is args.ObjectNames populated?

If you passed in the name of an object that wasn't registered you'd get the exception.

I'd really need more detail to actual speculate on a cause

TMOONLIGHT
@tmoonlight
@Alex Maitland hi, I have submitted PR just now.
@amaitland
Angshuman Agarwal
@angshuman-agarwal

@amaitland : On a user PC, Win 10 with Intel HD Graphics 520, the cef subbrowser process just crashes. Unfortunately, I do not have debug.log. And, if I go to chrome://gpu (on chrome browser) - I see one difference i.e. Hardware Protected Video Decode : Unavailable

Any clues / ideas what can I further debug to understand why this happens ?

It is v73.1.3 (WPF)
Angshuman Agarwal
@angshuman-agarwal
In the code, I have DisableGpuAcceleration() enabled
Cortney Smith
@cortneysmith
Hey -- I posted here a while ago about not being able to get CefSharp working with a proxy. I've updated to version 86.0.241 and it's still not working. I did notice though that the code which checks for an internet connection (which I've added in IsBrowserIntialized) is called before Cef.Initialize. This might be the issue. Do you have any ideas? Thanks!
Alex Maitland
@amaitland
@angshuman-agarwal Try
//Firstly try this
settings.CefCommandLineArgs.Add("disable-gpu");
settings.CefCommandLineArgs.Add("disable-gpu-compositing");

//If first first two don't work then try to completely disable the use of the GPU process
settings.CefCommandLineArgs.Add("disable-gpu");
settings.CefCommandLineArgs.Add("disable-software-rasterizer");

(which I've added in IsBrowserIntialized) is called before Cef.Initialize

@cortneysmith You need to call Cef.Initialize before you create your first ChromiumWebBrowser instance.
If you have an if(!Cef.IsInitialized) check in your code temp commented it out, an exception should be thrown indicating you need to restructure your code.

Angshuman Agarwal
@angshuman-agarwal

@angshuman-agarwal Try

//Firstly try this
settings.CefCommandLineArgs.Add("disable-gpu");
settings.CefCommandLineArgs.Add("disable-gpu-compositing");

//If first first two don't work then try to completely disable the use of the GPU process
settings.CefCommandLineArgs.Add("disable-gpu");
settings.CefCommandLineArgs.Add("disable-software-rasterizer");

Thanks a lot - will try these suggestions. I thought DisableGpuAcceleration() did the same as setting "1" for disable-gpu and disable-gpu-compositing options, no ?

Angshuman Agarwal
@angshuman-agarwal

@amaitland - I enabled debug.log and ran a build with switches you mentioned. Does not look like a graphics issue. What I see when proxy URL hit (internally), there is this message :

proxy_resolution_service.cc(1353)] Failed configuring with PAC script, falling-back to manual proxy servers.

No idea why should that crash the browser sub process. No other information on crash in the debug.log. I enabled verbose logging.

Angshuman Agarwal
@angshuman-agarwal
But cefclient (v73.1.3) works fine on that machine and I see no issues in debug.log
Angshuman Agarwal
@angshuman-agarwal

Also, one more peculiar issue I observed is

WARNING: Unsupported cookie scheme: chrome-devtools (via CefSharp)

Alex Maitland
@amaitland
@angshuman-agarwal I've seen other reports of proxy related crashes, try disabling proxy resolution. See https://magpcss.org/ceforum/viewtopic.php?f=6&t=17247
Angshuman Agarwal
@angshuman-agarwal

I did do a new build with this : No luck though :(

CefCommandLineArgs.Add("no-proxy-server", "1")

Is that you meant ?

Angshuman Agarwal
@angshuman-agarwal
That suppresses that proxy error ... but sub process still crashes silently...nothing in eventvwr nor in debug.log... I also tried to disable full GPU process, only gpu compositing (as you suggested), ...No luck on that machine. cefclient with osr (the WPF equivalent cmd line options) just works fine.
Angshuman Agarwal
@angshuman-agarwal
Just to continue being more explicit - If I only disable proxy, then I start getting this error - Failed to launch GPU process.
So, as I mentioned above, I tried both disabling proxy + GPU (compositing / all ..both options you suggested) - After these, all errors go away from debug.log, but sub-process still crashes in cefsharp.
Angshuman Agarwal
@angshuman-agarwal
I know...it's hard to debug for anyone with this kind of info...I am discussing to see if I can get directions to debug cefsharp further on a user machine where I have no dev environment nor I have luxury to even download or install anything. And, of course, if I could reproduce on my machine...that would be ideal (I just cannot).
Angshuman Agarwal
@angshuman-agarwal
Thanks, I will setup crash reporter - v. useful.
I have one issue now related to UnitTests. So far, one of our WPF UI (XAML) classes was not having cef control and there are tons of tests (using Dispatcher) written which loads that UI. With cef control being added to the XAML recently, all tests fail with Could not load file or assembly CefSharp, Version=73.1.130.0, Culture=.... blah...
I do not want to test anything related to cefsharp here, but is there a way to get past this error such that tests work again ? Anyone faced/solved this ?
NB: I use NUnit
Alex Maitland
@amaitland

I do not want to test anything related to cefsharp here, but is there a way to get past this error such that tests work again ?

@angshuman-agarwal Subclass ChromiumWebBrowser override CreateOffscreenBrowser and return false when running your unit tests.

Angshuman Agarwal
@angshuman-agarwal
Thank you !
larouchefrancois
@larouchefrancois
Hello! I was wondering how to get settings value set in CefSettings with Initialize later in the code. Is there a global variable that can get that?
For instance, if I want to read the LogSeverity later on. A related question is: is it possible to set a global variable to be accessed anywhere in the Cef context? like in one handler. Reason I'm asking is that I have my own logging object that I want to set once and reuse the same. I can always create a new one each time but it's a bit of resource waste if you ask me...