Skip to content

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

Merged
Yury Semikhatsky (yury-s) merged 1 commit into
microsoft:mainfrom
hbenl:reimplement-sendtext
Jul 10, 2026
Merged

chore(bidi): reimplement RawKeyboard.sendText()#41637
Yury Semikhatsky (yury-s) merged 1 commit into
microsoft:mainfrom
hbenl:reimplement-sendtext

Conversation

@hbenl

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.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

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?

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.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@hbenl

Holger Benl (hbenl) commented Jul 7, 2026

Copy link
Copy Markdown
CollaboratorAuthor

Yury Semikhatsky (@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.

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
CollaboratorAuthor

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

Copy link
Copy Markdown
Member

Yury Semikhatsky (@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

Copy link
Copy Markdown
CollaboratorAuthor

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).

@github-actions

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

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.

@yury-s

Copy link
Copy Markdown
Member

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

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

Holger Benl (@hbenl) bumping this up. Do you think the implementation could benefit from a native support of insert text in the Bidi protocol? Quick search didn't return any issues about it.

@yury-s
Yury Semikhatsky (yury-s) merged commit 3717f69 into microsoft:mainJul 10, 2026
46 of 49 checks passed
@hbenl

Copy link
Copy Markdown
CollaboratorAuthor

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

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

Holger Benl (@hbenl) bumping this up. Do you think the implementation could benefit from a native support of insert text in the Bidi protocol? Quick search didn't return any issues about it.

I haven't found any significant downsides with this implementation but I've opened an issue to see if there's interest to add this to Bidi: w3c/webdriver-bidi#1133

Sign up for freeto 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

@hbenl@yury-s