chore: sanitize file path when saving (#99)
Fixes https://github.com/microsoft/playwright-mcp/issues/96
This commit is contained in:
@@ -331,3 +331,25 @@ test('cdp server', async ({ cdpEndpoint, startClient }) => {
|
||||
`
|
||||
);
|
||||
});
|
||||
|
||||
test('save as pdf', async ({ client }) => {
|
||||
expect(await client.callTool({
|
||||
name: 'browser_navigate',
|
||||
arguments: {
|
||||
url: 'data:text/html,<html><title>Title</title><body>Hello, world!</body></html>',
|
||||
},
|
||||
})).toHaveTextContent(`
|
||||
- Page URL: data:text/html,<html><title>Title</title><body>Hello, world!</body></html>
|
||||
- Page Title: Title
|
||||
- Page Snapshot
|
||||
\`\`\`yaml
|
||||
- document [ref=s1e2]: Hello, world!
|
||||
\`\`\`
|
||||
`
|
||||
);
|
||||
|
||||
const response = await client.callTool({
|
||||
name: 'browser_save_as_pdf',
|
||||
});
|
||||
expect(response).toHaveTextContent(/^Saved as.*page-[^:]+.pdf$/);
|
||||
});
|
||||
|
||||
@@ -81,15 +81,14 @@ export const test = baseTest.extend<Fixtures>({
|
||||
type Response = Awaited<ReturnType<Client['callTool']>>;
|
||||
|
||||
export const expect = baseExpect.extend({
|
||||
toHaveTextContent(response: Response, content: string | string[]) {
|
||||
toHaveTextContent(response: Response, content: string | RegExp) {
|
||||
const isNot = this.isNot;
|
||||
try {
|
||||
content = Array.isArray(content) ? content : [content];
|
||||
const texts = (response.content as any).map(c => c.text);
|
||||
const text = (response.content as any)[0].text;
|
||||
if (isNot)
|
||||
baseExpect(texts).not.toEqual(content);
|
||||
baseExpect(text).not.toMatch(content);
|
||||
else
|
||||
baseExpect(texts).toEqual(content);
|
||||
baseExpect(text).toMatch(content);
|
||||
} catch (e) {
|
||||
return {
|
||||
pass: isNot,
|
||||
|
||||
Reference in New Issue
Block a user