Module: PlaywrightRuntime

Defined in:
app/services/playwright_runtime.rb

Overview

Resolves the Playwright CLI executable path for the current environment.

Lookup order:

  1. node_modules/.bin/playwright (dev, where yarn install provides it)
  2. ~/.playwright-driver/ (production standalone driver, bundles its own Node)
  3. npx playwright (fallback)

The standalone driver is installed with:
wget https://playwright.azureedge.net/builds/driver/playwright--linux.zip
unzip -d ~/.playwright-driver/

Constant Summary collapse

STANDALONE_DRIVER_DIR =
File.join(Dir.home, '.playwright-driver').freeze

Class Method Summary collapse

Class Method Details

.cli_pathObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/playwright_runtime.rb', line 18

def cli_path
  local = Rails.root.join('node_modules/.bin/playwright')
  return local.to_s if File.exist?(local)

  standalone_node = File.join(STANDALONE_DRIVER_DIR, 'node')
  standalone_cli  = File.join(STANDALONE_DRIVER_DIR, 'package', 'cli.js')
  return "#{standalone_node} #{standalone_cli}" if File.exist?(standalone_node) && File.exist?(standalone_cli)

  npx = find_npx
  return "#{npx} playwright" if npx

  raise "Playwright runtime not found. Install the standalone driver in #{STANDALONE_DRIVER_DIR} " \
        "or ensure node_modules/.bin/playwright exists (yarn install)."
end

.find_npxObject



33
34
35
36
# File 'app/services/playwright_runtime.rb', line 33

def find_npx
  path = `which npx 2>/dev/null`.strip
  path.present? ? path : nil
end