Skip to content

Commit 91bdf45

Browse files
Sean-R-Wilsonclaude
andcommitted
fix(web): say when an offered page copy could not be copied
Choosing Copy on a page's copy offer closed the offer and swallowed any clipboard failure, so the user believed the text was copied. Web now shows "Could not copy the text" with the reason, and mobile shows the same alert. Addresses the CodeRabbit review comment on #32801. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0fa45a3 commit 91bdf45

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎apps/mobile/src/features/browser/PreviewStreamWebView.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ async function sendFilesToPage(chooser: PreviewStreamFileChooser, pick: boolean)
9494
function offerPageCopy({ text, host }: PreviewStreamCopyOffer) {
9595
Dialog.alert(`${host || "This page"} wants to copy text`, undefined, [
9696
{ text: "Not now", style: "cancel" },
97-
{ text: "Copy", onPress: () => void Clipboard.setStringAsync(text).catch(() => undefined) },
97+
{
98+
text: "Copy",
99+
onPress: () =>
100+
void Clipboard.setStringAsync(text).catch(() => Dialog.alert("Could not copy the text")),
101+
},
98102
]);
99103
}
100104

‎apps/web/src/browser/ServerBrowserSurface.browser.test.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async function renderSurface(controller: PreviewStreamControl["controller"]) {
7474
const keys = () => mocks.sent.filter((input) => input.type === "key");
7575

7676
describe("ServerBrowserSurface clipboard commands", () => {
77-
it("copies an offered value only on acceptance when the Clipboard API is unavailable", async () => {
77+
it("copies an offered value only on acceptance, or says it could not, without the Clipboard API", async () => {
7878
setup();
7979
const { screen } = await renderSurface("you");
8080
await using _screen = screen;
@@ -96,6 +96,11 @@ describe("ServerBrowserSurface clipboard commands", () => {
9696
await userEvent.click(page.getByRole("button", { name: "Copy", exact: true }));
9797
expect(copied).toEqual(["offered value"]);
9898
expect(keys()).toEqual([]);
99+
100+
using _refused = vi.spyOn(document, "execCommand").mockReturnValue(false);
101+
await act(() => handlers.onCopyOffer?.({ text: "refused value", host: "copy.example" }));
102+
await userEvent.click(page.getByRole("button", { name: "Copy", exact: true }));
103+
await expect.element(page.getByText("Could not copy the text")).toBeVisible();
99104
});
100105

101106
it("sends a native Copy or Cut menu command to the page once", async () => {

‎apps/web/src/browser/ServerBrowserSurface.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ function offerPageCopy({ text, host }: PreviewStreamCopyOffer) {
133133
children: "Copy",
134134
onClick: () => {
135135
toastManager.close(id);
136-
void writeTextToClipboard(text).catch(() => undefined);
136+
void writeTextToClipboard(text).catch((cause: unknown) =>
137+
toastManager.add({
138+
type: "error",
139+
title: "Could not copy the text",
140+
description: cause instanceof Error ? cause.message : undefined,
141+
}),
142+
);
137143
},
138144
},
139145
});

0 commit comments

Comments
 (0)