Skip to content

Commit 5e57819

Browse files
fix: add try-catch to clipboard write in BrainRot
1 parent bc5e1cf commit 5e57819

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/pages/play/BrainRot.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const brainrotDict: Record<string, string[]> = {
3333
function toBrainrot(text: string): string {
3434
let result = text;
3535
Object.entries(brainrotDict).forEach(([word, replacements]) => {
36-
const regex = new RegExp(`\\b${word}\\b`, 'gi');
36+
const regex = new RegExp(`\b${word}\b`, 'gi');
3737
result = result.replace(regex, () => replacements[Math.floor(Math.random() * replacements.length)]);
3838
});
3939
// Add some random brainrot filler
@@ -54,10 +54,14 @@ export default function BrainRot() {
5454
setOutput(toBrainrot(input));
5555
};
5656

57-
const copy = () => {
58-
navigator.clipboard.writeText(output);
59-
setCopied(true);
60-
setTimeout(() => setCopied(false), 2000);
57+
const copy = async () => {
58+
try {
59+
await navigator.clipboard.writeText(output);
60+
setCopied(true);
61+
setTimeout(() => setCopied(false), 2000);
62+
} catch {
63+
// Clipboard failed (non-secure context), silently ignore
64+
}
6165
};
6266

6367
return (

0 commit comments

Comments
 (0)