microsoft / playwright-dotnet

.NET version of the Playwright testing and automation library.
https://playwright.dev/dotnet/
MIT License
2.47k stars 235 forks source link

[Question]: How to launch Chrome from specific location. #1705

Closed zydjohnHotmail closed 3 years ago

zydjohnHotmail commented 3 years ago

Your question

Hello: I am new to Playwright-DotNet, but I have used Puppeteer-Sharp for some time. In Puppeteer-Sharp, I can launch Puppeteer using specific location of Google Chrome. As the following C# code example:

public static readonly LaunchOptions Launch_Option = new()
{
    Headless = false,
    IgnoreHTTPSErrors = true,
    ExecutablePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
    Args = new[] {
    "--no-sandbox",
    "--disable-setuid-sandbox",
    "--ignore-certificate-errors",
    },
};

And launch it like this: await Puppeteer.LaunchAsync(Launch_Option);

Now, for Playwright-DotNet (Version 1.14.0 on Windows 10). I can do this:

C:\Project1 >playwright install chrome
Downloading Google Chrome
Installing Google Chrome

ProductVersion   FileVersion      FileName
--------------   -----------      --------
92.0.4515.159    92.0.4515.159    C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

But I can’t find any C# code example on how to launch it from Chrome’s execute path. I tried something like this:

using var playwright = await Playwright.CreateAsync();
await using var browser =
await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{ Headless = false, SlowMo = 50, Channel = "chrome" });
IBrowserContext context = await browser.NewContextAsync();
IPage page = await context.NewPageAsync();
await page.GotoAsync("https://www.bing.com/");

But when I run my code, I can see Chromium is launched, not Chrome. Any suggestions? I have to use Chrome, as for some web sites, they play some videos, I want to watch the videos. Thanks,

avodovnik commented 3 years ago

1) There is ExecutablePath available as well, in BrowserTypeLaunchOptions.

2) If you try running something like the following, what does version tell you:

using System;
using System.Threading.Tasks;
using Microsoft.Playwright;

namespace chromelaunch
{
    class Program
    {
        static async Task Main(string[] args)
        {
            using (IPlaywright pw = await Playwright.CreateAsync())
            {
                var b = await pw.Chromium.LaunchAsync(new BrowserTypeLaunchOptions() { Headless = false, Channel = "chrome"  });
                var context = await b.NewContextAsync();
                var page = await context.NewPageAsync();

                await page.GotoAsync("chrome://version");
                await page.ScreenshotAsync(new PageScreenshotOptions() { Path = "version.png" });
            }
        }
    }
}
avodovnik commented 3 years ago

This looks like it hasn't had a response. If you're still having trouble, please open a new isssue.