简体   繁体   中英

C# Headless browser without needing a .exe

I have been looking at using a headless browser with C# code. Headless Chrome seems like the way to go as Phantom JS is on its way down. When I install either of these to work with selenium, an executable is copied into the project and the C# code will call this .exe to load the headless browser.

I have strict restrictions that prevent me from being able to call a .exe from my code, which prevents me from being able to do this. I can't call any executables from windows either, so I need a headless browser that doesn't run from a standalone executable.

I have tried to see whether it is possible to serialize the executable in some way that would let me load it up and run it inside the memory pool of the application. From the research I have done, this seems like something that would be really difficult unless I were to emulate windows with some kind of virtual machine. This might do it, but the cost of spinning up an entire VM operating system, running a browser and navigating to a website would take so long that the solution wouldn't be of any use.

The thought of even trying to decompile an executable to see if I can create a DLL of some kind seems like a stretch too far. Is there anything I can do to get a headless chrome browser, or any headless browser for that matter to working without the need to call an external executable.

I see two possibilies:

  1. Use the official chromedriver code to built what you need
  2. Use something like https://crossbrowsertesting.com/selenium-testing , https://www.browserstack.com/ or similar services to run your selenium tests somewhere who have the possibilites to do so

Depending on your type of application I think several options are possible:

  1. Run you online service (or use 3rd party services) that hosts headless browser and then call your service from an application. That would be an external dependency, associated with extra cost, but at least you won't invoke local .exe files.

  2. If this is a desktop Windows-based application, you can embed WebBrowser control, make it invisible and use IE-based automation library, that won't call Internet explorer .exe file directly.

  3. Probably some of Fake Browser Engines can be enough for your tasks. From that list, the Simple Browser looks like 100% C#-based implementation, but with no Javascript support.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM