fix(webkit): support clipboard.readText (#27581)

Reference #27475
This commit is contained in:
Yury Semikhatsky 2023-10-13 09:10:35 -07:00 committed by GitHub
parent f8a30fb726
commit bc59565d77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 15 deletions

View File

@ -1148,6 +1148,7 @@ export class WKPage implements PageDelegate {
async _grantPermissions(origin: string, permissions: string[]) {
const webPermissionToProtocol = new Map<string, string>([
['geolocation', 'geolocation'],
['clipboard-read', 'clipboard-read'],
]);
const filtered = permissions.map(permission => {
const protocolPermission = webPermissionToProtocol.get(permission);

View File

@ -148,19 +148,27 @@ it.describe('permissions', () => {
await otherContext.close();
await context.close();
});
it('should support clipboard read', async ({ page, context, server, browserName, headless }) => {
it.fail(browserName === 'webkit');
it.fail(browserName === 'firefox', 'No such permissions (requires flag) in Firefox');
it.fixme(browserName === 'chromium' && (!headless || !!process.env.PLAYWRIGHT_CHROMIUM_USE_HEADLESS_NEW));
await page.goto(server.EMPTY_PAGE);
expect(await getPermission(page, 'clipboard-read')).toBe('prompt');
let error;
await page.evaluate(() => navigator.clipboard.readText()).catch(e => error = e);
expect(error.toString()).toContain('denied');
await context.grantPermissions(['clipboard-read']);
expect(await getPermission(page, 'clipboard-read')).toBe('granted');
await page.evaluate(() => navigator.clipboard.readText());
});
});
it('should support clipboard read', async ({ page, context, server, browserName, isWindows, isLinux, headless }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/27475' });
it.fail(browserName === 'firefox', 'No such permissions (requires flag) in Firefox');
it.fixme(browserName === 'chromium' && (!headless || !!process.env.PLAYWRIGHT_CHROMIUM_USE_HEADLESS_NEW));
it.fixme(browserName === 'webkit' && isWindows, 'WebPasteboardProxy::allPasteboardItemInfo not implemented for Windows.');
it.fixme(browserName === 'webkit' && isLinux && headless, 'WebPasteboardProxy::allPasteboardItemInfo not implemented for WPE.');
await page.goto(server.EMPTY_PAGE);
// There is no 'clipboard-read' permission in WebKit Web API.
if (browserName !== 'webkit')
expect(await getPermission(page, 'clipboard-read')).toBe('prompt');
let error;
await page.evaluate(() => navigator.clipboard.readText()).catch(e => error = e);
expect(error.toString()).toContain('denied');
await context.grantPermissions(['clipboard-read']);
if (browserName !== 'webkit')
expect(await getPermission(page, 'clipboard-read')).toBe('granted');
// There is no 'clipboard-write' permission in WebKit Web API.
if (browserName === 'chromium')
await context.grantPermissions(['clipboard-write']);
await page.evaluate(() => navigator.clipboard.writeText('test content'));
expect(await page.evaluate(() => navigator.clipboard.readText())).toBe('test content');
});