Trace: fetch/XHR response bodies hidden in the player on Safari (content.mimeType is empty)

未關閉 適合新手
#586 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@SergeyPirogov 已經在處理了。

開始於 2026年11月22日。

  • #587 來自 @SergeyPirogov —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
72/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
typescript
領域
tooling

研究方向

從 packages/trace/src/trace-har.ts 第 138 行附近的 content.mimeType 指派開始,該處只讀取 entry.response?.mimeType。檢查頁面收集器的 responseHeaders 如何傳到該筆項目,然後加入回退到 content-type 標頭的邏輯,並去除其中的所有參數。完成的標準是:來自 Safari 追蹤的 fetch/XHR 項目能取得文字類型的 mimeType,且其回應內容會顯示在 Network 分頁中;一個只提供 responseHeaders 的項目經過轉換器處理的測試可以驗證這一點。

由索引模型根據 Issue 內容生成。

描述

What happens

In trace mode on iOS Safari (Appium XCUITest, no WebDriver BiDi), the Network tab of show-trace shows response headers for the page's fetch/XHR calls, but never the response body.

The body is in the trace. The resource-snapshot entries in trace.network carry response.content.text (or _sha1 with the file under resources/), and response.headers contains content-type: application/json. But response.content.mimeType is "":

"response": {
  "status": 200,
  "headers": [{ "name": "content-type", "value": "application/json" }, ...],
  "content": { "size": 1297, "mimeType": "", "text": "{\"id\":...}", "_sha1": "..." }
}

The player only reads a body when the mime type is textual (/json|xml|javascript|ecmascript|^text\// in the trace parser, for both inline text and _sha1), so every body is dropped.

Cause

packages/trace/src/trace-har.ts:138

const mimeType = entry.response?.mimeType ?? ''

The requests the page collector records (the fetch/XHR patch that serves Safari and Appium sessions) carry responseHeaders but no response.mimeType. With no fallback, content.mimeType ends up empty.

Suggested fix

Fall back to the content-type header:

const headers = entry.response?.headers ?? entry.responseHeaders
const mimeType =
  entry.response?.mimeType ||
  String(headers?.['content-type'] ?? '').split(';')[0].trim()

We applied the same change as a local patch to the built dist/index.js. After it, all 21 fetch/XHR entries in our trace have mimeType: application/json, and their bodies are readable. Setting response.mimeType where the collector's requests are ingested would fix it at the source too.

Environment

  • @wdio/devtools-service 11.2.0 (@wdio/devtools-app 1.13.0), WebdriverIO 9.33.1
  • Appium 3.5, XCUITest driver 12.22.8, iOS 18.6 Simulator, Safari
  • Service options: { mode: 'trace', traceFormat: 'zip', traceGranularity: 'spec' }
主要語言
TypeScript
星號
10
分支
4
平均合併
1 天 11 小時
30 天內合併 PR
76

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

webdriverio/devtools 的其他 Issue

查看 webdriverio/devtools 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。