I try to code JavaScript extension for translate an image which is in the windows clipboard.
Site page web: https://translate.google.fr/?hl=fr&sl=auto&tl=fr&op=images
An image is already in the clipboard. When I execute the code JavaScript on console:
document.querySelector('[aria-label="Coller une image depuis le presse-papiers"]').click();
the button is found by JavaScript selector and click is done but a message says
impossible de coller le contenu du presse-papiers pour le moment. Ressayer de copier l'image" = "impossible to paste clipboard content at this time. Retry to copy the image"
If I click with the mouse on the button in the web page, it works... Why? How to do with JavaScript?
Help please / Thanks
Check if the following steps are done:
DevToolsin the tab of Google Translate web page?Possible cause
This might be caused by the secure limit of
navigator.clipboard API. According to the solution of: DOMException on calling navigator.clipboard.readText(), you have to ensure you are focus on the page view of Google Translate.However, if you open the
DevTools, Chrome detects that you don't focus on the page view.How to focus page by Chrome Extensions API
To focus on the window:
To focus on the tab:
Here is a demo of auto pasting: Auto Paste Picture to Google Translate