Courses / Frontend Security & Observability
1. Synthetic monitoring for frontend flows
Using scripted synthetic checks to monitor critical frontend flows and availability.
How It Works
Think of synthetic checks as a robot QA engineer on a schedule: it opens the site, follows a predefined path, measures each step, and reports errors or slow steps so you can act before users complain.
Write a script that performs the exact user flow you want to monitor.
Run that script from one or more locations (or the cloud) on a schedule.
Record assertions and timing for key steps and report failures/threshold breaches to alerts or dashboards.
See It
This script uses Selenium WebDriver to open a browser, navigate to a login page, fill credentials, submit, and wait up to 5s for an element with id "welcome". If found, it logs success; on errors it logs failure and sets a nonzero exit code so monitoring systems detect failure. Try changing the wait timeout to 20000 to allow slower responses.
const { Builder, By, until } = require('selenium-webdriver');
(async function syntheticCheck() {
let driver = await new Builder().forBrowser('chrome').build();
try {
await driver.get('https://example.com/login');
await driver.findElement(By.name('username')).sendKeys('monitor-user');
await driver.findElement(By.name('password')).sendKeys('s3cret');
await driver.findElement(By.css('button[type="submit"]')).click();
// wait for a selector that indicates success
await driver.wait(until.elementLocated(By.id('welcome')), 5000);
console.log('OK: login flow succeeded');
} catch (e) {
console.error('FAIL:', e.message);
process.exitCode = 1;
} finally {
await driver.quit();
}
})();Use It
Monitoring a site's login + redirect to dashboard from multiple regions to catch outages or regressions early.
const fetch = require('node-fetch');
async function checkHealth() {
const start = Date.now();
const res = await fetch('https://example.com/health');
const ms = Date.now() - start;
if (!res.ok) throw new Error(`Status ${res.status}`);
const body = await res.text();
if (!body.includes('ok')) throw new Error('unexpected body');
return { status: res.status, latencyMs: ms };
}
checkHealth()
.then(r => console.log('OK', r))
.catch(e => { console.error('FAIL', e.message); process.exitCode = 1; });Scripted checks let you assert the actual user path and timings (not just server up) and trigger alerts before real users are affected.
Break It
What will this script most likely do in practice when the "buy now" click opens a client-side modal?
const puppeteer = require('puppeteer');
async function check() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// navigate and wait for network idle as a sign of readiness
await page.goto('https://example.com/checkout', { waitUntil: 'networkidle0' });
// click "buy now" which opens a confirmation modal
await page.click('button.buy-now');
// assert modal visible by checking text
const text = await page.$eval('.modal .title', el => el.textContent);
if (text.includes('Confirmed')) {
console.log('SUCCESS');
} else {
console.log('FAIL');
process.exitCode = 1;
}
await browser.close();
}
check().catch(e => { console.error(e); process.exitCode = 1; });networkidle0 only waits for network activity to quiesce at navigation time; it doesn't guarantee that subsequent client-side interactions (like click handlers that render a modal) have completed. The script clicks after navigation but doesn't wait for the modal to appear, so $eval can run before the DOM contains .modal .title and throw or return unexpected text.
After clicking, explicitly wait for the modal selector to appear (e.g., page.waitForSelector('.modal .title', { visible: true })) before reading its text.
const puppeteer = require('puppeteer');
async function check() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com/checkout', { waitUntil: 'networkidle0' });
await page.click('button.buy-now');
// wait for the modal to be rendered by the click handler
await page.waitForSelector('.modal .title', { visible: true, timeout: 5000 });
const text = await page.$eval('.modal .title', el => el.textContent);
if (text.includes('Confirmed')) {
console.log('SUCCESS');
} else {
console.log('FAIL');
process.exitCode = 1;
}
await browser.close();
}
check().catch(e => { console.error(e); process.exitCode = 1; });Level Up
Multi-location distributed checks: Run the same synthetic script from multiple geographic locations to detect region-specific outages and CDN issues.
Canary deployment probes: Run synthetic checks against a canary instance and compare metrics to prod to catch regressions before rollout.
Resource timing and tracing integration: Capture detailed resource timings and attach traces to synthetic failures for faster root cause analysis.
Prove It
Write a short Node.js script using Puppeteer that navigates to a demo login page, attempts login with supplied credentials, and returns an exit code 0 only if both (a) the final URL contains "/dashboard" and (b) the total time from navigation start to dashboard visible is under 3 seconds.
JavaScript
Synthetic monitoring for frontend flows
Scripted checks that automatically run browser-like interactions to verify web app availability and key user flows.
"I want to know immediately if checkout or login breaks — without relying on a real user to tell me."
Synthetic monitoring uses automated scripts that emulate user actions (page loads, clicks, form fills) on a schedule to detect failures, latency, and regressions before customers do.
"I want to know immediately if checkout or login breaks — without relying on a real user to tell me."
Synthetic monitoring uses automated scripts that emulate user actions (page loads, clicks, form fills) on a schedule to detect failures, latency, and regressions before customers do.