Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: copy for legacy browser (#20670)

ecmadao85ca5c182c3a
diff --git a/frontend/src/plugins/ai/react/ChatView/Markdown/CodeBlock.tsx b/frontend/src/plugins/ai/react/ChatView/Markdown/CodeBlock.tsx
index 2697c6c53b..3745edc6a3 100644
--- a/frontend/src/plugins/ai/react/ChatView/Markdown/CodeBlock.tsx
+++ b/frontend/src/plugins/ai/react/ChatView/Markdown/CodeBlock.tsx
@@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { MonacoEditor } from "@/react/components/monaco/MonacoEditor";
import { Tooltip } from "@/react/components/ui/tooltip";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { findAncestor } from "@/utils";
import { sqlEditorEvents } from "@/views/sql-editor/events";
import { useAIContext } from "../../context";
@@ -181,11 +182,9 @@ function CopyButton({ content }: { content: string }) {
}, [copied]);
const handleClick = async () => {
- if (typeof navigator === "undefined" || !navigator.clipboard) return;
- try {
- await navigator.clipboard.writeText(content);
+ if (await writeTextToClipboard(content)) {
setCopied(true);
- } catch {
+ } else {
// ignore — same posture as TableSchemaViewer.tsx
}
};
diff --git a/frontend/src/react/components/DataExportButton.tsx b/frontend/src/react/components/DataExportButton.tsx
index 943d80610c..91f60e13d8 100644
--- a/frontend/src/react/components/DataExportButton.tsx
+++ b/frontend/src/react/components/DataExportButton.tsx
@@ -34,6 +34,7 @@ import {
SheetTitle,
} from "@/react/components/ui/sheet";
import { Tooltip } from "@/react/components/ui/tooltip";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { cn } from "@/react/lib/utils";
import { pushNotification } from "@/store";
import { ExportFormat } from "@/types/proto-es/v1/common_pb";
@@ -287,7 +288,9 @@ export function DataExportButton({
async (value: string): Promise<boolean> => {
if (!value) return false;
try {
- await navigator.clipboard.writeText(value);
+ if (!(await writeTextToClipboard(value))) {
+ throw new Error("clipboard unavailable");
+ }
pushNotification({
module: "bytebase",
style: "SUCCESS",
diff --git a/frontend/src/react/components/TableSchemaViewer.tsx b/frontend/src/react/components/TableSchemaViewer.tsx
index 5faa1203a9..f09c14ea59 100644
--- a/frontend/src/react/components/TableSchemaViewer.tsx
+++ b/frontend/src/react/components/TableSchemaViewer.tsx
@@ -6,6 +6,7 @@ import { databaseServiceClientConnect } from "@/connect";
import { ReadonlyMonaco } from "@/react/components/monaco/ReadonlyMonaco";
import { Button } from "@/react/components/ui/button";
import { Tooltip } from "@/react/components/ui/tooltip";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import {
type Database,
type GetSchemaStringRequest_ObjectType,
@@ -66,8 +67,7 @@ export function TableSchemaViewer({
}, [database.name, schema, object, type]);
const handleCopy = async () => {
- if (typeof navigator === "undefined" || !navigator.clipboard) return;
- await navigator.clipboard.writeText(schemaString);
+ await writeTextToClipboard(schemaString);
};
return (
diff --git a/frontend/src/react/components/instance/CreateDataSourceExample.tsx b/frontend/src/react/components/instance/CreateDataSourceExample.tsx
index 380c999aff..ac6c062227 100644
--- a/frontend/src/react/components/instance/CreateDataSourceExample.tsx
+++ b/frontend/src/react/components/instance/CreateDataSourceExample.tsx
@@ -1,6 +1,7 @@
import { useCallback, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { Alert } from "@/react/components/ui/alert";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import {
DATASOURCE_ADMIN_USER_NAME,
DATASOURCE_READONLY_USER_NAME,
@@ -468,7 +469,7 @@ export function CreateDataSourceExample({
);
const handleCopy = useCallback(() => {
- navigator.clipboard.writeText(grantStatement);
+ void writeTextToClipboard(grantStatement);
}, [grantStatement]);
const toggleExample = useCallback(() => {
diff --git a/frontend/src/react/components/sql-editor/HistoryPane.tsx b/frontend/src/react/components/sql-editor/HistoryPane.tsx
index 38d862a861..b012d28d37 100644
--- a/frontend/src/react/components/sql-editor/HistoryPane.tsx
+++ b/frontend/src/react/components/sql-editor/HistoryPane.tsx
@@ -11,6 +11,7 @@ import {
import { useTranslation } from "react-i18next";
import { HighlightLabelText } from "@/react/components/HighlightLabelText";
import { Button } from "@/react/components/ui/button";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { cn } from "@/react/lib/utils";
import { router } from "@/react/router";
import { SQL_EDITOR_QUERY_HISTORY_MODULE } from "@/react/router/handles";
@@ -142,14 +143,13 @@ export function HistoryPane() {
};
const handleCopy = async (statement: string) => {
- try {
- await navigator.clipboard.writeText(statement);
+ if (await writeTextToClipboard(statement)) {
useAppStore.getState().notify({
module: "bytebase",
style: "SUCCESS",
title: t("sql-editor.url-copied-to-clipboard"),
});
- } catch {
+ } else {
// clipboard not available
}
};
@@ -171,14 +171,13 @@ export function HistoryPane() {
};
const handleCopyLink = async (history: QueryHistory) => {
- try {
- await navigator.clipboard.writeText(buildHistoryLink(history));
+ if (await writeTextToClipboard(buildHistoryLink(history))) {
useAppStore.getState().notify({
module: "bytebase",
style: "SUCCESS",
title: t("sql-editor.url-copied-to-clipboard"),
});
- } catch {
+ } else {
// clipboard not available
}
};
diff --git a/frontend/src/react/components/sql-editor/ResultView/DetailPanel.tsx b/frontend/src/react/components/sql-editor/ResultView/DetailPanel.tsx
index f424317979..75df5c960a 100644
--- a/frontend/src/react/components/sql-editor/ResultView/DetailPanel.tsx
+++ b/frontend/src/react/components/sql-editor/ResultView/DetailPanel.tsx
@@ -20,6 +20,7 @@ import {
SheetTitle,
} from "@/react/components/ui/sheet";
import { Tooltip } from "@/react/components/ui/tooltip";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { cn } from "@/react/lib/utils";
import {
STORAGE_KEY_SQL_EDITOR_DETAIL_FORMAT,
@@ -152,11 +153,10 @@ export function DetailPanel({ rows, columns }: DetailPanelProps) {
}, [content, guessedIsJSON, format]);
const handleCopy = useCallback(async () => {
- try {
- await navigator.clipboard.writeText(copyContent);
+ if (await writeTextToClipboard(copyContent)) {
setCopied(true);
window.setTimeout(() => setCopied(false), 2000);
- } catch {
+ } else {
// ignore
}
}, [copyContent]);
diff --git a/frontend/src/react/components/sql-editor/ResultView/SingleResultView.tsx b/frontend/src/react/components/sql-editor/ResultView/SingleResultView.tsx
index 914bbc272f..18dc535974 100644
--- a/frontend/src/react/components/sql-editor/ResultView/SingleResultView.tsx
+++ b/frontend/src/react/components/sql-editor/ResultView/SingleResultView.tsx
@@ -42,6 +42,7 @@ import { Switch } from "@/react/components/ui/switch";
import { Tooltip } from "@/react/components/ui/tooltip";
import { useExecuteSQL } from "@/react/hooks/useExecuteSQL";
import { useSQLEditorQueryDataPolicy } from "@/react/hooks/useSQLEditorBridge";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { cn } from "@/react/lib/utils";
import { useAppStore } from "@/react/stores/app";
import { useSQLEditorEditorState } from "@/react/stores/sqlEditor/editor";
@@ -867,11 +868,10 @@ function DatabaseInfo({ database }: { database: Database }) {
function CopyInlineButton({ text }: { text: string }) {
const [copied, setCopied] = useState(false);
const handleCopy = async () => {
- try {
- await navigator.clipboard.writeText(text);
+ if (await writeTextToClipboard(text)) {
setCopied(true);
window.setTimeout(() => setCopied(false), 1500);
- } catch {
+ } else {
// ignore
}
};
diff --git a/frontend/src/react/components/sql-editor/ResultView/VirtualDataBlock.tsx b/frontend/src/react/components/sql-editor/ResultView/VirtualDataBlock.tsx
index 82d0e56b87..12ca00a867 100644
--- a/frontend/src/react/components/sql-editor/ResultView/VirtualDataBlock.tsx
+++ b/frontend/src/react/components/sql-editor/ResultView/VirtualDataBlock.tsx
@@ -11,6 +11,7 @@ import { useTranslation } from "react-i18next";
import { MaskingReasonPopover } from "@/react/components/sql-editor/MaskingReasonPopover";
import { Button } from "@/react/components/ui/button";
import { Tooltip } from "@/react/components/ui/tooltip";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { cn } from "@/react/lib/utils";
import type { Database } from "@/types/proto-es/v1/database_service_pb";
import type { MaskingReason } from "@/types/proto-es/v1/sql_service_pb";
@@ -217,11 +218,10 @@ function CopyJSONButton({
}) {
const [copied, setCopied] = useState(false);
const handleCopy = async () => {
- try {
- await navigator.clipboard.writeText(getContent());
+ if (await writeTextToClipboard(getContent())) {
setCopied(true);
window.setTimeout(() => setCopied(false), 2000);
- } catch {
+ } else {
// ignore
}
};
diff --git a/frontend/src/react/components/sql-editor/ResultView/context.tsx b/frontend/src/react/components/sql-editor/ResultView/context.tsx
index 7c8aefb753..337bc5bd62 100644
--- a/frontend/src/react/components/sql-editor/ResultView/context.tsx
+++ b/frontend/src/react/components/sql-editor/ResultView/context.tsx
@@ -8,6 +8,7 @@ import {
useState,
} from "react";
import { useTranslation } from "react-i18next";
+import { writeTextToClipboard as copyTextToClipboard } from "@/react/lib/clipboard";
import { useAppStore } from "@/react/stores/app";
import { Engine } from "@/types/proto-es/v1/common_pb";
import type { RowValue } from "@/types/proto-es/v1/sql_service_pb";
@@ -290,7 +291,9 @@ export function SQLResultViewProvider({
if (!payload) return;
setCopying(true);
try {
- await navigator.clipboard.writeText(payload);
+ if (!(await copyTextToClipboard(payload))) {
+ throw new Error("clipboard unavailable");
+ }
useAppStore.getState().notify({
module: "bytebase",
style: "SUCCESS",
diff --git a/frontend/src/react/components/sql-editor/SchemaPane/actions.tsx b/frontend/src/react/components/sql-editor/SchemaPane/actions.tsx
index 7bd952e03e..3dd46213d7 100644
--- a/frontend/src/react/components/sql-editor/SchemaPane/actions.tsx
+++ b/frontend/src/react/components/sql-editor/SchemaPane/actions.tsx
@@ -17,6 +17,7 @@ import { useCallback, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { formatSQL } from "@/react/components/monaco/sqlFormatter";
import { useExecuteSQL } from "@/react/hooks/useExecuteSQL";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { keyWithPosition } from "@/react/lib/keyWithPosition";
import { router } from "@/react/router";
import { SQL_EDITOR_DATABASE_MODULE } from "@/react/router/handles";
@@ -139,11 +140,9 @@ const copyToClipboard = async (
content: string,
notify: (key: string) => void
) => {
- if (typeof navigator === "undefined" || !navigator.clipboard) return;
- try {
- await navigator.clipboard.writeText(content);
+ if (await writeTextToClipboard(content)) {
notify("common.copied");
- } catch {
+ } else {
// Silent fail — matches Vue's `if (!isSupported.value) return` behavior.
}
};
diff --git a/frontend/src/react/components/sql-editor/SharePopoverBody.tsx b/frontend/src/react/components/sql-editor/SharePopoverBody.tsx
index 14963a3cbb..5bb37ce840 100644
--- a/frontend/src/react/components/sql-editor/SharePopoverBody.tsx
+++ b/frontend/src/react/components/sql-editor/SharePopoverBody.tsx
@@ -15,6 +15,7 @@ import {
PopoverTrigger,
} from "@/react/components/ui/popover";
import { useCurrentUser } from "@/react/hooks/useAppState";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { cn } from "@/react/lib/utils";
import { router } from "@/react/router";
import { SQL_EDITOR_WORKSHEET_MODULE } from "@/react/router/handles";
@@ -112,14 +113,13 @@ export function SharePopoverBody({ worksheet }: Props) {
"visibility",
]);
- try {
- await navigator.clipboard.writeText(sharedTabLink);
+ if (await writeTextToClipboard(sharedTabLink)) {
useAppStore.getState().notify({
module: "bytebase",
style: "SUCCESS",
title: t("sql-editor.url-copied-to-clipboard"),
});
- } catch {
+ } else {
useAppStore.getState().notify({
module: "bytebase",
style: "SUCCESS",
@@ -134,14 +134,13 @@ export function SharePopoverBody({ worksheet }: Props) {
};
const handleCopyLink = async () => {
- try {
- await navigator.clipboard.writeText(sharedTabLink);
+ if (await writeTextToClipboard(sharedTabLink)) {
useAppStore.getState().notify({
module: "bytebase",
style: "SUCCESS",
title: t("sql-editor.url-copied-to-clipboard"),
});
- } catch {
+ } else {
// clipboard not available
}
};
diff --git a/frontend/src/react/components/ui/copy-button.tsx b/frontend/src/react/components/ui/copy-button.tsx
index a6dd854907..b3e059f903 100644
--- a/frontend/src/react/components/ui/copy-button.tsx
+++ b/frontend/src/react/components/ui/copy-button.tsx
@@ -3,37 +3,10 @@ import { useCallback, useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { Button, type ButtonProps } from "@/react/components/ui/button";
import { Tooltip } from "@/react/components/ui/tooltip";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { cn } from "@/react/lib/utils";
import { useAppStore } from "@/react/stores/app";
-// Copy `text` to the clipboard, falling back to the legacy execCommand path
-// when the async Clipboard API is unavailable (e.g. insecure contexts).
-async function writeClipboard(text: string): Promise<boolean> {
- if (navigator.clipboard) {
- try {
- await navigator.clipboard.writeText(text);
- return true;
- } catch {
- // fall through to the execCommand fallback
- }
- }
- const textarea = document.createElement("textarea");
- textarea.value = text;
- textarea.style.position = "fixed";
- textarea.style.opacity = "0";
- document.body.appendChild(textarea);
- textarea.select();
- try {
- // execCommand is deprecated but remains the only clipboard path in
- // insecure (http) contexts where navigator.clipboard is unavailable.
- return document.execCommand("copy"); // NOSONAR
- } catch {
- return false;
- } finally {
- textarea.remove();
- }
-}
-
interface CopyButtonProps {
// The text to copy. Pass a function to defer resolution until click.
readonly content: string | (() => string);
@@ -59,7 +32,7 @@ export function CopyButton({
const handleCopy = useCallback(async () => {
const text = typeof content === "function" ? content() : content;
if (!text) return;
- const ok = await writeClipboard(text);
+ const ok = await writeTextToClipboard(text);
useAppStore.getState().notify({
module: "bytebase",
style: ok ? "SUCCESS" : "CRITICAL",
diff --git a/frontend/src/react/lib/clipboard.test.ts b/frontend/src/react/lib/clipboard.test.ts
new file mode 100644
index 0000000000..137a4aae2b
--- /dev/null
+++ b/frontend/src/react/lib/clipboard.test.ts
@@ -0,0 +1,49 @@
+import { afterEach, describe, expect, test, vi } from "vitest";
+import { writeTextToClipboard } from "./clipboard";
+
+const originalClipboard = Object.getOwnPropertyDescriptor(
+ navigator,
+ "clipboard"
+);
+const originalExecCommand = document.execCommand;
+
+afterEach(() => {
+ if (originalClipboard) {
+ Object.defineProperty(navigator, "clipboard", originalClipboard);
+ } else {
+ Object.defineProperty(navigator, "clipboard", {
+ configurable: true,
+ value: undefined,
+ });
+ }
+ document.execCommand = originalExecCommand;
+ vi.restoreAllMocks();
+});
+
+describe("writeTextToClipboard", () => {
+ test("falls back to execCommand when navigator.clipboard is unavailable", async () => {
+ Object.defineProperty(navigator, "clipboard", {
+ configurable: true,
+ value: undefined,
+ });
+ const execCommand = vi.fn(() => true);
+ document.execCommand = execCommand;
+
+ await expect(writeTextToClipboard("hello")).resolves.toBe(true);
+
+ expect(execCommand).toHaveBeenCalledWith("copy");
+ expect(document.body.querySelector("textarea")).toBeNull();
+ });
+
+ test("uses writeText when the async Clipboard API is available", async () => {
+ const writeText = vi.fn().mockResolvedValue(undefined);
+ Object.defineProperty(navigator, "clipboard", {
+ configurable: true,
+ value: { writeText },
+ });
+
+ await expect(writeTextToClipboard("hello")).resolves.toBe(true);
+
+ expect(writeText).toHaveBeenCalledWith("hello");
+ });
+});
diff --git a/frontend/src/react/lib/clipboard.ts b/frontend/src/react/lib/clipboard.ts
new file mode 100644
index 0000000000..1789d1d8b0
--- /dev/null
+++ b/frontend/src/react/lib/clipboard.ts
@@ -0,0 +1,28 @@
+export async function writeTextToClipboard(text: string): Promise<boolean> {
+ const clipboard = globalThis.navigator?.clipboard;
+ if (clipboard?.writeText) {
+ try {
+ await clipboard.writeText(text);
+ return true;
+ } catch {
+ // Fall through to the legacy fallback below.
+ }
+ }
+
+ if (typeof document === "undefined") {
+ return false;
+ }
+ const textarea = document.createElement("textarea");
+ textarea.value = text;
+ textarea.style.position = "fixed";
+ textarea.style.opacity = "0";
+ document.body.appendChild(textarea);
+ textarea.select();
+ try {
+ return document.execCommand("copy"); // NOSONAR
+ } catch {
+ return false;
+ } finally {
+ textarea.remove();
+ }
+}
diff --git a/frontend/src/react/pages/project/database-detail/DatabaseDetailHeader.tsx b/frontend/src/react/pages/project/database-detail/DatabaseDetailHeader.tsx
index 63d5e1b618..1391a85dec 100644
--- a/frontend/src/react/pages/project/database-detail/DatabaseDetailHeader.tsx
+++ b/frontend/src/react/pages/project/database-detail/DatabaseDetailHeader.tsx
@@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next";
import { EngineIcon } from "@/react/components/EngineIcon";
import { RouterLink } from "@/react/components/RouterLink";
import { useEnvironment, usePlanFeature } from "@/react/hooks/useAppState";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { INSTANCE_ROUTE_DETAIL } from "@/react/router/handles";
import type { Database } from "@/types/proto-es/v1/database_service_pb";
import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";
@@ -32,18 +33,6 @@ const extractDatabaseParts = (resource: string) => {
};
};
-async function copyToClipboard(text: string): Promise<boolean> {
- if (navigator.clipboard?.writeText) {
- try {
- await navigator.clipboard.writeText(text);
- return true;
- } catch {
- return false;
- }
- }
- return false;
-}
-
export function DatabaseDetailHeader({
database,
onSQLEditorFailed,
@@ -106,7 +95,7 @@ export function DatabaseDetailHeader({
}, [environmentColorRgb]);
const handleCopy = useCallback(async () => {
- const success = await copyToClipboard(database.name);
+ const success = await writeTextToClipboard(database.name);
setCopied(success);
if (success) {
window.setTimeout(() => setCopied(false), 1200);
diff --git a/frontend/src/react/pages/settings/IDPsPage.tsx b/frontend/src/react/pages/settings/IDPsPage.tsx
index db6227f435..6ee7f0fc7a 100644
--- a/frontend/src/react/pages/settings/IDPsPage.tsx
+++ b/frontend/src/react/pages/settings/IDPsPage.tsx
@@ -48,6 +48,7 @@ import {
TableRow,
} from "@/react/components/ui/table";
import { useIdentityProviderList } from "@/react/hooks/useAppState";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { router } from "@/react/router";
import { WORKSPACE_ROUTE_IDENTITY_PROVIDER_DETAIL } from "@/react/router/handles";
import { useAppStore } from "@/react/stores/app";
@@ -150,13 +151,14 @@ function ExternalURLInfo({ type }: { type: IdentityProviderType }) {
if (!redirectUrl) return null;
- const handleCopy = () => {
- navigator.clipboard.writeText(redirectUrl);
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.copied"),
- });
+ const handleCopy = async () => {
+ if (await writeTextToClipboard(redirectUrl)) {
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.copied"),
+ });
+ }
};
return (
diff --git a/frontend/src/react/pages/settings/ServiceAccountsPage.tsx b/frontend/src/react/pages/settings/ServiceAccountsPage.tsx
index 230fb62257..1ccb299911 100644
--- a/frontend/src/react/pages/settings/ServiceAccountsPage.tsx
+++ b/frontend/src/react/pages/settings/ServiceAccountsPage.tsx
@@ -29,6 +29,7 @@ import {
import { Tooltip } from "@/react/components/ui/tooltip";
import { PagedTableFooter, usePagedData } from "@/react/hooks/usePagedData";
import { useProjectByName } from "@/react/hooks/useProjectByName";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { cn } from "@/react/lib/utils";
import { useAppStore } from "@/react/stores/app";
import {
@@ -48,34 +49,6 @@ import type { ServiceAccount } from "@/types/proto-es/v1/service_account_service
import { type User, UserSchema } from "@/types/proto-es/v1/user_service_pb";
import { hasProjectPermissionV2, hasWorkspacePermissionV2 } from "@/utils";
-function execCommandCopy(text: string): boolean {
- const textarea = document.createElement("textarea");
- textarea.value = text;
- textarea.style.position = "fixed";
- textarea.style.opacity = "0";
- document.body.appendChild(textarea);
- textarea.select();
- try {
- return document.execCommand("copy");
- } catch {
- return false;
- } finally {
- document.body.removeChild(textarea);
- }
-}
-
-async function copyToClipboard(text: string): Promise<boolean> {
- if (navigator.clipboard) {
- try {
- await navigator.clipboard.writeText(text);
- return true;
- } catch {
- // fall through to execCommand fallback
- }
- }
- return execCommandCopy(text);
-}
-
// ============================================================
// ServiceAccountTable
// ============================================================
@@ -149,7 +122,10 @@ function ServiceAccountTable({
);
const updated = serviceAccountToUser(sa);
onUserUpdated(updated);
- if (updated.serviceKey && (await copyToClipboard(updated.serviceKey))) {
+ if (
+ updated.serviceKey &&
+ (await writeTextToClipboard(updated.serviceKey))
+ ) {
setCopiedKeys((prev) => new Set(prev).add(updated.name));
pushNotification({
module: "bytebase",
@@ -163,7 +139,7 @@ function ServiceAccountTable({
};
const handleCopyKey = async (user: User) => {
- if (!(await copyToClipboard(user.serviceKey))) return;
+ if (!(await writeTextToClipboard(user.serviceKey))) return;
setCopiedKeys((prev) => new Set(prev).add(user.name));
pushNotification({
module: "bytebase",
diff --git a/frontend/src/react/pages/settings/SubscriptionPage.tsx b/frontend/src/react/pages/settings/SubscriptionPage.tsx
index 5b4aaeeeee..d6a40e8ca6 100644
--- a/frontend/src/react/pages/settings/SubscriptionPage.tsx
+++ b/frontend/src/react/pages/settings/SubscriptionPage.tsx
@@ -15,6 +15,7 @@ import {
useServerState,
useSubscriptionState,
} from "@/react/hooks/useAppState";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { getResourceId, workspaceNamePrefix } from "@/react/lib/resourceName";
import { ENTERPRISE_INQUIRE_LINK } from "@/types";
import { PlanType } from "@/types/proto-es/v1/subscription_service_pb";
@@ -122,11 +123,10 @@ export function SubscriptionPage({
};
const handleCopy = async () => {
- try {
- await navigator.clipboard.writeText(workspaceId);
+ if (await writeTextToClipboard(workspaceId)) {
setCopied(true);
setTimeout(() => setCopied(false), 2000);
- } catch {
+ } else {
// Clipboard API not available
}
};
diff --git a/frontend/src/react/pages/settings/shared/AADSyncSheet.tsx b/frontend/src/react/pages/settings/shared/AADSyncSheet.tsx
index 69e6fd81a9..29490aaa1a 100644
--- a/frontend/src/react/pages/settings/shared/AADSyncSheet.tsx
+++ b/frontend/src/react/pages/settings/shared/AADSyncSheet.tsx
@@ -14,6 +14,7 @@ import {
SheetHeader,
SheetTitle,
} from "@/react/components/ui/sheet";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { useAppStore } from "@/react/stores/app";
import { pushNotification } from "@/store";
import { hasWorkspacePermissionV2 } from "@/utils";
@@ -43,26 +44,13 @@ export function AADSyncSheet({
: "";
const copyToClipboard = async (value: string) => {
- try {
- if (navigator.clipboard) {
- await navigator.clipboard.writeText(value);
- } else {
- // Fallback for non-secure contexts (e.g. self-hosted HTTP)
- const textarea = document.createElement("textarea");
- textarea.value = value;
- textarea.style.position = "fixed";
- textarea.style.opacity = "0";
- document.body.appendChild(textarea);
- textarea.select();
- document.execCommand("copy");
- document.body.removeChild(textarea);
- }
+ if (await writeTextToClipboard(value)) {
pushNotification({
module: "bytebase",
style: "SUCCESS",
title: t("common.copied"),
});
- } catch {
+ } else {
pushNotification({
module: "bytebase",
style: "WARN",
diff --git a/frontend/src/react/pages/settings/two-factor/TwoFactorSecretModal.tsx b/frontend/src/react/pages/settings/two-factor/TwoFactorSecretModal.tsx
index 7fa70b761d..9823bd1231 100644
--- a/frontend/src/react/pages/settings/two-factor/TwoFactorSecretModal.tsx
+++ b/frontend/src/react/pages/settings/two-factor/TwoFactorSecretModal.tsx
@@ -7,6 +7,7 @@ import {
DialogDescription,
DialogTitle,
} from "@/react/components/ui/dialog";
+import { writeTextToClipboard } from "@/react/lib/clipboard";
import { pushNotification } from "@/store";
interface TwoFactorSecretModalProps {
@@ -23,14 +24,13 @@ export function TwoFactorSecretModal({
const { t } = useTranslation();
const copySecret = async () => {
- try {
- await navigator.clipboard.writeText(secret);
+ if (await writeTextToClipboard(secret)) {
pushNotification({
module: "bytebase",
style: "INFO",
title: t("two-factor.your-two-factor-secret.copy-succeed"),
});
- } catch {
+ } else {
// Clipboard API not available
}
onClose();