mirror of
https://github.com/microsoft/playwright-mcp.git
synced 2025-07-26 08:32:26 +08:00
fix(cursor): allow enforcing images for cursor --image-responses=allow (#478)
Fixes https://github.com/microsoft/playwright-mcp/issues/449
This commit is contained in:
parent
1051ea810a
commit
9e5ffd2ccf
4
config.d.ts
vendored
4
config.d.ts
vendored
@ -117,7 +117,7 @@ export type Config = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Do not send image responses to the client.
|
||||
* Whether to send image responses to the client. Can be "allow", "omit", or "auto". Defaults to "auto", which sends images if the client can display them.
|
||||
*/
|
||||
noImageResponses?: boolean;
|
||||
imageResponses?: 'allow' | 'omit' | 'auto';
|
||||
};
|
||||
|
@ -38,7 +38,7 @@ export type CLIOptions = {
|
||||
host?: string;
|
||||
ignoreHttpsErrors?: boolean;
|
||||
isolated?: boolean;
|
||||
imageResponses: boolean;
|
||||
imageResponses?: 'allow' | 'omit' | 'auto';
|
||||
sandbox: boolean;
|
||||
outputDir?: string;
|
||||
port?: number;
|
||||
@ -188,13 +188,9 @@ export async function configFromCLIOptions(cliOptions: CLIOptions): Promise<Conf
|
||||
},
|
||||
saveTrace: cliOptions.saveTrace,
|
||||
outputDir: cliOptions.outputDir,
|
||||
imageResponses: cliOptions.imageResponses,
|
||||
};
|
||||
|
||||
if (!cliOptions.imageResponses) {
|
||||
// --no-image-responses was passed, disable image responses
|
||||
result.noImageResponses = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -92,8 +92,7 @@ export class Connection {
|
||||
await new Promise<void>(resolve => {
|
||||
this.server.oninitialized = () => resolve();
|
||||
});
|
||||
if (this.server.getClientVersion()?.name.includes('cursor'))
|
||||
this.context.config.noImageResponses = true;
|
||||
this.context.clientVersion = this.server.getClientVersion();
|
||||
}
|
||||
|
||||
async close() {
|
||||
|
@ -48,12 +48,21 @@ export class Context {
|
||||
private _modalStates: (ModalState & { tab: Tab })[] = [];
|
||||
private _pendingAction: PendingAction | undefined;
|
||||
private _downloads: { download: playwright.Download, finished: boolean, outputFile: string }[] = [];
|
||||
clientVersion: { name: string; version: string; } | undefined;
|
||||
|
||||
constructor(tools: Tool[], config: FullConfig) {
|
||||
this.tools = tools;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
clientSupportsImages(): boolean {
|
||||
if (this.config.imageResponses === 'allow')
|
||||
return true;
|
||||
if (this.config.imageResponses === 'omit')
|
||||
return false;
|
||||
return !this.clientVersion?.name.includes('cursor');
|
||||
}
|
||||
|
||||
modalStates(): ModalState[] {
|
||||
return this._modalStates;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ program
|
||||
.option('--host <host>', 'host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.')
|
||||
.option('--ignore-https-errors', 'ignore https errors')
|
||||
.option('--isolated', 'keep the browser profile in memory, do not save it to disk.')
|
||||
.option('--no-image-responses', 'do not send image responses to the client.')
|
||||
.option('--image-responses <mode>', 'whether to send image responses to the client. Can be "allow", "omit", or "auto". Defaults to "auto", which sends images if the client can display them.')
|
||||
.option('--no-sandbox', 'disable the sandbox for all process types that are normally sandboxed.')
|
||||
.option('--output-dir <path>', 'path to the directory for output files.')
|
||||
.option('--port <port>', 'port to listen on for SSE transport.')
|
||||
|
@ -64,7 +64,7 @@ const screenshot = defineTool({
|
||||
else
|
||||
code.push(`await page.screenshot(${javascript.formatObject(options)});`);
|
||||
|
||||
const includeBase64 = !context.config.noImageResponses;
|
||||
const includeBase64 = context.clientSupportsImages();
|
||||
const action = async () => {
|
||||
const screenshot = locator ? await locator.screenshot(options) : await tab.page.screenshot(options);
|
||||
return {
|
||||
|
@ -172,12 +172,12 @@ test('browser_take_screenshot (filename: "output.jpeg")', async ({ startClient,
|
||||
expect(files[0]).toMatch(/^output\.jpeg$/);
|
||||
});
|
||||
|
||||
test('browser_take_screenshot (noImageResponses)', async ({ startClient, server }, testInfo) => {
|
||||
test('browser_take_screenshot (imageResponses=omit)', async ({ startClient, server }, testInfo) => {
|
||||
const outputDir = testInfo.outputPath('output');
|
||||
const client = await startClient({
|
||||
config: {
|
||||
outputDir,
|
||||
noImageResponses: true,
|
||||
imageResponses: 'omit',
|
||||
},
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user