mirror of
https://github.com/microsoft/playwright-mcp.git
synced 2025-07-26 16:42:27 +08:00
Fix linting issues and finalize save-session implementation
Co-authored-by: pavelfeldman <883973+pavelfeldman@users.noreply.github.com>
This commit is contained in:
parent
f00f78491a
commit
9588845cc3
@ -164,6 +164,8 @@ Playwright MCP server supports following arguments. They can be provided in the
|
|||||||
"http://myproxy:3128" or "socks5://myproxy:8080"
|
"http://myproxy:3128" or "socks5://myproxy:8080"
|
||||||
--save-trace Whether to save the Playwright Trace of the
|
--save-trace Whether to save the Playwright Trace of the
|
||||||
session into the output directory.
|
session into the output directory.
|
||||||
|
--save-session Whether to save the session log with tool calls
|
||||||
|
and snapshots into the output directory.
|
||||||
--storage-state <path> path to the storage state file for isolated
|
--storage-state <path> path to the storage state file for isolated
|
||||||
sessions.
|
sessions.
|
||||||
--user-agent <ua string> specify user agent string
|
--user-agent <ua string> specify user agent string
|
||||||
|
@ -52,9 +52,8 @@ export class Context {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
this._browserContextFactory = browserContextFactory;
|
this._browserContextFactory = browserContextFactory;
|
||||||
testDebug('create context');
|
testDebug('create context');
|
||||||
if (this.config.saveSession) {
|
if (this.config.saveSession)
|
||||||
void this._initializeSessionFile();
|
void this._initializeSessionFile();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clientSupportsImages(): boolean {
|
clientSupportsImages(): boolean {
|
||||||
@ -138,11 +137,11 @@ export class Context {
|
|||||||
private async _initializeSessionFile() {
|
private async _initializeSessionFile() {
|
||||||
if (!this.config.saveSession)
|
if (!this.config.saveSession)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const timestamp = new Date().toISOString();
|
const timestamp = new Date().toISOString();
|
||||||
const fileName = `session${timestamp}.yml`;
|
const fileName = `session${timestamp}.yml`;
|
||||||
this._sessionFile = await outputFile(this.config, fileName);
|
this._sessionFile = await outputFile(this.config, fileName);
|
||||||
|
|
||||||
// Initialize empty session file
|
// Initialize empty session file
|
||||||
await fs.promises.writeFile(this._sessionFile, '# Session log started at ' + timestamp + '\n', 'utf8');
|
await fs.promises.writeFile(this._sessionFile, '# Session log started at ' + timestamp + '\n', 'utf8');
|
||||||
}
|
}
|
||||||
@ -163,9 +162,8 @@ export class Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add snapshot reference if provided
|
// Add snapshot reference if provided
|
||||||
if (snapshotFile) {
|
if (snapshotFile)
|
||||||
entry.push(` snapshot: ${path.basename(snapshotFile)}`);
|
entry.push(` snapshot: ${path.basename(snapshotFile)}`);
|
||||||
}
|
|
||||||
|
|
||||||
entry.push(''); // Empty line for readability
|
entry.push(''); // Empty line for readability
|
||||||
|
|
||||||
@ -191,7 +189,7 @@ export class Context {
|
|||||||
|
|
||||||
const tab = this.currentTabOrDie();
|
const tab = this.currentTabOrDie();
|
||||||
let snapshotFile: string | undefined;
|
let snapshotFile: string | undefined;
|
||||||
|
|
||||||
// TODO: race against modal dialogs to resolve clicks.
|
// TODO: race against modal dialogs to resolve clicks.
|
||||||
const actionResult = await this._raceAgainstModalDialogs(async () => {
|
const actionResult = await this._raceAgainstModalDialogs(async () => {
|
||||||
try {
|
try {
|
||||||
@ -214,9 +212,8 @@ export class Context {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Log session entry if enabled
|
// Log session entry if enabled
|
||||||
if (this.config.saveSession) {
|
if (this.config.saveSession)
|
||||||
await this._logSessionEntry(tool.schema.name, params || {}, snapshotFile);
|
await this._logSessionEntry(tool.schema.name, params || {}, snapshotFile);
|
||||||
}
|
|
||||||
|
|
||||||
const result: string[] = [];
|
const result: string[] = [];
|
||||||
result.push(`### Ran Playwright code
|
result.push(`### Ran Playwright code
|
||||||
|
@ -57,7 +57,7 @@ test('check that session includes multiple tool calls', async ({ startClient, se
|
|||||||
arguments: { url: server.HELLO_WORLD },
|
arguments: { url: server.HELLO_WORLD },
|
||||||
});
|
});
|
||||||
|
|
||||||
// Take a snapshot
|
// Take a snapshot
|
||||||
await client.callTool({
|
await client.callTool({
|
||||||
name: 'browser_snapshot',
|
name: 'browser_snapshot',
|
||||||
arguments: {},
|
arguments: {},
|
||||||
@ -71,8 +71,8 @@ test('check that session includes multiple tool calls', async ({ startClient, se
|
|||||||
const sessionContent = fs.readFileSync(path.join(outputDir, sessionFiles[0]), 'utf8');
|
const sessionContent = fs.readFileSync(path.join(outputDir, sessionFiles[0]), 'utf8');
|
||||||
expect(sessionContent).toContain('- browser_navigate:');
|
expect(sessionContent).toContain('- browser_navigate:');
|
||||||
expect(sessionContent).toContain('- browser_snapshot:');
|
expect(sessionContent).toContain('- browser_snapshot:');
|
||||||
|
|
||||||
// Check that snapshot files exist
|
// Check that snapshot files exist
|
||||||
const snapshotFiles = files.filter(f => f.includes('snapshot.yaml'));
|
const snapshotFiles = files.filter(f => f.includes('snapshot.yaml'));
|
||||||
expect(snapshotFiles.length).toBeGreaterThan(0);
|
expect(snapshotFiles.length).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user