Skip to content

Commit

Permalink
Merge pull request #31 from arkamar/navigator
Browse files Browse the repository at this point in the history
check existence of clipboard in navigator
  • Loading branch information
theinterned authored Mar 16, 2023
2 parents 7d751a8 + fdd5461 commit ea995cc
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/navigator-clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@ export async function clipboardRead() {
}

export function isSupported(): boolean {
return typeof navigator.clipboard.read === 'function' && typeof navigator.clipboard.write === 'function'
return (
'clipboard' in navigator &&
typeof navigator.clipboard.read === 'function' &&
typeof navigator.clipboard.write === 'function'
)
}

export function isPolyfilled(): boolean {
return navigator.clipboard.write === clipboardWrite || navigator.clipboard.read === clipboardRead
return (
'clipboard' in navigator &&
(navigator.clipboard.write === clipboardWrite || navigator.clipboard.read === clipboardRead)
)
}

export function apply(): void {
if (!isSupported()) {
if ('clipboard' in navigator && !isSupported()) {
navigator.clipboard.write = clipboardWrite
navigator.clipboard.read = clipboardRead
}
Expand Down

0 comments on commit ea995cc

Please sign in to comment.