← Back to docs

Browser Automation

Language: EN | EN | SV

Browser Automation

Browser Automation is a new admin-only Tools feature for storing and running browser scripts directly from Tools.

Why Playwright and not TestCafe?

For this Tools integration, Playwright is the better fit because it is easier to call from Laravel/PHP, works well with Chrome/Chromium/Edge, supports persistent browser profiles, and gives clean screenshot/artifact capture.

That makes it a more practical base for login-heavy sites like Facebook than adding a larger standalone TestCafe project structure inside Tools.

What it can do

The current implementation supports:

  • stored browser scripts in the database
  • Chrome / Chromium / Microsoft Edge execution
  • optional persistent profile directories for reusing logged-in sessions
  • optional headed or headless execution
  • screenshots, JSON dumps, and text artifacts saved under storage/app/browser-automation/
  • immediate Run now execution from Tools admin
  • CLI execution with Artisan
  • cron-friendly scheduled execution through the existing DB-backed scheduled-jobs system

Where to manage it

Tools admin:

  • /admin/browser-automation

From there you can:

  1. create a stored script key/name
  2. set browser, start URL, timeout, and optional persistent profile directory
  3. store JSON input passed to the script
  4. paste the Playwright async script body itself
  5. run the script immediately and inspect the latest output/artifact directory

The create/edit page is now also organized as a more guided admin form:

  • a clearer runtime/setup section for key, browser, profile, timeout, and flags
  • a dedicated code section for input JSON and script source
  • a built-in quick-test checklist in the sidebar
  • a ready-to-run smoke-test script that opens https://example.com, logs the title, saves a screenshot, and returns structured output

Server-side runtime requirement

The Playwright runner lives under automation/playwright and needs its Node dependency installed on the server:

cd automation/playwright
npm install

If Chrome / Chromium / Edge is not discoverable automatically on the host, set the matching server environment variable such as BROWSER_AUTOMATION_CHROME_PATH.

Script runtime contract

The stored script body runs inside an async function and receives:

  • page
  • context
  • browser
  • playwright
  • helpers
  • input

Useful helpers include:

  • helpers.log(...parts)
  • await helpers.screenshot('shot.png')
  • await helpers.saveText('note.txt', '...')
  • await helpers.saveJson('state.json', value)
  • helpers.setOutput(value)
  • await helpers.delay(ms)
  • helpers.getEnv('NAME')

CLI and cron

Run one stored script directly:

php artisan browser-automation:run facebook-post

Schedule one through DB-backed scheduled jobs:

  • handler: App\Jobs\Handlers\BrowserAutomationScheduledJobHandler
  • job key: browser_automation.run:facebook-post

The normal Laravel scheduler now also runs jobs:run every minute, so browser automation jobs can be executed automatically from a standard schedule:run cron setup.

Quick first test

If you want to verify that the browser automation stack works before trying Facebook or another interactive site:

  1. open /admin/browser-automation/create
  2. use a simple key like example-home
  3. keep browser as chrome or chromium
  4. set start_url (or input.url) to https://example.com
  5. keep the prefilled example script or paste this:
await page.goto(input.url || 'https://example.com', { waitUntil: 'domcontentloaded' });
helpers.log('Loaded page', await page.title());
await helpers.screenshot('example-home.png');
return {
  title: await page.title(),
  url: page.url(),
};
  1. save the script
  2. click Run now
  3. confirm that:
    • latest status becomes ok
    • output shows the page title/URL
    • the artifact folder contains a screenshot such as example-home.png

Facebook note

If you want to automate actions on Facebook or similar sites:

  • use a persistent profile directory so the browser can keep its authenticated session
  • use headed mode when first logging in or when interactive challenges are expected
  • expect that the target platform may still challenge, block, or limit automation

Always make sure your use complies with the target platform's own rules and your own security/operational policy.