11

Is it possible to control and instantiate a Chrome browser from C#? Things like opening a new window, changing the URL, reloading the tabs, etc.

I've had a look for a C# Chrome API but can only find a Javascript ones on https://developer.chrome.com/, and the best I could find here was C# - How to control chrome browser - the best answer was to check out the API.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sam0
  • 141
  • 1
  • 1
  • 5

4 Answers4

9

There is an API available for that. It's called 'Selenium', and has a Chrome-specific third party extension.

http://www.seleniumhq.org/

Check that link.

TernaryTopiary
  • 436
  • 5
  • 17
Abiezer
  • 772
  • 8
  • 14
  • the fact that it is designed specifically for testing put me off - not only do you have to control Chrome through a secondary executable (chromedriver.exe), but in recent versions of Chrome there is a message appearing on top of the screen warning the user that Chrome is controlled by automated testing software. Besides, you cannot control an already opened browser. And I thought this would be so simple.. – hello_earth Mar 25 '20 at 10:43
6

Doing a quick Google search for "chrome C# api" turned up some results I think you may like to consider

I thought the following were particularly promising, if you're willing to accept the concession of using Chrome's developer tools:

TernaryTopiary
  • 436
  • 5
  • 17
  • Thanks - I saw the first link before and it talked about websockets, so saved it in case there wasn't an API. Will have a look at the other 2, thanks. – Sam0 Feb 09 '17 at 18:28
3

Are you looking for something like CEF Sharp?

It's an open source project that allows you to embed Chrome into your .NET application. So you can have those C# controls interact with the browser.

Sunny Patel
  • 7,830
  • 2
  • 31
  • 46
  • If we're talking embedding, I think this question deserves an honorable mention for touching on many options: http://stackoverflow.com/questions/18119125/options-for-embedding-chromium-instead-of-ie-webbrowser-control-with-wpf-c – TernaryTopiary Feb 08 '17 at 18:23
  • Not looking to embed Chrome, but rather control Chrome from C#. The easiest way I can explain it is to use a c# program as a portal for another device to set the URL, or to refresh the tab, or to get the current URL. The C# program is "behind the scenes" – Sam0 Feb 09 '17 at 18:26
  • Well we had an application like that, and embedding Chrome made the best sense so that we could refresh the tab, or certain parts of the page if we needed to. Good luck! – Sunny Patel Feb 09 '17 at 18:31
0

Anyone who has tried Puppeteer? Article about it here. (not C# specific)

TheStoryCoder
  • 3,403
  • 6
  • 34
  • 64