|
| 1 | +/** |
| 2 | + * Copyright (c) Microsoft Corporation. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { test, expect } from './fixtures'; |
| 18 | + |
| 19 | +test('clipboard write without permission dialog', async ({ startClient, server, mcpBrowser }) => { |
| 20 | + test.skip(mcpBrowser === 'firefox' || mcpBrowser === 'webkit', 'Clipboard permissions are fully supported only in Chromium'); |
| 21 | + const { client } = await startClient({ |
| 22 | + args: [`--grant-permissions=clipboard-read,clipboard-write`] |
| 23 | + }); |
| 24 | + await client.callTool({ |
| 25 | + name: 'browser_navigate', |
| 26 | + arguments: { url: server.HELLO_WORLD }, |
| 27 | + }); |
| 28 | + const writeResult = await client.callTool({ |
| 29 | + name: 'browser_evaluate', |
| 30 | + arguments: { |
| 31 | + function: `() => navigator.clipboard.writeText('Hello from Playwright!').then( |
| 32 | + () => 'Write successful', |
| 33 | + e => 'Write failed: ' + e.message)`, |
| 34 | + }, |
| 35 | + }); |
| 36 | + expect(writeResult).toHaveResponse({ |
| 37 | + result: '"Write successful"', |
| 38 | + }); |
| 39 | + const readResult = await client.callTool({ |
| 40 | + name: 'browser_evaluate', |
| 41 | + arguments: { |
| 42 | + function: `() => navigator.clipboard.readText()`, |
| 43 | + }, |
| 44 | + }); |
| 45 | + expect(readResult).toHaveResponse({ |
| 46 | + result: '"Hello from Playwright!"', |
| 47 | + }); |
| 48 | +}); |
0 commit comments