Feature idea: Abstract file system layer so that Playwright can be run isolated and better as a SaaS project to obtain the created files better
Main use cases:
Related issues: https://github.com/mxschmitt/try-playwright/issues/12
Related code in the project:
Possible implementation would be a writeFile(path: string, content: Buffer) method. For that readProtocolStream needs to be rewritten, so a Buffer will be returned instead of writing to the filesystem via fs.{open,write,close}.
I would pass this in the end as a .launch() argument.
(We discussed this offline, I'll put a summary here)
There are two ways to implement this:
Page.prototype.screenshot method (and Page.prototype.pdf).const playwright = require('playwright');
const {Page} = require('playwright/lib/api');
const superScreenshot = Page.prototype.screenshot;
const BROWSER_ID = Symbol('BROWSER_ID');
Page.prototype.screenshot = async function(options) {
const path = options.path;
const browserId = this.context()._browser[BROWSER_ID];
delete options.path;
const buffer = await superScreenshot.call(this, options);
console.log(`BrowserId = ${browserId} screenshot to path: ${path}`);
return buffer;
};
(async() => {
for (let i = 0; i < 10; ++i) {
const browser = await playwright.chromium.launch();
browser[BROWSER_ID] = i;
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'foo.png'});
await browser.close();
}
})();
//src/platform.ts - it provides a set of basic file system primitives we use to access file system. These are not guaranteed to be stable though - might be added/changed/removed in future.Hope this helps!
Most helpful comment
(We discussed this offline, I'll put a summary here)
There are two ways to implement this:
Page.prototype.screenshotmethod (andPage.prototype.pdf).code snippet
//src/platform.ts- it provides a set of basic file system primitives we use to access file system. These are not guaranteed to be stable though - might be added/changed/removed in future.Hope this helps!