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]: Calling BrowserContext.close() throws "Invalid String Length" #2771

Open
pamalite opened this issue Mar 10, 2025 · 1 comment
Open

Comments

@pamalite
Copy link

Version

1.50.0

Steps to reproduce

  1. Create a new BrowserContext by setting it to record HAR:
pw = sync_playwright().start()
browser = pw.chromium.launch(traces_dir = ".\\some\\directory")
context = browser.context(record_har_path = ".\\some\\directory")
page = context.new_page()
page.goto("https://www.bing.com")
  1. Interact with the browser; OR sleep the script and let the browser stay for a few seconds.
  2. Stop the script:
context.close()
browser.close()
pw.stop()
  1. The Error will be thrown on context.close() line.

Expected behavior

No errors thrown and HAR file generated.

Actual behavior

The following error is thrown:

  File "E:\project\BrowserLauncher.py", line 107, in _close_playwright
    self._context.close()
  File "E:\project\venv\lib\site-packages\playwright\sync_api\_generated.py", line 13474, in close
    return mapping.from_maybe_impl(self._sync(self._impl_obj.close(reason=reason)))
  File "E:\project\venv\lib\site-packages\playwright\_impl\_sync_base.py", line 115, in _sync
    return task.result()
  File "E:\project\venv\lib\site-packages\playwright\_impl\_browser_context.py", line 598, in close
    await self._channel._connection.wrap_api_call(_inner_close, True)
  File "E:\project\venv\lib\site-packages\playwright\_impl\_connection.py", line 528, in wrap_api_call
    raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
playwright._impl._errors.Error: : Invalid string length

No HAR file generated.

Additional context

No response

Environment

- Operating System: Windows 10
- CPU: Core i9
- Browser: Chromium
- Python Version: 3.10
- Other info:
@mxschmitt
Copy link
Member

The script does not work for me. Would it be possible to provide exact reproduction steps and a entire script we can just run using python test.py? Thanks.

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

No branches or pull requests

2 participants