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

ignoreDefaultArgs launch parameter is broken #189

Closed
Granitosaurus opened this issue Sep 14, 2020 · 11 comments · Fixed by #190
Closed

ignoreDefaultArgs launch parameter is broken #189

Granitosaurus opened this issue Sep 14, 2020 · 11 comments · Fixed by #190
Labels

Comments

@Granitosaurus
Copy link

Granitosaurus commented Sep 14, 2020

I'm trying to disable default launch arguments however when this parameter is set to True one of two things happen:

browser: Browser = chromium.launch(ignoreDefaultArgs=True)

will break with:

  File "/home/user/.local/lib/python3.8/site-packages/playwright/browser_type.py", line 66, in launch
    normalize_launch_params(params)
  File "/home/user/.local/lib/python3.8/site-packages/playwright/browser_type.py", line 140, in normalize_launch_params
    params["env"] = {name: str(value) for [name, value] in params["env"].items()}
KeyError: 'env'

I've made a hotfix patch here Granitosaurus@2dc0e10 now the browser launches fine but timesout on launch() call:

Traceback (most recent call last):
  File "/home/user/.local/lib/python3.8/site-packages/playwright/browser_type.py", line 68, in launch
    return from_channel(await self._channel.send("launch", params))
  File "/home/user/.local/lib/python3.8/site-packages/playwright/connection.py", line 39, in send
    result = await callback.future
  File "/usr/lib/python3.8/asyncio/futures.py", line 260, in __await__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.8/asyncio/tasks.py", line 349, in __wakeup
    future.result()
  File "/usr/lib/python3.8/asyncio/futures.py", line 178, in result
    raise self._exception
playwright.helper.TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================
<launching> /home/user/.cache/ms-playwright/chromium-799411/chrome-linux/chrome 
<launched> pid=301672
[err] [301699:301699:0914/061714.839670:ERROR:sandbox_linux.cc(374)] InitializeSandbox() called with multiple threads in process gpu-process.
@Granitosaurus
Copy link
Author

Granitosaurus commented Sep 14, 2020

I thought it might be hanging because some of browser flags were required but I popped the defaults from playwright repo here https://github.com/microsoft/playwright/blob/ed3b00efdf0d2e44fc667ade8298ac6d504109bf/src/server/chromium/chromium.ts#L151 and passed them to launch(args=) and unfortunately it's still timing out on launch:

browser_args = [
  '--disable-background-networking',
  '--enable-features=NetworkService,NetworkServiceInProcess',
  '--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',
  # BlinkGenPropertyTrees disabled due to crbug.com/937609
  '--disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies,LazyFrameLoading',
  '--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',
]
pw.chromium.launch(args=browser_args, ignoreDefaultArgs=True)
# or 
pw.chromium.launch(args=['--enable-automation'], ignoreDefaultArgs=True)
# alternatively passing this list to ignoreDefaultArgs doesn't seem to disable the flags.
pw.chromium.launch(ignoreDefaultArgs=browser_args)

From what I understand here:

pw.chromium.launch(args=browser_args, ignoreDefaultArgs=True)
# should be equivalent of 
pw.chromium.launch()

@mxschmitt
Copy link
Member

Hi, thanks for reporting and digging into that issue. I created a patch to fix this behaviour.

@Granitosaurus
Copy link
Author

I've tried the patched branch and it fixes the first error but it still hangs indefinitely if started with ignoreDefaultArgs=True

@mxschmitt
Copy link
Member

I've tried the patched branch and it fixes the first error but it still hangs indefinitely if started with ignoreDefaultArgs=True

Yeah since it probably removes some arguments which we need internally. What are you trying to archive? Does maybe ignoring a selection of arguments help you?

@Granitosaurus
Copy link
Author

Maybe my default argument list is incorrect but assuming it is correct shouldn't:

pw.chromium.launch(args=browser_args, ignoreDefaultArgs=True)
# be equivalent of 
pw.chromium.launch()

I'm trying to debug some unusual behavior I see in playwright's browser but not in desktop browser. Presumably it's being caused by one of these flags. For example launch(ignoreDefaultArgs=['--incognito']) still starts the browser in incognito mode, with launch(ignoreDefaultArgs=True) the browser starts in normal mode but hangs. Seems like ignore list of arguments doesn't work?

@mxschmitt
Copy link
Member

Maybe my default argument list is incorrect but assuming it is correct shouldn't:

pw.chromium.launch(args=browser_args, ignoreDefaultArgs=True)
# be equivalent of 
pw.chromium.launch()

I'm trying to debug some unusual behavior I see in playwright's browser but not in desktop browser. Presumably it's being caused by one of these flags. For example launch(ignoreDefaultArgs=['--incognito']) still starts the browser in incognito mode, with launch(ignoreDefaultArgs=True) the browser starts in normal mode but hangs. Seems like ignore list of arguments doesn't work?

We unfortunately require the usage of an incognito tab internally: microsoft/playwright#2071

@Granitosaurus
Copy link
Author

The patch doesn't fix the issue though.
I could not get any of the ignoreDefaultArgs functions working, none of the flags passed to ignoreDefaultArgs are ignored and setting it to True even by supplying all of the upstream default flags manually hangs the process. Did I miss something? 😬

Additionally I think it would be great to document default browser launch flags (DefaultArgs) somewhere because now it's extremely difficult to debug why playwright browser is seeing different page compared to the user i.e. it's hard to use as a testing framework if it cannot properly simulate user.

@mxschmitt
Copy link
Member

I tried it and for me it's working. (Tested ignoreDefaultArgs: ['--mute-audio']
and checked the launch internally by setting the DEBUG=pw* env var.)

Maybe launchPersistentContext fits for your needs?

Why different? Would be great to know why the behavior is different. And which behavior.

Thanks!

@humanperzeus
Copy link

im running into the issue that i can't set the browser size via args what's wrong with the command?

browser_args = ['viewport: {width: 1280, height: 720}']
browser = await playwright.webkit.launch(headless=False, args=browser_args)

@mxschmitt
Copy link
Member

You can set the viewport when creating a context: https://playwright.dev/#version=v1.5.2&path=docs%2Fapi.md&q=browsernewcontextoptions--options-viewport-width

So

browser.newContext(viewport={
    "width": 1280,
    "height": 720,
})

should work. Is this what you want?

@maxktz
Copy link

maxktz commented Aug 7, 2024

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

Successfully merging a pull request may close this issue.

4 participants