chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.22k stars 456 forks source link

winforms: setting `remote-allow-origins` does not show remote origins on set port with Chrome bootstrap #3740

Closed m-kovac closed 1 month ago

m-kovac commented 1 month ago

Describe the bug

With CefSharp v126.2.70, CEF v126.0.6478.115 the remote-allow-origins parameter with set localhost:port stopped to have effect. This is connected to switch from Alloy bootstrap to Chrome bootstrap.

To Reproduce

  1. Clone https://github.com/cefsharp/CefSharp.MinimalExample
  2. Open solution CefSharp.MinimalExample.net472
  3. Update CefSharp for CefSharp.MinimalExample.WinForms.net472 to v126.2.70
  4. In CefSharp.MinimalExample.WinForms.net472 project Program.cs set following settings to CefSettings
settings.RemoteDebuggingPort = 1236; 
settings.CefCommandLineArgs.Add("remote-allow-origins", $"http://localhost:{settings.RemoteDebuggingPort}");
  1. Start the project
  2. Open new browser window and go to localhost:1236
  3. Observe empty window
  4. Stop the project
  5. Add setting settings.ChromeRuntime = false; to CefSettings to change back to Alloy bootstrap
  6. Start the project
  7. Go to localhost:1236
  8. Observe window with the link to "Google"

Expected behavior The remote-allow-origins should work with Chrome bootstrap.

Screenshots

Missing link image

Expected behavior image

Versions (please complete the following information):

magreenblatt commented 1 month ago

The remote-allow-origins flag is implemented in Chromium. I suggest that you test the behavior in Google Chrome.

m-kovac commented 1 month ago

Sorry, I don't understand. What should I test in Google Chrome?

magreenblatt commented 1 month ago

What should I test in Google Chrome?

You should test how the --remote-allow-origins flag behaves in Google Chrome. From the code:

// Enables web socket connections from the specified origins only. '*' allows
// any origin.
magreenblatt commented 1 month ago

Go to localhost:1236 Observe window with the link to "Google"

You should use chrome://inspect/ for connecting to remote debugging.

magreenblatt commented 1 month ago

Your "Missing link" and "Expected behavior" screenshots are also both showing Chrome style windows.

magreenblatt commented 1 month ago

Closing this issue as WontFix given that CEF has no special handling for the --remote-allow-origins flag, and there are better/preferred ways to access remote debugging if that is the intention.

SiMoStro commented 1 month ago

To be honest, we are facing the exact same problem starting from v126 and I don't get the "WontFix" reason; we were able to successfully use the "--remote-allow-origins" switch:

https://github.com/cefsharp/CefSharp/issues/4894

this seems a regression to me, either in CEF or in CefSharp :-/

jozefizso commented 1 month ago

Opening the URL for the remote debugging port on previous CEF releases will load the JSON with list of active browser instances:

image

This no longer happens for the v126:

image

Requesting the JSON manually for v126 does work:

 curl http://localhost:1236/json/list?t=1722606942069
[ {
   "description": "",
   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:1236/devtools/page/A4A02D4EEDF8E9EDB16F4C71237DB7FD",
   "id": "A4A02D4EEDF8E9EDB16F4C71237DB7FD",
   "title": "Slido",
   "type": "page",
   "url": "https://app.example.org/",
   "webSocketDebuggerUrl": "ws://localhost:1236/devtools/page/A4A02D4EEDF8E9EDB16F4C71237DB7FD"
} ]

And opening the devtoolsFrontendUrl in the browser will show the Dev Tools for the running CEF instance.

amaitland commented 1 month ago

this seems a regression to me, either in CEF or in CefSharp :-/

This is not a regression in CefSharp.

Testing with cef_binary_127.3.2+gf1af617+chromium-127.0.6533.100_windows64_client and the problem reproduces.

# Works
.\cefclient.exe --use-alloy-style --remote-debugging-port=9955 --remote-allow-origins=http://localhost:9955 --disable-chrome-runtime

# Doesn't work
.\cefclient.exe --use-alloy-style --remote-debugging-port=9955 --remote-allow-origins=http://localhost:9955

Tested with --disable-request-handling-for-testing also which makes no difference.

given that CEF has no special handling for the --remote-allow-origins flag

Without actually debugging my guess would be that it's something fairly simple that's missing or not enabled in the Chrome Bootstrap.

jozefizso commented 2 weeks ago

Our CefSharp setttings:

var settings = new CefSettings();
settings.RootCachePath = Path.Combine(appDataFolder, @"browser-cache");
settings.BrowserSubprocessPath = Path.Combine(installPath, Environment.Is64BitProcess ? "x64" : "x86", "CefSharp.BrowserSubprocess.exe");
settings.RemoteDebuggingPort = 1236;
settings.CefCommandLineArgs.Add("remote-allow-origins", $"http://localhost:{settings.RemoteDebuggingPort}");

CefSharpSettings.RuntimeStyle = CefRuntimeStyle.Chrome;

Remote Debugger in M125

curl  -v http://localhost:1236
* Host localhost:1236 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:1236...
*   Trying 127.0.0.1:1236...
* Connected to localhost (127.0.0.1) port 1236
> GET / HTTP/1.1
> Host: localhost:1236
> User-Agent: curl/8.8.0
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 200 OK
< X-Frame-Options:DENY
< Content-Length:1475
< Content-Type:text/html; charset=UTF-8
<
<html>
<head>
<title>CEF remote debugging</title>
<style>
</style>

<script>
function onLoad() {
  var tabs_list_request = new XMLHttpRequest();
  tabs_list_request.open("GET", "/json/list?t=" + new Date().getTime(), true);
  tabs_list_request.onreadystatechange = onReady;
  tabs_list_request.send();
}

function onReady() {
  if(this.readyState == 4 && this.status == 200) {
    if(this.response != null)
      var responseJSON = JSON.parse(this.response);
      for (var i = 0; i < responseJSON.length; ++i)
        appendItem(responseJSON[i]);
  }
}

function appendItem(item_object) {
  var frontend_ref;
  if (item_object.devtoolsFrontendUrl) {
    frontend_ref = document.createElement("a");
    frontend_ref.href = item_object.devtoolsFrontendUrl;
    frontend_ref.title = item_object.title;
  } else {
    frontend_ref = document.createElement("div");
    frontend_ref.title = "The tab already has active debugging session";
  }

  var text = document.createElement("div");
  if (item_object.title)
    text.innerText = item_object.title;
  else
    text.innerText = "(untitled tab)";
  text.style.cssText = "background-image:url(" + item_object.faviconUrl + ")";
  frontend_ref.appendChild(text);

  var item = document.createElement("p");
  item.appendChild(frontend_ref);

  document.getElementById("items").appendChild(item);
}
</script>
</head>
<body onload='onLoad()'>
  <div id='caption'>Inspectable WebContents</div>
  <div id='items'></div>
</body>
</html>
* Connection #0 to host localhost left intact

Remote Debugger in M126 & M127

 curl  -v http://localhost:1236
* Host localhost:1236 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:1236...
*   Trying 127.0.0.1:1236...
* Connected to localhost (127.0.0.1) port 1236
> GET / HTTP/1.1
> Host: localhost:1236
> User-Agent: curl/8.8.0
> Accept: */*
>
< HTTP/1.1 200 OK
< X-Frame-Options:DENY
< Content-Length:0
< Content-Type:text/html; charset=UTF-8
<
* Connection #0 to host localhost left intact