[Bug]: Recorder/codegen and page bindings break when the page defines Array.prototype.toJSON
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 68/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- javascript, typescript
調査の方向性
bindingsController.ts と、レポートで説明されている PageBinding.dispatch パスから始め、Chromium をインストールした後、リンクされた repro.spec.ts の再現コードを実行します。ページの Array.prototype.toJSON が binding payload をどのように変更するかを追跡し、recorder のクリックが serializedArgs エラーなしで記録されることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Version
1.61.0
Steps to reproduce
Recorder:
- Run
npx playwright codegenand navigate to any page (evenabout:blank). - In the browser's DevTools Console, paste the kind of serializer Prototype.js installs:
Array.prototype.toJSON = function () { var results = []; this.forEach(function (value) { results.push(typeof value === 'object' ? JSON.stringify(value) : String(value)); }); return '[' + results.join(', ') + ']'; }; - Click any element. Recording stops with the error below.
Deterministic (no UI): minimal repo https://github.com/whgksqls9999/pw-tojson-recorder-repro
git clone https://github.com/whgksqls9999/pw-tojson-recorder-repro
cd pw-tojson-recorder-repro
npm install
npx playwright install chromium
npx playwright test repro.spec.ts
Expected behavior
When an element is clicked, codegen tracks it and records the corresponding action.
Actual behavior
Error: serializedArgs is not an array. This can happen when Array.prototype.toJSON is defined incorrectly
at _PageBinding.dispatch
at _Page.onBindingCalled
at _FrameSession._onBindingCalled
The recorder is unusable on such a page.
Additional context
Root cause: the injected binding controller serializes its payload with the page's JSON.stringify, so a page-defined Array.prototype.toJSON turns the internal serializedArgs array into a string and PageBinding.dispatch rejects it.
I completely understand the decision in #32508 to surface a clear log rather than handle the error. The one thing I'd gently raise is the user experience: a developer whose app has such an incorrect Array.prototype.toJSON override might try codegen, see that clicks do nothing, and — without opening DevTools — assume "maybe this just doesn't fit our app" and move on. That's partly on the developer for not checking, of course, but it can be an easy silent dead end. Would you be open to revisiting this case, or do you feel the current approach is the one to keep?
As a heavily simplified illustration, something like the patch below worked in my testing. If you feel this direction is worth pursuing, I'd be glad to refine it as needed and take the work forward.
[bindingsController.ts]
private _stringifyPayload(payload: BindingPayload): string {
const arrayToJSON = Array.prototype.toJSON;
const objectToJSON = Object.prototype.toJSON;
try {
delete Array.prototype.toJSON;
delete Object.prototype.toJSON;
return JSON.stringify(payload);
} finally {
if (arrayToJSON !== undefined) Array.prototype.toJSON = arrayToJSON;
if (objectToJSON !== undefined) Object.prototype.toJSON = objectToJSON;
}
}
(this._global as any)[this._globalBindingName](
this._stringifyPayload(payload),
);
Environment
System:
OS: Windows 10 Home 10.0.19045
CPU: (16) x64 12th Gen Intel(R) Core(TM) i5-12500H
Memory: 1.54 GB / 15.71 GB
Binaries:
Node: 22.20.0
npm: 10.9.3
npmPackages:
@playwright/test: 1.61.0 => 1.61.0
- 主要言語
- TypeScript
- スター
- 99.1k
- フォーク
- 6.8k
- 平均マージ
- 16時間 3分
- マージ済み PR(30日)
- 315
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/playwright のほかの issue
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
microsoft/playwright#43875 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 18/100
microsoft/playwright#43871 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: A paused clock still fires a timer the page sets while loading対応中かも @microsoft-playwright-automation が今日担当しました。 オープンneeds-triage
難易度 3/5 半日 初心者へのやさしさ 42/100
microsoft/playwright#43869 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[Feature]: Configure web servers per project対応中かも @microsoft-playwright-automation が今日担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
microsoft/playwright#43853 · コメント 4 件 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[Feature]: Extend isVisible/toBeVisible API to include overlap detection対応中かも @microsoft-playwright-automation が今日担当しました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
microsoft/playwright#43849 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
microsoft/playwright の issue をすべて見る
似ている issue
-
feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
calagopus/panel#285 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1時間未満 初心者へのやさしさ 88/100
adobe/react-spectrum#10909 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
Run the dependency drift check対応中かも @spaceninja が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
cloudfour/lighthouse-parade#449 ·
メンテナーはふだん 1 日以内に返信
-
Documentation Enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
JSPrismarine/JSPrismarine#2706 ·
メンテナーはふだん 1 日以内に返信