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

オープン 初心者向け
#3,361 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
testing

調査の方向性

報告者は Artifact.save_as を指摘しており、これはドライバーに送る前にすでにパスを絶対化しています。そこから始めて、それがどのように行っているかを確認してください。次に、tracing.stop(path=...) と record_har_path コンテキストオプションをドライバーにシリアライズしている 2 か所を見つけ、同じ扱いをしてください。issue 内の再現スクリプトがチェックです。os.chdir(target) の後、trace.zip と rel.har は、sync と async の両方の API で、shot.png と同様に新しい cwd に置かれるはずです。

索引モデルが issue の本文から書いたものです。

説明

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:
主要言語
Python
スター
15.1k
フォーク
1.3k
平均マージ
6時間 16分
マージ済み PR(30日)
53

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/playwright-python のほかの issue

microsoft/playwright-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。