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.

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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..
It is not just for testing. We use Selenium in high-volume production code to automate Chrome. It can work well, but can be quirky as well. My advice is to develop in Chrome Console, finding the javascript commands you need and then calling ExecuteScript.
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:

1 Comment

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.
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.

3 Comments

If we're talking embedding, I think this question deserves an honorable mention for touching on many options: stackoverflow.com/questions/18119125/…
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"
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!
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.