Skip to content

Commit a508373

Browse files
committed
fix: tryfix safari clipboard
1 parent 2cafe1b commit a508373

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

tests/suites/tenant/summary/objectSummary.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ test.describe('Object Summary', async () => {
201201
]);
202202
});
203203

204-
test('Copy path copies correct path to clipboard', async ({page, browserName}) => {
205-
test.skip(browserName === 'webkit', 'Clipboard API is not reliable in Safari');
206-
204+
test.only('Copy path copies correct path to clipboard', async ({page}) => {
207205
const pageQueryParams = {
208206
schema: dsVslotsSchema,
209207
database: tenantName,
@@ -215,9 +213,18 @@ test.describe('Object Summary', async () => {
215213
const objectSummary = new ObjectSummary(page);
216214
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.CopyPath);
217215

218-
await page.waitForTimeout(1000);
219-
220-
const clipboardContent = await getClipboardContent(page);
216+
// Wait for clipboard operation to complete
217+
await page.waitForTimeout(2000);
218+
219+
// Retry clipboard read a few times if needed
220+
let clipboardContent = '';
221+
for (let i = 0; i < 3; i++) {
222+
clipboardContent = await getClipboardContent(page);
223+
if (clipboardContent) {
224+
break;
225+
}
226+
await page.waitForTimeout(500);
227+
}
221228
expect(clipboardContent).toBe('.sys/ds_vslots');
222229
});
223230

tests/utils/clipboard.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,35 @@ import type {Page} from '@playwright/test';
33
export const getClipboardContent = async (page: Page): Promise<string> => {
44
await page.context().grantPermissions(['clipboard-read']);
55

6-
return page.evaluate(async () => {
6+
// First try the modern Clipboard API
7+
const clipboardText = await page.evaluate(async () => {
78
try {
89
const text = await navigator.clipboard.readText();
910
return text;
1011
} catch (error) {
11-
console.error('Failed to read clipboard:', error);
12+
return null;
13+
}
14+
});
15+
16+
if (clipboardText !== null) {
17+
return clipboardText;
18+
}
19+
20+
// Fallback: Create a contenteditable element, focus it, and send keyboard shortcuts
21+
return page.evaluate(async () => {
22+
const el = document.createElement('div');
23+
el.contentEditable = 'true';
24+
document.body.appendChild(el);
25+
el.focus();
26+
27+
try {
28+
// Send paste command
29+
document.execCommand('paste');
30+
const text = el.textContent || '';
31+
document.body.removeChild(el);
32+
return text;
33+
} catch (error) {
34+
document.body.removeChild(el);
1235
return '';
1336
}
1437
});

0 commit comments

Comments
 (0)