Skip to content

Commit

Permalink
clipboard: fix clipboard block's result being undefined sometimes (#1346
Browse files Browse the repository at this point in the history
)

May resolve [a recent conversation in the TurboWarp Discord
server](https://discord.com/channels/837024174865776680/1132437506655268926/1215424597730787368)

In some cases, the Clipboard extension's `clipboard` block can return
undefined. The most reproducible case I could find is using a browser
that supports the block (e.g Chrome), accepting TurboWarp's clipboard
permission prompt but *denying* the *browser's* clipboard permission
prompt.
This PR should fix it. (At least, it fixes the reproducible allow+deny
behavior.)
  • Loading branch information
CST1229 authored Mar 8, 2024
1 parent 264f92e commit cb9ff26
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions extensions/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,16 @@

clipboard() {
if (navigator.clipboard && navigator.clipboard.readText) {
return Scratch.canReadClipboard().then((allowed) => {
if (allowed) {
return navigator.clipboard.readText();
}
return "";
});
return Scratch.canReadClipboard()
.then((allowed) => {
if (allowed) {
return navigator.clipboard.readText() ?? "";
}
return "";
})
.catch(() => {
return "";
});
}
return "";
}
Expand Down

0 comments on commit cb9ff26

Please sign in to comment.