DEV Community

Cover image for Automating Microsoft Edge with Puppeteer-Sharp
Darío Kondratiuk
Darío Kondratiuk

Posted on • Edited on • Originally published at hardkoded.com

Automating Microsoft Edge with Puppeteer-Sharp

As you may have heard, Microsoft made available to the public its Chromium-powered Edge browser. Maybe this question won't qualify as technical interview question but:

If Puppeteer-Sharp automates Chromium, and Microsoft Edge (insider) is powered by chromium, that would mean that...

Idea

When you call Puppeteer.LaunchAsync, one of the values you can set in the LaunchOptions is the ExecutablePath.

So, what would happen if we launch Puppeteer passing our Microsoft Edge browser path?



var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
    Headless = true,
    ExecutablePath = "C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe"
});


Enter fullscreen mode Exit fullscreen mode

Let's write a super simple example:



var browserOptions = new LaunchOptions
{
    Headless = false,
    ExecutablePath = "C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe"
};

var browser = await Puppeteer.LaunchAsync(browserOptions);
var page = await browser.NewPageAsync();

await page.SetContentAsync("<div>Testing</div>");


Enter fullscreen mode Exit fullscreen mode

Voilà!

demo running

And after a few tweaks in puppeteer-sharp, and one similar change in puppeteer, we managed to get all tests running using Microsoft Edge!

tests running

So we can say that Puppeteer-Sharp v1.14 is fully compatible with Microsoft Edge Insider version 75.0.131.0.

Yeah

Don't stop coding!

Originally posted on harkoded.com

Top comments (3)

Collapse
 
headlesstesting profile image
HeadlessTesting

Great writeup.

We've added a similar tutorial on our website to use PuppeteerSharp and MicrosoftEdge via Puppeteer in the cloud: headlesstesting.com/support/start/...

The advantage is that you do not need to have Microsoft Edge installed on your computer, the browser is running in our cloud. And you can scale your script to use multiple browsers in parallel.

Collapse
 
vekzdran profile image
Vedran Mandić

Congratulations! :-) The miracles of modern browsers (and good software which is well tested.)

Collapse
 
hardkoded profile image
Darío Kondratiuk

Thanks! :)