playwright-fluent
Version:
Fluent API around playwright
18 lines (17 loc) • 701 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.recordDownloadsTo = void 0;
const tslib_1 = require("tslib");
const path_1 = tslib_1.__importDefault(require("path"));
async function recordDownloadsTo(downloadDirectory, page) {
if (!page) {
throw new Error(`Cannot record downloads to '${downloadDirectory}' because no browser has been launched`);
}
page.on('download', async (download) => {
const filename = download.suggestedFilename();
const filepath = path_1.default.join(downloadDirectory, filename);
download.saveAs(filepath);
await download.path();
});
}
exports.recordDownloadsTo = recordDownloadsTo;
;