[Bug]: tracing.stop(path=...) and record_har_path ignore os.chdir() for relative paths

Open Beginner friendly
#3,361 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
testing

Research direction

The reporter points at Artifact.save_as, which already absolutizes its path before sending it to the driver; start there and see how it does it. Then find the two places that serialize tracing.stop(path=...) and the record_har_path context option to the driver and give them the same treatment. The repro script in the issue is the check: after os.chdir(target), trace.zip and rel.har should land in the new cwd just like shot.png does, in both the sync and async APIs.

Written by the indexing model from the issue text.

Description

Version

1.65.2 (same on 1.64.0)

Steps to reproduce

Relative paths for traces and HARs are resolved against the directory the driver was started in, not the current one. Screenshots use the current one, so in one script the files end up in two places:

import os, tempfile
from playwright.sync_api import sync_playwright

start = os.getcwd()
with sync_playwright() as p:
    target = tempfile.mkdtemp()
    os.chdir(target)
    ctx = p.chromium.launch().new_context(record_har_path="rel.har")
    ctx.tracing.start()
    page = ctx.new_page()
    page.goto("data:text/html,x")
    ctx.tracing.stop(path="trace.zip")
    page.screenshot(path="shot.png")
    ctx.close()
    for f in ("trace.zip", "rel.har", "shot.png"):
        print(f, os.path.exists(os.path.join(target, f)), os.path.exists(os.path.join(start, f)))
Expected behavior

All three files in target.

Actual behavior
trace.zip False True
rel.har False True
shot.png True False

Hits anyone using monkeypatch.chdir() with a session-scoped playwright. Artifact.save_as already makes the path absolute before sending it; tracing and HAR don't.

Additional context

No response

Environment
- Operating System: macOS 27.2
- CPU: arm64
- Browser: Chromium
- Python Version: 3.14
- Other info:
Dominant language
Python
Stars
15.1k
Forks
1.3k
Avg merge
6h 16m
Merged PRs (30d)
53

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/playwright-python

All issues in microsoft/playwright-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.