Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when renderer-process-limit=1, in the same ChromiumWebBrowser instance ,after cross-site access,CefSharp.BindObjectAsync not work. #3166

Closed
issingle opened this issue Jul 2, 2020 · 9 comments

Comments

@issingle
Copy link

issingle commented Jul 2, 2020

cefsharp v81
cefsharp.winforms.example
settings.CefCommandLineArgs.Add("renderer-process-limit", "1");

In same ChromiumWebBrowser instance ,access file:///c:/test.html first,then access http://192.168.1.100/test2.html
CefSharp.BindObjectAsync in test2.html dont work,but no throw exception,and devtools console no message too.
i visited #2246 it look like no help.

test2.html some js code:

<script type="text/javascript">
	function Main() {

	   var foo = async function () {
		alert("2.18")
							
		var ret=CefSharp.RemoveObjectFromCache("boundAsync2")
		alert(ret)
			
		var ret2=CefSharp.DeleteBoundObject("boundAsync2")
		alert(ret)
		try{
			await CefSharp.BindObjectAsync({ NotifyIfAlreadyBound: true, IgnoreCache: true },"boundAsync2")
		}catch(err){
			alert(err);
		}
		alert("2.5")
		var ret3=await boundAsync2.hello(" world")
		alert(ret3)
		alert("3")
	  };
	 alert("1")
	 foo();
      }
    
    $(function () {
        Main();
    });
</script>
@amaitland
Copy link
Member

Please fork https://github.com/cefsharp/CefSharp.MinimalExample and provide an example that reproduces your problem.

@amaitland
Copy link
Member

settings.CefCommandLineArgs.Add("renderer-process-limit", "1");

Just to be clear this is not officially tested/supported.

@issingle
Copy link
Author

issingle commented Jul 2, 2020

OK!CefSharp.MinimalExample
Program.cs add:

settings.CefCommandLineArgs.Add("renderer-process-limit", "1");

BrowserForm.cs add code in BrowserForm constructor:

            browser.JavascriptObjectRepository.ResolveObject += (sender,e)=> {
                var repo = e.ObjectRepository;
                if (e.ObjectName == "boundAsync2") {
                    BindingOptions bindingOptions =  BindingOptions.DefaultBinder;
                    bindingOptions.CamelCaseJavascriptNames = false;
                    repo.Register(e.ObjectName, new BoundAsync2(), isAsync: true, options: bindingOptions);
                }
            };

Add Bound Class:

    public class BoundAsync2 {
        public string hello(string s) {
            return "hello " + s;
        }
    }

test.html:

<html>
<body>
<img src="1.png?a=120309093"></img>
</body>
</html>

test2.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="scripts/jquery.min.js"></script>
</head>
<body>
    <div>v1</div>
    <script type="text/javascript">
	function Main() {

	   var foo = async function () {		
		var ret=CefSharp.RemoveObjectFromCache("boundAsync2")
		alert("1“)
		var ret2=CefSharp.DeleteBoundObject("boundAsync2")
		alert("2")
		try{
			await CefSharp.BindObjectAsync({ NotifyIfAlreadyBound: true, IgnoreCache: true },"boundAsync2")
		}catch(err){
			alert(err);
		}
		alert("3")
		var ret3=await boundAsync2.hello(" world")
		alert(ret3)
	  };
	 foo();
      }
    
      $(function () {
          Main();
      });
   </script>
</body>
</html>

Put test2.html in 192.168.1.100,and put test.html in c:\

1.access 192.168.1.100\test2.html ,and it will alert "1",”2“, “3” and “hello world”
2. then access file:///c:/test.html
3. access 192.168.1.100\test2.html again, just alert "1", "2" ,but "3" and "hello word" will not be alerted

Please fork https://github.com/cefsharp/CefSharp.MinimalExample and provide an example that reproduces your problem.

@amaitland
Copy link
Member

Please fork the minimum example and push your changes to GitHub.

@issingle
Copy link
Author

issingle commented Jul 2, 2020

Please fork the minimum example and push your changes to GitHub.

https://github.com/issingle/CefSharp.MinimalExample

@amaitland
Copy link
Member

  1. then access file:///c:/test.html

Does the problem reproduce if you use the http/https scheme?

The file scheme is a non standard scheme and behaves differently to others.

settings.CefCommandLineArgs.Add("renderer-process-limit", "1");

If you remove this line does it behave as expected?

@issingle
Copy link
Author

issingle commented Jul 2, 2020

Problem reproduce if corss-domain access use http scheme.
If remove this line, it behave as expected!!

settings.CefCommandLineArgs.Add("renderer-process-limit", "1");
  1. then access file:///c:/test.html

Does the problem reproduce if you use the http/https scheme?

The file scheme is a non standard scheme and behaves differently to others.

settings.CefCommandLineArgs.Add("renderer-process-limit", "1");

If you remove this line does it behave as expected?

@amaitland
Copy link
Member

I will have a quick look though it's unlikely this can be fixed. I suspect the IPC message is being sent and not received. As CEF doesn't officially support renderer-process-limit there's nothing I can do about that.

@amaitland
Copy link
Member

In some instances CefAppUnmanagedWrapper::OnBrowserDestroyed is being called with the incorrect CefBrowser instance, others I don't see the IPC message being send from the browser -> render process in response to trying to bind an object.

Basically there are bugs in CEF/Chromium when renderer-process-limit is used. This is not something we can fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants