From 2b28aa1378dfd9be7440cb1e33b845605a34e7c9 Mon Sep 17 00:00:00 2001 From: Kyle Gach Date: Wed, 24 Feb 2021 07:20:39 -0700 Subject: [PATCH] SyntaxHighlighter: Safely access clipboard Use optional chaining to safely access `clipboard` on `global.navigator` --- lib/components/src/syntaxhighlighter/syntaxhighlighter.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/components/src/syntaxhighlighter/syntaxhighlighter.tsx b/lib/components/src/syntaxhighlighter/syntaxhighlighter.tsx index d8985c0e1a2e..619f2369b312 100644 --- a/lib/components/src/syntaxhighlighter/syntaxhighlighter.tsx +++ b/lib/components/src/syntaxhighlighter/syntaxhighlighter.tsx @@ -54,7 +54,7 @@ const themedSyntax = memoize(2)((theme) => let copyToClipboard: (text: string) => Promise; -if (navigator.clipboard) { +if (navigator?.clipboard) { copyToClipboard = (text: string) => navigator.clipboard.writeText(text); } else { copyToClipboard = async (text: string) => {