Skip to content

Commit

Permalink
fix(sheet-ui): fix clipboard not available in unsecure context (#1345)
Browse files Browse the repository at this point in the history
* fix(sheet-ui): fix clipboard not available in unsecure context

* docs: add comment
  • Loading branch information
wzhudev committed Feb 7, 2024
1 parent 9340f54 commit bd57a84
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Expand Up @@ -18,6 +18,7 @@ import { Disposable, ILogService, LocaleService } from '@univerjs/core';
import { createIdentifier, Inject, Optional } from '@wendellhu/redi';

import { INotificationService } from '../notification/notification.service';
import { supportClipboardAPI } from './clipboard-utils';

export const PLAIN_TEXT_CLIPBOARD_MIME_TYPE = 'text/plain';
export const HTML_CLIPBOARD_MIME_TYPE = 'text/html';
Expand Down Expand Up @@ -62,7 +63,7 @@ export const IClipboardInterfaceService = createIdentifier<IClipboardInterfaceSe

export class BrowserClipboardService extends Disposable implements IClipboardInterfaceService {
get supportClipboard(): boolean {
return typeof window.navigator.clipboard.readText === 'function';
return supportClipboardAPI();
}

constructor(
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/services/clipboard/clipboard-utils.ts
Expand Up @@ -21,5 +21,6 @@
* @returns if the system supports clipboard API
*/
export function supportClipboardAPI(): boolean {
return typeof navigator.clipboard.readText !== 'undefined';
// In unsecure context, navigator.clipboard does not exist.
return typeof navigator.clipboard !== 'undefined' && typeof navigator.clipboard.readText !== 'undefined';
}

0 comments on commit bd57a84

Please sign in to comment.