I am trying to get the HTML content of the clipboard when user copies text from Calibre E-book Viewer. The clipboard does have the item type of "text/html"
, but item.getType("text/html")
returns null
. How can I resolve the problem?
This problem only happens with Calibre E-book Viewer. The code works fine with Firefox, Chrome, etc.
const clipboardContents = await navigator.clipboard.read();
for (const item of clipboardContents) {
for (const mimeType of item.types) {
if (mimeType === "text/html") {
const blob = await item.getType("text/html");
clipboardText = await blob.text();
}
}
}
What I tried: I had a workaround but it’s clumsy and inconvenient: I wrote a C++ program just to get the HTML content in clipboard, do no processing and put it back in clipboard again as a text/plain
item, rather than text/html
item, so JavaScript code can get it. Thus, user will have to do extra step whenever copying text from Calibre.
Expected:
clipboardText
should contain the HTML content copied previously from Calibre E-book Viewer.- The code snippet should work the same for all web engine: Firefox, Chrome, IE, whatever Calibre E-Book Viewer is using (I guess it’s some Qt stuffs).
kjcX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.