[Bug]: route.fulfill({ json }) replaces a Content-Type set in headers and sets none for null, false, 0 and ''
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 82/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, typescript
調査の方向性
バグは packages/playwright-core/src/client/network.ts の _innerFulfill にある json 分岐にあり、既存のヘッダーを確認せずに Content-Type を設定し、options.json の truthiness をテストしています。そのすぐ上にある、options.json !== undefined で本文を構築するブロックを読み、2つの条件を比較してください。完了条件は、json に Content-Type があらかじめ設定されている場合はその値を保持し、null、false、0、'' の場合は application/json を送信することです。Chromium、Firefox、WebKit で再現用 spec テスト tests/fulfill-json.spec.ts を使って確認してください。
索引モデルが issue の本文から書いたものです。
説明
Version
1.65.1
Steps to reproduce
- Clone https://github.com/ondraulehla/playwright-repro-fulfill-json-content-type
npm installnpx playwright installnpx playwright test
The repro is one spec file, tests/fulfill-json.spec.ts. Every request is routed, so it needs no server. Each test does this with a different set of options:
await page.route('http://repro.test/data', route => route.fulfill(options));
const result = await page.evaluate(async () => {
const response = await fetch('/data');
return { contentType: response.headers.get('content-type'), body: await response.text() };
});
Expected behavior
The docs for the json option say: "JSON response. This method will set the content type to application/json if not set."
So I'd expect two things:
route.fulfill({ json: { a: 1 }, headers: { 'Content-Type': 'application/problem+json' } })keepsapplication/problem+json, because the content type is already set.route.fulfill({ json: null })responds withapplication/json, and so dofalse,0and'', the same wayjson: 1does. Playwright already serializes the body for them (null,false,0,"").
Actual behavior
18 of the 30 tests fail, the same 6 in Chromium, Firefox and WebKit. The 4 control tests pass in all three.
fulfill options |
Expected | Chromium | Firefox | WebKit |
|---|---|---|---|---|
json: { a: 1 }, headers: { 'content-type': 'application/problem+json' } |
application/problem+json |
application/json |
application/json |
application/json |
json: { a: 1 }, headers: { 'Content-Type': 'application/problem+json' } |
application/problem+json |
application/json |
application/json |
application/json |
json: null |
application/json |
no header | no header | text/plain |
json: false |
application/json |
no header | no header | text/plain |
json: 0 |
application/json |
no header | no header | text/plain |
json: '' |
application/json |
no header | no header | text/plain |
"no header" means response.headers.get('content-type') is null in the page.
I get the same table on macOS and on Linux (Ubuntu 24.04 in Docker).
Additional context
I found this while looking at how the clients pick the content type after #43205, which was the Python side of the second case (json=[] and json={}).
Both cases come from the same block in _innerFulfill in packages/playwright-core/src/client/network.ts:
if (options.contentType)
headers['content-type'] = String(options.contentType);
else if (options.json)
headers['content-type'] = 'application/json';
The json branch doesn't check whether headers already has a content type, and it tests options.json for truthiness. A few lines above, the body is built with options.json !== undefined, which is why the falsy values get a serialized body but no header.
I tried this change against the installed 1.65.1 bundle and all 30 tests pass with it:
else if (options.json !== undefined && !('content-type' in headers))
I'd like to send a PR with the fix and tests if this is approved for a community contribution.
Environment
System:
OS: macOS 26.6.2
CPU: (8) arm64 Apple M1 Pro
Binaries:
Node: 26.5.0 - /opt/homebrew/bin/node
npm: 11.17.0 - /opt/homebrew/bin/npm
npmPackages:
@playwright/test: 1.65.1 => 1.65.1
- 主要言語
- TypeScript
- スター
- 99.7k
- フォーク
- 6.8k
- 平均マージ
- 16時間 10分
- マージ済み PR(30日)
- 301
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/playwright のほかの issue
-
[Bug]: WebKit emits pageerror for native RTCDataChannel send diagnostics without a JS exceptionオープンagent-triage
難易度 5/5 1週間以上 初心者へのやさしさ 45/100
microsoft/playwright#44103 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[MCP]: --extension --background: noDefaults skips focus emulation, hidden tabs get no rAF and clicks time out対応中かも @microsoft-playwright-automation が今日担当しました。 オープンagent-triage
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
microsoft/playwright#44096 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Crash tests fail with the Chromium sandbox on Linux対応中かも @microsoft-playwright-automation が今日担当しました。 オープンagent-triage needs-triage
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
microsoft/playwright#44094 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
api review feedback Nov 11th, 2026対応中かも @luizpaulo-antunes が 1 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 70/100
microsoft/playwright#44062 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: page.evaluate in Chromium never settles when its argument nests 60 objects deep対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンagent-triage
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
microsoft/playwright#44060 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
microsoft/playwright の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
pieterjanscheir/belgica#201 ·
メンテナーはふだん 1 日以内に返信
-
accessibility
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
numerique-gouv/lasuite-landingpage#311 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
oxc-project/tsgolint#1362 ·
メンテナーはふだん 1 日以内に返信
-
bug external xai
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
langchain-ai/langchain#41854 ·
メンテナーはふだん 1 日以内に返信
-
ready-for-agent
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
nemchik/biome-plugin-suitescript#137 ·
メンテナーはふだん 1 日以内に返信