Implementation:Microsoft Playwright Client Artifact
| Knowledge Sources | |
|---|---|
| Domains | Browser Automation, File Management |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for managing downloadable file artifacts (traces, videos, downloads) provided by the Playwright library.
Description
The Artifact class extends ChannelOwner and represents a file artifact produced during browser automation, such as a downloaded file, a trace, or a video recording. It provides methods to retrieve the artifact path (local only), save it to a specified location (supporting both local and remote connections via streaming), check for failure, create readable streams, read the entire content into a buffer, cancel ongoing operations, and delete the artifact. When connected remotely, path access is blocked and saveAs() uses a streaming mechanism through the Stream class.
Usage
Use the Artifact class when you need to interact with files produced by Playwright operations such as downloads, trace recordings, or video captures. It is typically obtained from Download, Video, or tracing APIs rather than instantiated directly.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File:
packages/playwright-core/src/client/artifact.ts
Signature
export class Artifact extends ChannelOwner<channels.ArtifactChannel> {
static from(channel: channels.ArtifactChannel): Artifact;
async pathAfterFinished(): Promise<string>;
async saveAs(path: string): Promise<void>;
async failure(): Promise<string | null>;
async createReadStream(): Promise<Readable>;
async readIntoBuffer(): Promise<Buffer>;
async cancel(): Promise<void>;
async delete(): Promise<void>;
}
Import
import { Artifact } from 'playwright-core/src/client/artifact';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| path (saveAs) | string |
Yes | The file system path to save the artifact to |
Outputs
| Name | Type | Description |
|---|---|---|
| pathAfterFinished() | Promise<string> |
The local file path of the artifact (throws if remote) |
| saveAs() | Promise<void> |
Saves the artifact to the specified path |
| failure() | null> | Returns the failure error string or null if successful |
| createReadStream() | Promise<Readable> |
Returns a Node.js Readable stream of the artifact content |
| readIntoBuffer() | Promise<Buffer> |
Returns the full artifact content as a Buffer |
Usage Examples
// Save a download artifact
const download = await page.waitForEvent('download');
const artifact = download._artifact;
await artifact.saveAs('/tmp/downloaded-file.pdf');
// Read artifact into buffer
const buffer = await artifact.readIntoBuffer();
console.log('Artifact size:', buffer.length);
// Check for failure
const error = await artifact.failure();
if (error) {
console.error('Artifact failed:', error);
}