Skip to content

Commit 17e83ae

Browse files
committed
clipboard defined only in secure context; paste should deselect
1 parent d0b6936 commit 17e83ae

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

page/keyboard.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ function deselect() {
274274
sendSystemEventToKeyboard({ type: 'DESELECT' })
275275
}
276276

277-
let buffer = '' // A fallback for paste if user rejects permission.
277+
let buffer = '' // A fallback for paste if user rejects permission or context is insecure.
278278

279279
function copy(remove: boolean) {
280280
const input = getInputElement()
@@ -283,7 +283,7 @@ function copy(remove: boolean) {
283283
}
284284
const { selectionStart, selectionEnd } = input
285285
buffer = input.value.slice(selectionStart!, selectionEnd!)
286-
navigator.clipboard.writeText(buffer)
286+
navigator.clipboard?.writeText(buffer) // clipboard is undefined in insecure context.
287287
if (remove) {
288288
updateInput(input, input.value.slice(0, selectionStart!) + input.value.slice(selectionEnd!), selectionStart!)
289289
deselect()
@@ -300,6 +300,7 @@ async function paste() {
300300
if (input && text) {
301301
replaceSelection(input, text)
302302
}
303+
deselect()
303304
}
304305

305306
export function createKeyboard() {

tests/test-simulate.mobile.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ test('Clipboard', async ({ page }) => {
280280
}
281281
await expect(textarea).toHaveValue('a')
282282
expect(await getSelection(textarea)).toEqual([1, 1])
283+
284+
await left.tap()
285+
expect(await getSelection(textarea), 'Should deselect after paste').toEqual([0, 0])
283286
})
284287

285288
test('Backspace', async ({ page }) => {

0 commit comments

Comments
 (0)