[Feature] how to simulate a paste event
See original GitHub issueHi,
I tried the following code to trigger a paste event
const browser = await chromium.launch(options);
const context = await browser.newContext();
await context.grantPermissions(["clipboard-read", "clipboard-write"]);
const page = await context.newPage();
await page.goto('http://example.com/');
await page.evaluate(async (text) => {
await navigator.clipboard.writeText(text);
document.execCommand("paste");
}, "123");
await page.screenshot({ path: `example.png` });
But i got a rejection
(node:29654) UnhandledPromiseRejectionWarning: Error: Evaluation failed: ReferenceError: __awaiter is not defined
at __playwright_evaluation_script__:1:20
at CRExecutionContext.evaluate (/home/project/node_modules/playwright-core/lib/chromium/crExecutionContext.js:82:23)
at FrameManager.waitForSignalsCreatedBy (/home/project/node_modules/playwright-core/lib/frames.js:81:28)
at FrameExecutionContext._doEvaluateInternal (/home/project/node_modules/playwright-core/lib/dom.js:42:16)
-- ASYNC --
at Frame.<anonymous> (/home/project/node_modules/playwright-core/lib/helper.js:63:23)
at Page.evaluate (/home/project/node_modules/playwright-core/lib/page.js:257:33)
at Page.<anonymous> (/home/project/node_modules/playwright-core/lib/helper.js:64:31)
at /home/project/test/end2end/plop.spec.ts:16:16
at step (/home/project/test/end2end/plop.spec.ts:33:23)
at Object.next (/home/project/test/end2end/plop.spec.ts:14:53)
at fulfilled (/home/project/test/end2end/plop.spec.ts:5:58)
I am not sure if it is an issue or if i am doing something wrong
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How to trigger `paste` event manually in javascript?
My question is how to trigger a paste event programmatically. You can't, without the browser having a special setting allowing it (I'm not ......
Read more >Element: paste event - Web APIs | MDN
Element: paste event. The paste event is fired when the user has initiated a "paste" action through the browser's user interface.
Read more >Programatically trigger paste event (ctrl+v) | SpreadJS
Programatically trigger paste event (ctrl+v) ... Hello,. I am trying to achieve the same results as ctrl+v but upon clicking a button. ......
Read more >2 Ways to Trigger the onPaste Event with Testing-Library
Two examples (you only need one) showing how we render the paste component, trigger the on paste event and then test that it...
Read more >onpaste Event - W3Schools
The onpaste event occurs when the user pastes some content into an element. The onpaste event is mostly used on <input> elements with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
A couple of issues here:
navigator.clipboard
is only available to content from the secure origins, replace url withhttps://example.com
and it’ll be there. Secure origins includelocalhost
.document.execCommand("paste")
will trigger the paste event, but won’t trigger the default behavior.In case this helps anyone, I was able to emulate a text paste event using
evaluate
: