0

Goal

  • I am trying to get remote debugging URL of specific ChromiumWebBrowser object after initializing it with new ChromiumWebBrowser(...)

Application Info

  • My application creates multiple ChromiumWebBrowser worker instances at runtime, the number of instances varies according to workload. All of them navigates to some URLs and perform tasks(clicks on buttons, fills inputs, collects values) on sites. If the worker finds unexpected result after it's actions(Couldn't find the div element with given id), it sends notification to the user and hands out it's remote debugging URL which is allowing the user to take control of worker and investigate what went wrong during process.

The Problem

  • I don't know how to obtain remote debugging URL of specific ChromiumWebBrowser object
  • e.g. it would be nice if the URL variable could instantiated that easy in the following code block but ChromiumWebBrowser class doesn't have such property (RemoteDebuggingUrl).

    ChromiumWebBrowser worker1 = new ChromiumWebBrowser(...);

    string URL = worker1.RemoteDebuggingUrl;

Efforts

I decided to dig down into the source code of CefSharp to find out how remote debugging server creates links per ChromiumWebBrowser basis, e.g. i assumed maybe it is accessing of ChromiumWebBrowser objects ID like property because the links of browsers in remote debugging main page (accessed via http://localhost:8088) is like following url ;

http://localhost:8088/devtools/inspector.html?ws=localhost:8088/devtools/page/FA54735587998EFD141A2300AE57F70C

The "FA54735587998EFD141A2300AE57F70C" part is the ID of the remote debugging link as seen in http://localhost:8088/json

[
  {
    "description": "",
    "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:8088/devtools/page/FA54735587998EFD141A2300AE57F70C",
    "id": "FA54735587998EFD141A2300AE57F70C",
    "title": "Sign In",
    "type": "page",
    "url": "https://af.sts.mapfre.net/adfs/ls/?SAMLRequest=hZJda8IwFIb%2FSsm9TVvFj9AKtk4Q3BDddrGbEeopBpqkyzl1279fWnFzF3NXgZPzJs9zkhSlrhuxaOlodvDWAlLwoWuDot%2FIWOuMsBIVCiM1oKBS7Bf3G5GEkWicJVvaml1FbickIjhS1rBgvczYa5zP8tE0XxXjPJrdjYer8SiaTIplnAxXwyguWPAMDn1%2FxnzchxBbWBskaciXong2iJNBMn6MExFNxTB5YcHSOygjqU8diRoUnMsqRMJQy6ZyEBogLg8V8ho5CwprELrzbpGX5yZRts75daB0U6tSEQtW1pXQDzBjlawROsytN1Un%2BK4sLuLdZa0Gtwd3UiU87TY%2FkJ7uQlhaHZLjGuraGt5YpB1g0zGwedrNWfSjcPM%2Fsym%2FbkvP7%2FzgvdbLrfXonx24lv9odxV1GFR9qyAnDSqv74U82HvhQJKXJNcC4%2FPzlb9%2F0%2FwL",
    "webSocketDebuggerUrl": "ws://localhost:8088/devtools/page/FA54735587998EFD141A2300AE57F70C"
  }
]

Finally i couldn't navigate to the implementation of following symbol using Visual Studio 2019

bool CefInitialize(const CefMainArgs& args,
                   const CefSettings& settings,
                   CefRefPtr<CefApp> application,
                   void* windows_sandbox_info);

in purpose of finding how remote debugging server works. I located this symbol in "cef_app.h" header file which is part of the cef-sdk.75.1.14 Nuget Package. I tried to find the implementation of this symbol because i thought it is the entry point of remote debugging server, because it takes CefSettings parameter which includes RemoteDebuggingPort which was 8088 in my case.

yildizmehmet
  • 53
  • 1
  • 8
  • Please read the first few paragraphs of https://github.com/cefsharp/CefSharp/wiki/General-Usage – amaitland Jan 10 '20 at 21:30
  • @amaitland oh so it is clear why i can't navigate to the implementation of CefInitialize it is part of another project. Thanks for pointing out. – yildizmehmet Jan 10 '20 at 21:39
  • 1
    CEF unfortunately doesn't provide a means of identify the browser, would be nice to have. There's a feature request forum at https://magpcss.org/ceforum/viewforum.php?f=7 I've seen people hack together workarounds, usually be adding a fragment identifier to the url and identifying the browser instances that way. – amaitland Jan 12 '20 at 03:38
  • @amaitland What is fragment identifier?, And how can i add something to the URL, since URLs are generated by CEF Remote Debugging Server? I thought about giving some values to description (which is seen in json), but i cannot manipulate it. – yildizmehmet Jan 13 '20 at 08:24
  • 1
    [Fragment Identifier](https://en.wikipedia.org/wiki/Fragment_identifier) is a `#`. You don't add the fragment to the debugging url, you add it to the url of the web page displayed in the browser. You can then identify the relevant instance. – amaitland Jan 13 '20 at 08:32
  • So browser adds own ID like fragment identifier to the url of whichever page it loads, like ; "https://www.google.com#browser1" then when i query the fragment identifier part of url i will know which browser instance is running. Nice trick thank you :) – yildizmehmet Jan 13 '20 at 12:13

0 Answers0