microsoft / playwright-dotnet

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

[BUG]Playwright is timing out while opening browser (Timeout 180000ms exceeded.) #2753

Closed kabdul-incomm closed 12 months ago

kabdul-incomm commented 1 year ago

Source code

` var playwright = await Microsoft.Playwright.Playwright.CreateAsync(); var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = false, IgnoreAllDefaultArgs = true, Args = new[] { "--disable-field-trial-config", "--disable-background-networking", "--enable-features=NetworkService,NetworkServiceInProcess", "--disable-background-timer-throttling", "--disable-backgrounding-occluded-windows", "--disable-back-forward-cache", "--disable-breakpad", "--disable-client-side-phishing-detection", "--disable-component-extensions-with-background-pages", "--disable-default-apps", "--disable-dev-shm-usage", "--disable-extensions", "--disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate", "--allow-pre-commit-input", "--disable-hang-monitor", "--disable-ipc-flooding-protection", "--disable-popup-blocking", "--disable-prompt-on-repost", "--disable-renderer-backgrounding", "--disable-sync", "--force-color-profile=srgb", "--metrics-recording-only", "--no-first-run", "--enable-automation", "--password-store=basic", "--use-mock-keychain", "--no-service-autorun", "--export-tagged-pdf"

          }
      }) ;
      _Page = await browser.NewPageAsync();
      _Page.SetDefaultTimeout((float)60000);`


**Steps**
  Run the above steps in a test method.

**Expected**
Maximized browser should be opened.
Note:I'm trying to open browser in maximize state. And my application to use all the monitor space.

**Actual**
Playwright timeout after 180000ms.
mxschmitt commented 1 year ago

Have you tried running it without passing all these extra arguments?

kabdul-incomm commented 1 year ago

Yes. And it times out.

Have you tried running it without passing all these extra arguments?

mxschmitt commented 1 year ago

Can you set the $Env:DEBUG="pw:browser,pw:protocol" env var? this should yield us more output about whats going on.

kabdul-incomm commented 1 year ago

$Env:DEBUG="pw:browser,pw:protocol

System.AggregateException : One or more errors occurred. (Timeout 180000ms exceeded. =========================== logs ===========================

C:\Users\kabdul\AppData\Local\ms-playwright\chromium-1080\chrome-win\chrome.exe --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf pid=8268 [pid=8268][err] [8268:27248:1110/121640.381:ERROR:policy_logger.cc(154)] :components\enterprise\browser\controller\chrome_browser_cloud_management_controller.cc(163) Cloud management controller initialization aborted as CBCM is not enabled. ============================================================) ----> System.TimeoutException : Timeout 180000ms exceeded. =========================== logs =========================== C:\Users\kabdul\AppData\Local\ms-playwright\chromium-1080\chrome-win\chrome.exe --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf pid=8268 [pid=8268][err] [8268:27248:1110/121640.381:ERROR:policy_logger.cc(154)] :components\enterprise\browser\controller\chrome_browser_clo ![AzureGitDebug](https://github.com/microsoft/playwright-dotnet/assets/51454842/16c00a51-905e-43f5-8e81-6fc57a330d68) ud_management_controller.cc(163) Cloud management controller initialization aborted as CBCM is not enabled.
mxschmitt commented 1 year ago

Could you try running chromium with the default arguments? I see that a few are missing which we are adding.

kabdul-incomm commented 1 year ago

Could you try running chromium with the default arguments? I see that a few are missing which we are adding. Here is the error response without passing default args. I know this quesiton will pop up. Message:  System.AggregateException : One or more errors occurred. (Timeout 180000ms exceeded. =========================== logs ===========================

C:\Users\kabdul\AppData\Local\ms-playwright\chromium-1080\chrome-win\chrome.exe pid=30472 [pid=30472][err] [30472:30700:1110/123241.703:ERROR:policy_logger.cc(154)] :components\enterprise\browser\controller\chrome_browser_cloud_management_controller.cc(163) Cloud management controller initialization aborted as CBCM is not enabled. ============================================================) ----> System.TimeoutException : Timeout 180000ms exceeded. =========================== logs =========================== C:\Users\kabdul\AppData\Local\ms-playwright\chromium-1080\chrome-win\chrome.exe pid=30472 [pid=30472][err] [30472:30700:1110/123241.703:ERROR:policy_logger.cc(154)] :components\enterprise\browser\controller\chrome_browser_cloud_management_controller.cc(163) Cloud management controller initialization aborted as CBCM is not enabled.
mxschmitt commented 1 year ago

did you also remove the IgnoreAllDefaultArgs flag? since now there are no arguments at all.

kabdul-incomm commented 1 year ago

did you also remove the IgnoreAllDefaultArgs flag? since now there are no arguments at all.

No. If I remove IgnoreAllDefaultArgs and try it doesn't maximize the window by default and when I try to maximize manually the viewport size is not matching with my monitior size. And my test runs fine.

Why can't I pass the args.. which I want?

mxschmitt commented 12 months ago

You don't need to remove all the arguments when you want to maximise the window. Its enough to do the following steps:

  1. Pass "--start-maximized" as a browser launch arg (don't use IgnoreAllDefaultArgs)
  2. Set ViewportSize: ViewportSize.NoViewport when creating your context.

You can pass custom args, but some arguments are required to run Playwright.

We strongly recommend to run tests with a fixed viewport, since on your CI or coworkers environment the screen resolution might be different and your site which you are testing will behave differently.

kabdul-incomm commented 12 months ago

You don't need to remove all the arguments when you want to maximise the window. Its enough to do the following steps:

  1. Pass "--start-maximized" as a browser launch arg (don't use IgnoreAllDefaultArgs)
  2. Set ViewportSize: ViewportSize.NoViewport when creating your context.

You can pass custom args, but some arguments are required to run Playwright.

We strongly recommend to run tests with a fixed viewport, since on your CI or coworkers environment the screen resolution might be different and your site which you are testing will behave differently.

Thank you. Above prescribed solution worked. Hence I suggest you to close the ticket.

 var playwright = await Microsoft.Playwright.Playwright.CreateAsync();
            var headless = Convert.ToBoolean(ConfigurationData.GetAppSetting("HeadlessModeEnabled"));
            IBrowser? browser;
            if (!headless)
            {
                browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
                {
                    Headless = headless,
                    Args = new[]
                    {
                        "--start-maximized"
                    }
                });
                var context = await browser.NewContextAsync(new BrowserNewContextOptions() { ViewportSize = ViewportSize.NoViewport });
                _Page = await context.NewPageAsync();
            }
            else
            {
                browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
                {
                    Headless = headless
                });
                _Page = await browser.NewPageAsync();
            }
            _Page.SetDefaultTimeout((float)60000);
            return _Page;

My application has three mode (mobile, tablet and computer) and in each of this mode the application has different options hence I was looking for computer option.