Skip to content

Bulk browser automation with Playwright: 30 parallel sessions in Salamah Checker

How I built a Windows tool that checks permits in bulk on the Salamah portal across up to 30 parallel browser sessions, resumes where it stopped, and retries with backoff.
Published
Reading
6 min read
Author
Full-Stack Engineer

Salamah Checker is bulk browser automation with Playwright and Python: a Windows desktop tool I built for Esnad Al-Mudun that checks permit statuses on the Saudi Civil Defense Salamah portal, up to 30 browser sessions at a time. Runs can pause and resume from checkpoints, failed checks retry with backoff, and every result lands in SQLite before it is exported to Excel.

What follows is the reliability engineering behind that list, the part that decides whether a long run against someone else's website finishes cleanly. Getting around a site's protections is a different subject, and not one this post covers.

The job: many permits, no lost work

Esnad Al-Mudun was checking permits on the portal by hand, one at a time. I had two months, as a freelance engagement in 2025, to replace that with something that could take a large batch and survive interruptions and portal errors without anyone starting over.

Input arrives three ways: a single number, a range, or an Excel file. In a tool like this, all three should collapse into one de-duplicated list before anything runs, since scheduling, saving and resuming only care about that list. Ranges also need a sanity check first. Start below end, a reasonable length: one mistyped digit can turn a hundred permits into a hundred thousand, and a tool like this should catch that and ask.

Bulk browser automation with Playwright: one browser, many contexts

If you are new to Playwright, the model that matters is Browser, BrowserContext, Page. The browser is the process. A context is an isolated session inside it, with its own cookies and storage. A page is a tab within a context. According to the Playwright docs, contexts are how you run many independent sessions in one browser, and a non-persistent context writes no browsing data to disk. So thirty isolated sessions need not cost thirty full browsers.

Here is roughly what a worker pool looks like with the async Python API. It illustrates the pattern; it is not the tool's code:

import asyncio
from playwright.async_api import async_playwright

async def worker(browser, queue, check, record_failure):
    context = await browser.new_context()
    page = await context.new_page()
    try:
        while True:
            permit = await queue.get()
            try:
                await check(page, permit)
            except Exception as exc:
                record_failure(permit, exc)
            finally:
                queue.task_done()
    finally:
        await context.close()

async def run(permits, check, record_failure, workers):
    queue = asyncio.Queue()
    for permit in permits:
        queue.put_nowait(permit)
    async with async_playwright() as pw:
        browser = await pw.chromium.launch()
        tasks = [
            asyncio.create_task(worker(browser, queue, check, record_failure))
            for _ in range(workers)
        ]
        await queue.join()
        for task in tasks:
            task.cancel()
        await asyncio.gather(*tasks, return_exceptions=True)
        await browser.close()

Two details in there are deliberate. A failed check is recorded and the worker moves on, because a worker that dies on its first exception takes its slot with it, and once every worker is gone queue.join() waits forever. And everything runs on one asyncio event loop: Playwright's docs say its API is not thread-safe, so if you do use threads, give each one its own Playwright instance.

Thirty sessions is a ceiling, not a target

Salamah Checker tops out at 30 parallel sessions. Each one has a cost. On the user's side, every context and page eats memory and CPU on an ordinary Windows PC, not a server. On the other side sits a public portal that other people depend on, and once it starts slowing down or throwing errors, extra sessions buy you nothing.

My rule for automating against a site you do not own is simple: when errors rise, run fewer sessions. A good checking tool finishes the job without leaning on its source.

Idempotent checkpoints for pause and resume

A checkpoint is only as good as its write. Make saving idempotent, so recording the same permit twice leaves one row in the same state rather than a duplicate, and resuming becomes trivial: read back whatever is not done yet. In Salamah Checker, checkpoints are what let a run pause and resume, and the results live in SQLite.

A table keyed by permit number, updated as each check finishes, is the simplest form. An illustration:

CREATE TABLE IF NOT EXISTS checks (
  permit     TEXT PRIMARY KEY,
  status     TEXT NOT NULL,
  attempts   INTEGER NOT NULL DEFAULT 0,
  result     TEXT,
  checked_at TEXT
);

INSERT INTO checks (permit, status, result, checked_at)
VALUES (?, 'done', ?, datetime('now'))
ON CONFLICT(permit) DO UPDATE SET
  status = 'done', result = excluded.result, checked_at = excluded.checked_at;

Watch two things. Pausing should stop handing out new work and let in-flight checks finish, not cut them off. And since SQLite takes one writer at a time, thirty sessions are better served by a single write path.

Retry with backoff, and when not to retry

Before tuning any formula, decide what deserves a retry. Timeouts and server errors usually do. A permit number that does not exist never will; record that answer and move on. Then cap the attempts per permit and flag the leftovers for a human.

For the retries themselves, Salamah Checker waits longer after each failure instead of hammering a busy portal. The common recipe is exponential backoff with jitter: double the wait up to a cap, and randomize it so that sessions failing together do not all come back at the same instant.

import random

def backoff_delay(attempt: int, base: float = 2.0, cap: float = 60.0) -> float:
    return random.uniform(0, min(cap, base * 2 ** attempt))

SQLite in, Excel out

A desktop tool should not ask its user to run a database server, and SQLite does not: it is one file on the machine, and anything already written survives a crash or a closed window. Excel bookends the process, since permits can arrive in a spreadsheet and results leave in one.

The export deserves care. Every permit that went in should come out, including the failures, each with a plain reason. A file with ten rows silently missing leaves the user guessing; ten rows marked "could not check" tell them exactly what to rerun.

Packaging Playwright for Windows

The classic packaging trap: Playwright is more than a Python library. It also needs browser binaries, normally fetched with playwright install. Ship them inside the package or download them on first launch, or the tool will run on your laptop and fail on the client's.

Salamah Checker went out in two builds, a standard installer and a portable folder that runs without installing, which helps on machines where the user has no rights to install software.

Testing without touching the portal

Most of what can break in a tool like this can be tested offline: range and Excel parsing, resume logic, retry policy, the export format. The browser-facing code can run against local HTML fixtures that play out success, slowness, errors and unknown numbers. Tests stay fast and never send a request to a portal you do not own.

Salamah Checker ships with 179 automated tests. I will not walk through them here; the principle above is the part that transfers.

Where this kind of automation stops

The tool speeds up work the client was already doing by hand. That is the right use for this kind of automation: legitimate checks on a portal you are entitled to use, at a pace it can handle. If a site asks you to slow down, slow down.

The full case study is at Salamah Checker, and the assistants and automation tools we build are on the Arabic AI chatbot and automation page. We are two engineers in Menoufia, Egypt, working remotely for clients in Egypt and the Gulf.

If your team repeats the same work in a browser or in spreadsheets every week, send us a short brief.

Share