Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 1.30 & 1.31 cmd open up with headless (pyinstaller) #1778

Closed
treb00 opened this issue Feb 22, 2023 · 8 comments · Fixed by #2004
Closed

[BUG] 1.30 & 1.31 cmd open up with headless (pyinstaller) #1778

treb00 opened this issue Feb 22, 2023 · 8 comments · Fixed by #2004

Comments

@treb00
Copy link

treb00 commented Feb 22, 2023

  • Playwright Version: now 1.29
  • Operating System: Windows
  • Python version: 3.10
  • Browser: tested only chromium

Using playwright with headless mode. When I run the script without builded edition it runs fine in headless mode, no popup, no nothing. However, when I build with pyinstaller and I also use these flags: --noconsole --excelude-module cmd -F and using with sync_playwright() as p: in 1.30 and 1.31 cmds popping up. In 1.30 only one empty cmd pops up, in 1.31 multiple windows appear. If I revert back to 1.29 this problem does not occur.

@mxschmitt
Copy link
Member

to reproduce:

  1. create a small python script with Playwright
  2. pythonw.exe test.py

expected: no window
actual: window shown

to fix it we could add creationflags=asyncio.subprocess.CREATE_NO_WINDOW inside _transport.py but that regresses other stuff.

@mxschmitt
Copy link
Member

1.31.1 will have less/no windows on windows with normal setup. The pythonw issue still remains.

@DuxSec
Copy link

DuxSec commented May 27, 2023

Is there any fix available for the cmd window pop ups?
I am on version 1.31.2.
Does the new version resolve this?

@erma0
Copy link

erma0 commented May 27, 2023

Is there any fix available for the cmd window pop ups? I am on version 1.31.2. Does the new version resolve this?

Not yet, but you can edit the create_subprocess_exec function for file playwright/_impl/_transport.py on your local machine, just add one arg like this:
creationflags=134217728 if sys.platform == "win32" else 0,
Then using pyinstaller -w will work fine

@DuxSec
Copy link

DuxSec commented May 27, 2023

Is there any fix available for the cmd window pop ups? I am on version 1.31.2. Does the new version resolve this?

Not yet, but you can edit the create_subprocess_exec function for file playwright/_impl/_transport.py on your local machine, just add one arg like this: creationflags=134217728 if sys.platform == "win32" else 0, Then using pyinstaller -w will work fine

Thank you, this works fantasic!
Does this number 134217728 have any influence or is it just random?

@erma0
Copy link

erma0 commented May 28, 2023

Is there any fix available for the cmd window pop ups? I am on version 1.31.2. Does the new version resolve this?

Not yet, but you can edit the create_subprocess_exec function for file playwright/_impl/_transport.py on your local machine, just add one arg like this: creationflags=134217728 if sys.platform == "win32" else 0, Then using pyinstaller -w will work fine

Thank you, this works fantasic! Does this number 134217728 have any influence or is it just random?

This is the constant subprocess.CREATE_NO_WINDOW

@mxschmitt
Copy link
Member

We should probably do the following:

            startupinfo = None
            if sys.platform == "win32":
                startupinfo = subprocess.STARTUPINFO()
                startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
                startupinfo.wShowWindow = subprocess.SW_HIDE

            self._proc = await asyncio.create_subprocess_exec(
                str(self._driver_executable),
                "run-driver",
                stdin=asyncio.subprocess.PIPE,
                stdout=asyncio.subprocess.PIPE,
                stderr=_get_stderr_fileno(),
                limit=32768,
                env=env,
                startupinfo=startupinfo,
            )

@farshadz1997
Copy link

We should probably do the following:

            startupinfo = None
            if sys.platform == "win32":
                startupinfo = subprocess.STARTUPINFO()
                startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
                startupinfo.wShowWindow = subprocess.SW_HIDE

            self._proc = await asyncio.create_subprocess_exec(
                str(self._driver_executable),
                "run-driver",
                stdin=asyncio.subprocess.PIPE,
                stdout=asyncio.subprocess.PIPE,
                stderr=_get_stderr_fileno(),
                limit=32768,
                env=env,
                startupinfo=startupinfo,
            )

Hello

thank you for this snippet, it would be awesome if you add this in the following versions of Playwright.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants