Skip to content

Latest commit

 

History

History
86 lines (68 loc) · 2.44 KB

File metadata and controls

86 lines (68 loc) · 2.44 KB

tools.xvfb

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.

Options

This plugin supports the following option:

  • args (default ["-screen", "0", "1920x1080x24"]): Arguments passed to the executable Xvfb.
  • keepalive (default false): Keep the Xvfb instance alive after the browser is closed. If this option is enabled, it is advisable to also provide a signal to stop the Xvfb executable manually.
  • signal: Signal to stop the Xvfb instance. Works in the same way as the signal parameter of fetch().

Examples

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();