microsoft / playwright-java

Java version of the Playwright testing and automation library
https://playwright.dev/java/
Apache License 2.0
1.16k stars 209 forks source link

Playwright failing in Windows Server 2019 based Docker container #782

Closed aarushiag closed 2 years ago

aarushiag commented 2 years ago

Context:

Code Snippet

import com.microsoft.playwright.*;

public class ExampleReproducible {
  public static void main(String[] args) {
    try (Playwright playwright = Playwright.create()) {
      BrowserType.LaunchOptions browserLaunchOptions = new BrowserType.LaunchOptions().setArgs(Arrays.asList("--disable-web-security")).setChromiumSandbox(false);

      Browser browser = playwright.chromium.launch(setBrowserExecutable(browserLaunchOptions));
      BrowserContext context = browser.newContext();

      Page page = context.newPage();
    }
  }
}

Describe the bug

Playwright is not working within dockerized environment in Windows Server 2019. The error is thrown while creating new page - Page page = context.newPage() . Strangely the same code snippet doesn't throw any error on the host machine which again has the same OS version (Microsoft Windows Server 2019 Standard). This was tried both by setting PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD as 1 and 0. Is there any dependency which can be possibly missing inside the container and should be installed explicitly for playwright to work?

UPDATE - The container was missing basic windows fonts. After installing the fonts, the issue was resolved. Are fonts a basic requirement for playwright library to work in Windows env? I remember using playwright in a linux based image (which also didn't have basic fonts) without facing such issues. Can we expect to have similar behaviour in Windows ?

Error Log

C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\server\chromium\crPage.js:445
      this._firstNonInitialNavigationCommittedReject(new Error('Page closed'));
                                                     ^

Error: Page closed
    at CRSession.<anonymous> (C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\server\chromium\crPage.js:445:54)
    at Object.onceWrapper (node:events:509:28)
    at CRSession.emit (node:events:402:35)
    at C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\server\chromium\crConnection.js:253:39
Exception in thread "main" com.microsoft.playwright.PlaywrightException: Error {
  message='Browser closed.
==================== Browser output: ====================
<launching> C:\Users\ContainerAdministrator\AppData\Local\ms-playwright\chromium-939194\chrome-win\chrome.exe --disable-background-networking --enable-features=NetworkService,NetworkServi
ceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --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,DestroyProfileOnBrowser
Close,MediaRouter,AcceptCHFrame --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-ba
ckgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --headles
s --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --disable-web-security --disable-ipc-f
looding-protection --user-data-dir=C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright_chromiumdev_profile-YX0WHs --remote-debugging-pipe --no-startup-window
<launched> pid=11396
[pid=11396][err] [0119/200410.915:ERROR:network_change_notifier_win.cc(227)] WSALookupServiceBegin failed with: 0
[pid=11396][err] [0119/200410.962:ERROR:platform_font_skia.cc(344)] Could not find any font: Segoe UI, sans. Falling back to the default
  name='Error
  stack='Error: Browser closed.
==================== Browser output: ====================
<launching> C:\Users\ContainerAdministrator\AppData\Local\ms-playwright\chromium-939194\chrome-win\chrome.exe --disable-background-networking --enable-features=NetworkService,NetworkServi
ceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --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,DestroyProfileOnBrowser
Close,MediaRouter,AcceptCHFrame --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-ba
ckgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --headles
s --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --disable-web-security --disable-ipc-f
looding-protection --user-data-dir=C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright_chromiumdev_profile-YX0WHs --remote-debugging-pipe --no-startup-window
<launched> pid=11396
[pid=11396][err] [0119/200410.915:ERROR:network_change_notifier_win.cc(227)] WSALookupServiceBegin failed with: 0
[pid=11396][err] [0119/200410.962:ERROR:platform_font_skia.cc(344)] Could not find any font: Segoe UI, sans. Falling back to the default
    at C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\server\chromium\crConnection.js:204:16
    at new Promise (<anonymous>)
    at CRSession.send (C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\server\chromium\crConnection.js:200:12)
    at CRBrowserContext.newPageDelegate (C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\server\chromium\crBrowser.js:385:38)
    at CRBrowserContext.newPage (C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\server\browserContext.js:327:37)
    at BrowserContextDispatcher.newPage (C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\dispatchers\browserContextDispatcher.js:145:67)
    at DispatcherConnection.dispatch (C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\dispatchers\dispatcher.js:352:46)
}
        at com.microsoft.playwright.impl.WaitableResult.get(WaitableResult.java:54)
        at com.microsoft.playwright.impl.ChannelOwner.runUntil(ChannelOwner.java:103)
        at com.microsoft.playwright.impl.Connection.sendMessage(Connection.java:115)
        at com.microsoft.playwright.impl.ChannelOwner.sendMessage(ChannelOwner.java:94)
        at com.microsoft.playwright.impl.ChannelOwner.sendMessage(ChannelOwner.java:90)
        at com.microsoft.playwright.impl.BrowserContextImpl.newPageImpl(BrowserContextImpl.java:323)
        at com.microsoft.playwright.impl.BrowserContextImpl.lambda$newPage$12(BrowserContextImpl.java:316)
        at com.microsoft.playwright.impl.LoggingSupport.withLogging(LoggingSupport.java:47)
        at com.microsoft.playwright.impl.ChannelOwner.withLogging(ChannelOwner.java:79)
        at com.microsoft.playwright.impl.BrowserContextImpl.newPage(BrowserContextImpl.java:316)
        at com.microsoft.playwright.impl.BrowserContextImpl.newPage(BrowserContextImpl.java:47)
        at TestHTML2PDF.test_html2pdf_withZip(TestHTML2PDF.java:26)
        at TestHTML2PDF.test_zip(TestHTML2PDF.java:109)
        at TestHTML2PDF.test_flaky_zip(TestHTML2PDF.java:117)
        at TestHTML2PDF.main(TestHTML2PDF.java:227)
Caused by: com.microsoft.playwright.impl.DriverException: Error {
==================== Browser output: ====================
<launching> C:\Users\ContainerAdministrator\AppData\Local\ms-playwright\chromium-939194\chrome-win\chrome.exe --disable-background-networking --enable-features=NetworkService,NetworkServi
ceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --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,DestroyProfileOnBrowser
Close,MediaRouter,AcceptCHFrame --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-ba
ckgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --headles
s --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --disable-web-security --disable-ipc-f
looding-protection --user-data-dir=C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright_chromiumdev_profile-YX0WHs --remote-debugging-pipe --no-startup-window
<launched> pid=11396
[pid=11396][err] [0119/200410.915:ERROR:network_change_notifier_win.cc(227)] WSALookupServiceBegin failed with: 0
[pid=11396][err] [0119/200410.962:ERROR:platform_font_skia.cc(344)] Could not find any font: Segoe UI, sans. Falling back to the default
  name='Error
  stack='Error: Browser closed.
==================== Browser output: ====================
<launching> C:\Users\ContainerAdministrator\AppData\Local\ms-playwright\chromium-939194\chrome-win\chrome.exe --disable-background-networking --enable-features=NetworkService,NetworkServi
ceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --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,DestroyProfileOnBrowser
Close,MediaRouter,AcceptCHFrame --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-ba
ckgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --headles
s --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --disable-web-security --disable-ipc-f
looding-protection --user-data-dir=C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright_chromiumdev_profile-YX0WHs --remote-debugging-pipe --no-startup-window
<launched> pid=11396
[pid=11396][err] [0119/200410.915:ERROR:network_change_notifier_win.cc(227)] WSALookupServiceBegin failed with: 0
[pid=11396][err] [0119/200410.962:ERROR:platform_font_skia.cc(344)] Could not find any font: Segoe UI, sans. Falling back to the default
    at C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\server\chromium\crConnection.js:204:16
    at new Promise (<anonymous>)
    at CRSession.send (C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\server\chromium\crConnection.js:200:12)
    at CRBrowserContext.newPageDelegate (C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\server\chromium\crBrowser.js:385:38)
    at CRBrowserContext.newPage (C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\server\browserContext.js:327:37)
    at BrowserContextDispatcher.newPage (C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\dispatchers\browserContextDispatcher.js:145:67)
    at DispatcherConnection.dispatch (C:\Users\ContainerAdministrator\AppData\Local\Temp\playwright-java-1794132438023527265\package\lib\dispatchers\dispatcher.js:352:46)
}
        at com.microsoft.playwright.impl.Connection.dispatch(Connection.java:228)
        at com.microsoft.playwright.impl.Connection.processOneMessage(Connection.java:208)
        at com.microsoft.playwright.impl.ChannelOwner.runUntil(ChannelOwner.java:101)
        ... 13 more
yury-s commented 2 years ago

This is the same issue as https://github.com/microsoft/playwright/issues/10036

The container was missing basic windows fonts. After installing the fonts, the issue was resolved. Are fonts a basic requirement for playwright library to work in Windows env?

Yes, the browser may fail without those fonts and they are apparently not shipped with windows server by default. For now you can either install the fonts manually or you can use our official docker linux image, we don't have one for Windows.

Can we expect to have similar behaviour in Windows ?

We can probably install missing fonts similar to how we install media pack on windows server. (cc @aslushnikov)

After installing the fonts, the issue was resolved.

Did you install some standard windows pack or downloaded the fonts from another source?

aarushiag commented 2 years ago

Thanks @yury-s for the clarification.

We can probably install missing fonts similar to how we install media pack on windows server. (cc @aslushnikov)

Could you clarify what media pack are you talking about ? Does playwright/browser install some fonts in case of linux? I wasn't able to see any fonts installed in the linux system while using playwright.

Did you install some standard windows pack or downloaded the fonts from another source?

We installed the standard windows pack. (We copied the ttf/otf files from the host system and registered them just to check the workflow (I understand this won't be a long term solution from the perspective of licensing)

yury-s commented 2 years ago

Could you clarify what media pack are you talking about ?

Server-Media-Foundation that we install automatically when running playwright on Windows Server.

Does playwright/browser install some fonts in case of linux?

Yes, it does install some fonts as native dependencies.

yury-s commented 2 years ago

We need more information to act on this report. Please file a new one and link to this issue when you get back to it!

aarushiag commented 2 years ago

Hi @yury-s , could you please suggest from where we can install the - Server-Media-Foundation package in Windows Server ?