Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore(mcp): handle cross-fs video moves (#37663)

Adam Gastineau86a00d091808
diff --git a/packages/playwright/src/mcp/browser/context.ts b/packages/playwright/src/mcp/browser/context.ts
index 79f2bae3a5..015a0da514 100644
--- a/packages/playwright/src/mcp/browser/context.ts
+++ b/packages/playwright/src/mcp/browser/context.ts
@@ -174,11 +174,20 @@ export class Context {
await fs.promises.mkdir(path.dirname(name), { recursive: true });
const p = await video.path();
// video.saveAs() does not work for persistent contexts.
- try {
- if (fs.existsSync(p))
+ if (fs.existsSync(p)) {
+ try {
await fs.promises.rename(p, name);
- } catch (e) {
- logUnhandledError(e);
+ } catch (e) {
+ if (e.code !== 'EXDEV')
+ logUnhandledError(e);
+ // Retry operation (possibly cross-fs) with copy and unlink
+ try {
+ await fs.promises.copyFile(p, name);
+ await fs.promises.unlink(p);
+ } catch (e) {
+ logUnhandledError(e);
+ }
+ }
}
}
});