3

When querying navigator.clipboard from puppeteer, I run into the following error:

DOMException: Document is not focused.

Example code (You can run it in Chrome to reproduce):

navigator.clipboard
            .read()
            .then(async (clipboards) => { })

Is it possible to disable the document focus check somehow? i.e. using chromeflags.

Slava Knyazev
  • 5,377
  • 1
  • 22
  • 43
  • Does this answer your question? [Is there any way in JavaScript to focus the document (content area)?](https://stackoverflow.com/questions/6976486/is-there-any-way-in-javascript-to-focus-the-document-content-area) – code Jan 03 '22 at 22:24
  • @code nope, this only works if the window is already focused. – Slava Knyazev Jan 03 '22 at 22:28
  • Hmm, will this post help? https://stackoverflow.com/questions/60158746/how-do-i-access-the-contents-of-the-clipboard-from-within-a-headless-puppeteer-t – code Jan 03 '22 at 22:31
  • @code The answer there returns me an empty string. Might be a regression. `page.click` does help with running it headfully(?) but headless hangs. – Slava Knyazev Jan 03 '22 at 22:45
  • Don't think so but this is a list of chromium flags: https://peter.sh/experiments/chromium-command-line-switches/ – first last Jan 04 '22 at 00:02
  • @SlavaKnyazev have you found a way? I am looking for that too (in Chrome) to paste content into a page that has no focus... – vdegenne Feb 10 '23 at 22:02
  • 1
    @vdegenne If you run it headfully, you can send a ctrl+c keystroke to it which will do a paste from the clipboard. That’s how I did it for myself. – Slava Knyazev Feb 10 '23 at 22:54

0 Answers0