Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sheet-ui): fix clipboard not available in unsecure context #1345

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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';
}
Loading