Skip to content

chore(bidi): reimplement RawKeyboard.sendText()#41637

Open
hbenl wants to merge 1 commit into
microsoft:mainfrom
hbenl:reimplement-sendtext
Open

chore(bidi): reimplement RawKeyboard.sendText()#41637
hbenl wants to merge 1 commit into
microsoft:mainfrom
hbenl:reimplement-sendtext

Conversation

@hbenl

@hbenl hbenl commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Bidi doesn't have a protocol method corresponding to CDP's Input.insertText, so this was emulated using keyboard actions. However, this emits key* events that are not expected for Keyboard.insertText(), breaking several tests.
This implementation tries to emulate CDP's Input.insertText behavior more closely.

Fixes the following tests:

  • page/page-fill.spec.ts:
    • "should not double-fill in contenteditable with beforeinput handler in Firefox"
  • tests/page/page-keyboard.spec.ts:
    • "should send a character with insertText"
    • "insertText should only emit input event"

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@hbenl hbenl force-pushed the reimplement-sendtext branch from f59dcb9 to 1343e6d Compare July 6, 2026 13:54
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@yury-s yury-s left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good except for putting Bidi-specific script into a separate extension.

This implementation tries to emulate CDP's Input.insertText behavior more closely.

Are there any plans to have such method in Bidi protocol?

Comment thread packages/injected/src/injectedScript.ts Outdated
return 'needsinput'; // Still need to input the value.
}

insertText(text: string): Element | undefined {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is only used in Bidi, it should go in its own script/module. You can call browserContext.extendInjectedScript() to add extra logic.

@hbenl hbenl force-pushed the reimplement-sendtext branch from 1343e6d to e25d3f6 Compare July 7, 2026 10:21
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@hbenl

hbenl commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

@yury-s I tried using browserContext.extendInjectedScript() but it breaks the test "should avoid side effects upon disconnect". Even without this PR, after adding

promises.push(this.extendInjectedScript(`module.exports = { default: () => class C {} };`));

to BidiBrowserContext.initialize() or to CRBrowserContext.initialize() (verifying that this is not a Firefox/Bidi specific issue), the test fails.

Comment thread packages/injected/src/injectedScript.ts Outdated
return 'needsinput'; // Still need to input the value.
}

bidiInsertText?: (text: string) => Element | undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid adding this to the main script? packages/injected/src/recorder/pollingRecorder.ts adds a rich API and doesn't leak any of it into the main InjectedScript, let's employ the same approach here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll do that.

@yury-s

yury-s commented Jul 8, 2026

Copy link
Copy Markdown
Member

@yury-s I tried using browserContext.extendInjectedScript() but it breaks the test "should avoid side effects upon disconnect". Even without this PR, after adding

promises.push(this.extendInjectedScript(`module.exports = { default: () => class C {} };`));

to BidiBrowserContext.initialize() or to CRBrowserContext.initialize() (verifying that this is not a Firefox/Bidi specific issue), the test fails.

Hmm, doesn't fail for me when I run the test with this change (in chromium). Are you sure there are no other changes?

@hbenl

hbenl commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

Hmm, doesn't fail for me when I run the test with this change (in chromium).

I found the root cause (see #41706) and it's a very subtle race condition - the timing needs to be just right to trigger it, so it's not surprising that it's hard to reproduce (it's rather surprising that it reproduces so well on my machine, although I could get the test to pass by adding a delay of 1 millisecond to it).

@hbenl hbenl force-pushed the reimplement-sendtext branch from e25d3f6 to d1bfcba Compare July 9, 2026 13:40
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Test results for "MCP"

2 failed
❌ [chromium] › mcp/http.spec.ts:104 › http transport browser lifecycle (isolated) @mcp-ubuntu-latest-chromium
❌ [firefox] › mcp/http.spec.ts:104 › http transport browser lifecycle (isolated) @mcp-ubuntu-latest-firefox

7733 passed, 1248 skipped


Merge workflow run.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

4 flaky ⚠️ [chromium-library] › library/chromium/chromium.spec.ts:371 › should produce network events, routing, and annotations for Service Worker `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/popup.spec.ts:260 › should not throw when click closes popup `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/video.spec.ts:717 › screencast › should work with video+trace `@chromium-ubuntu-22.04-node24`
⚠️ [chromium-library] › library/video.spec.ts:717 › screencast › should work with video+trace `@chromium-ubuntu-22.04-node22`

49512 passed, 1161 skipped


Merge workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants