Skip to content

Commit c0c40f6

Browse files
committed
Add feature detection & check for errors
1 parent f067c15 commit c0c40f6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

python_docs_theme/static/copybutton.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,23 @@ const loadCopyButton = () => {
3333
const makeOnButtonClick = () => {
3434
let timeout = null
3535
// define the behavior of the button when it's clicked
36-
return event => {
36+
return async event => {
37+
// check if the clipboard is available
38+
if (!navigator.clipboard || !navigator.clipboard.writeText) {
39+
return;
40+
}
41+
3742
clearTimeout(timeout)
3843
const buttonEl = event.currentTarget
3944
const codeEl = buttonEl.nextElementSibling
40-
navigator.clipboard.writeText(getCopyableText(codeEl))
45+
46+
try {
47+
await navigator.clipboard.writeText(getCopyableText(codeEl))
48+
} catch (e) {
49+
console.error(e.message)
50+
return
51+
}
52+
4153
buttonEl.innerText = _("Copied!")
4254
timeout = setTimeout(() => {
4355
buttonEl.innerText = _("Copy")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy