Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Paste (long) text from Clipboard to Textarea using Puppeteer

I am trying to enter some text in a textarea field using Puppeteer.

My approach is to copy the text to the clipboard, then click on the textarea and try to paste it in. However, the text is not added to the input field.

Things I've tried:

  • Using page.type takes a long time because the text is a few thousand characters. I would rather avoid this.

  • Using page.$eval("#textarea", (el, in) => el.value = in, text) does not work because the site is an SPA.

await clipboardy.writeSync(text);
await page.click("#textarea")
await page.waitFor(500);
await page.keyboard.down('Control');
await page.keyboard.down('Shift');
await page.keyboard.press('KeyV');
await page.keyboard.up('Control');
await page.keyboard.up('Shift');
// does not paste
// also tried, clipboardy.readSync();
// does not paste either

The expected result is to enter the text in the SPA textarea.

like image 445
Ioannis Tsiokos Avatar asked Oct 18 '25 16:10

Ioannis Tsiokos


1 Answers

To answer my own question, the above approach with copy/paste works fine.

The problem was that my text string was empty. :[

like image 87
Ioannis Tsiokos Avatar answered Oct 20 '25 05:10

Ioannis Tsiokos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!