Important
You need to install
Xvfb in your
Linux:
- Debian/Ubuntu:
sudo apt-get install xvfb - Fedora/RHEL/CentOS:
sudo yum install xorg-x11-server-Xvfb - Arch:
sudo pacman -S xorg-server-xvfb
Start an instance of Xvfb (X Virtual Frame Buffer) and launches the browser
in this virtual framebuffer. This plugin is only useful in headful mode.
This plugin supports the following option:
args(default["-screen", "0", "1920x1080x24"]): Arguments passed to the executableXvfb.keepalive(defaultfalse): Keep theXvfbinstance alive after the browser is closed. If this option is enabled, it is advisable to also provide asignalto stop theXvfbexecutable manually.signal: Signal to stop theXvfbinstance. Works in the same way as thesignalparameter offetch().
Use the plugin with default options.
import { chromium } from "playwright-ghost";
import toolsXvfbPlugin from "playwright-ghost/plugins/tools/xvfb";
const browser = await chromium.launch({
headless: false,
plugins: [toolsXvfbPlugin()],
});
// ...Use the plugin and specify arguments for a 2K screen.
import { chromium } from "playwright-ghost";
import toolsXvfbPlugin from "playwright-ghost/plugins/tools/xvfb";
const browser = await chromium.launch({
headless: false,
plugins: [toolsXvfbPlugin({ args: ["-screen", "0", "2560x1440x24"] })],
});
// ...Use the plugin with keepalive and signal.
import { chromium } from "playwright-ghost";
import toolsXvfbPlugin from "playwright-ghost/plugins/tools/xvfb";
const controller = new AbortController();
// Launch a browser and start Xvfb.
const browser = await chromium.launch({
headless: false,
plugins: [toolsXvfbPlugin({ keepalive: true, signal: controller.signal })],
});
// ...
// Close the browser, but don't stop Xvfb.
browser.close();
// Launch an other browser and reuse Xvfb.
const otherBrowser = await chromium.launch({
headless: false,
plugins: [toolsXvfbPlugin({ keepalive: true, signal: controller.signal })],
});
// ...
// Close the other browser, but don't stop Xvfb.
otherBrowser.close();
// Stop Xvfb.
controller.abort();