← Blog

BLOG

How to Use a Template: A Practical Developer Guide

Learn how to use a template, customize it safely, and turn a browser automation starter into a tested workflow using Playwright and CDP.

10 min readRemote Browser
Ivory computer towers connected across terracotta platforms in a quiet desert landscape
The infrastructure behind your browserREMOTE BROWSER / ILLUSTRATION

To use a template, choose a starting point that matches your task, make your own copy, replace its placeholders, and test the result before sharing or deploying it. The exact steps depend on the template: a document may need only editing, while a software starter may also need dependencies, environment variables, and security review.

This guide explains how to use a template in both cases, then walks through a practical developer example: adapting a Playwright script to connect to a hosted Chromium session over the Chrome DevTools Protocol (CDP).

What is a template?

A template is a reusable starting point with some structure already in place. It might contain a document outline, a spreadsheet with formulas, a website layout, or a code repository with configuration and example files.

The important distinction is that a template is not automatically ready for your use case. Its sample values, permissions, assumptions, and dependencies need review. A working example may demonstrate a connection without handling your production requirements.

Template typeCommon starting actionWhat to customizeWhat to check
Document or presentationOpen and make a copyText, images, audience, brandingAccuracy, sharing permissions, attribution
SpreadsheetDuplicate the file or sheetInputs, formulas, date rangesFormula references, totals, data access
Website or applicationCreate a project from the starterContent, configuration, routes, stylesDependencies, accessibility, security
Browser automation scriptCopy the script into a projectTarget URL, selectors, credentials, outputSession lifecycle, permissions, error handling

If you came here for a document or spreadsheet, the first five steps below apply directly. The later code example is for readers adapting a developer template.

How to use a template in five steps

1. Choose a template that fits the output

Start with what you need to produce, not just the visual design. Check whether the template has the right structure, file format, and tool compatibility.

For a document, ask whether its sections suit your audience. For a software project, check the language, runtime version, dependencies, license, and maintenance history. A polished screenshot is less useful than a starter you can understand and change.

If the template comes from an unfamiliar source, inspect it before running any commands. A starter can execute code during dependency installation or through setup scripts.

2. Make your own copy

Create a separate working copy so that you can customize it without changing the original.

  • Documents and spreadsheets: use the application’s copy or duplicate command.
  • Downloaded files: save a copy under a new name in your working folder.
  • Code repositories: use the host’s template or fork feature if available, or copy the files in a way the license permits.

A fork may retain a relationship with the original repository; a project created from a repository template is typically intended as a separate starting point. Check the hosting platform’s documentation if you need updates from the original or want a particular repository relationship.

3. Replace sample content and configuration

Look for placeholder text, sample URLs, hard-coded identifiers, images, and settings. Replace only what you understand, and keep a short list of changes that still need review.

In a code template, configuration often lives in a README, an example environment file, or a project-specific config file. Treat an example value as an illustration, not as proof that it is safe for production.

Never put real API keys, passwords, browser debugging endpoints, or session cookies into a shared template. Supply secrets through your deployment environment or secret manager instead.

4. Test the result

Review the finished output in the environment where it will be used. For a presentation, that might mean checking the exported PDF. For a spreadsheet, test formulas with known inputs. For software, run the documented checks and exercise the workflow with safe test data.

Test more than the happy path. For example, what happens when a required setting is missing or a page fails to load? A template that starts successfully is not necessarily a template that fails safely.

5. Save and share the right version

Give the customized copy a descriptive name, remove unused examples, and check who can access it. For code, commit only the files intended for the repository; exclude secret-bearing configuration and generated artifacts where appropriate.

If you modified a third-party template, retain required license notices and attribution. Confirm that the license allows your intended distribution and use.

How to evaluate a software template before running it

Software templates can save setup time, but they also bring another person’s dependencies and assumptions into your project. Before installing or deploying one, review:

  1. Purpose and scope. Does the starter solve your problem, or will you remove most of it?
  2. Runtime and dependencies. Are the required language versions compatible with your environment? Review dependency manifests and lockfiles.
  3. Setup scripts. Inspect install hooks, shell scripts, container configuration, and commands that download or execute remote code.
  4. Secrets and network access. Identify external services, credentials, data destinations, and permissions.
  5. License and maintenance. Verify reuse terms and check whether the project’s dependencies and instructions appear maintained.
  6. Operational behavior. Find out how the starter handles errors, cleanup, logs, and persistent data.

A template is useful when its assumptions are visible and its code is easier to adapt than to replace. If you cannot tell what a setup command does, investigate it before running it with access to production credentials.

Example: adapt a Playwright template for a remote browser

The following example is an illustrative starter, not a claim that Remote Browser provides a particular template repository. It shows how to use a template pattern: separate the reusable connection logic from the values and actions you will change for your own task.

The script connects Playwright to an existing CDP-enabled Chromium session, opens a page, checks its title, and closes the page. A service such as Remote Browser can provide hosted Chromium sessions and CDP access; your application still owns the workflow and its validation.

Prerequisites

You need:

  • A recent Node.js installation and an empty project directory.
  • Access to a running Chromium session with a CDP endpoint reachable from your machine.
  • Permission to connect to that session and visit the target page.
  • A way to provide the endpoint as the CDP_URL environment variable.

Install the dependencies in your project:

npm init -y
npm install playwright
npm install --save-dev typescript tsx @types/node

This example connects to an existing browser, so it does not launch a local Playwright browser. Use the CDP endpoint supplied for your session; it is not the same thing as an ordinary website URL. Treat it as sensitive because access to it can permit control of the browser.

Create the starter script

Save this as check-page.ts:

import { chromium, type Page } from "playwright";

async function main(): Promise<void> {
  const endpoint = process.env.CDP_URL;

  if (!endpoint) {
    throw new Error("Set CDP_URL to your session's CDP endpoint.");
  }

  const browser = await chromium.connectOverCDP(endpoint);
  let page: Page | undefined;

  try {
    // CDP connections expose the browser's existing default context.
    const context = browser.contexts()[0];

    if (!context) {
      throw new Error("No browser context is available in this session.");
    }

    page = await context.newPage();
    await page.goto("https://example.com", {
      waitUntil: "domcontentloaded",
      timeout: 30_000,
    });

    const title = await page.title();

    if (!title.includes("Example Domain")) {
      throw new Error("The page title did not match the expected value.");
    }

    console.log("Page title check passed.");
  } finally {
    if (page) {
      await page.close();
    }
    await browser.close();
  }
}

main().catch(() => {
  // Avoid printing connection errors that could expose the endpoint.
  console.error("Browser check failed. Review your session and configuration.");
  process.exitCode = 1;
});

Provide CDP_URL through your local environment or deployment secret manager, then run:

npx tsx check-page.ts

A successful run prints Page title check passed. If the connection or check fails, the process exits with a nonzero status. The generic error message deliberately avoids printing the endpoint; use your provider’s secure diagnostics and session viewer to investigate.

The Playwright `connectOverCDP` documentation describes the connection API and its Chromium-specific limitations.

Customize the script for your workflow

Replace https://example.com and the title check with an authorized test target and a meaningful assertion. For an application you control, you might check that a dashboard heading appears after navigation:

await page.goto("https://your-test-site.example/dashboard");
await page.getByRole("heading", { name: "Dashboard" }).waitFor();

The URL above is a placeholder, not a live test target. Choose selectors that reflect stable user-facing behavior where possible, and define the expected result before automating clicks. If login is necessary, use a test account and an approved credential-handling method.

The example closes the page it creates and calls browser.close() on the Playwright connection. Session termination and billing behavior depend on the browser provider. Follow your provider’s instructions to stop or release the hosted session separately when required. Do not attach this cleanup pattern to a shared browser session without first checking how your provider handles disconnection.

Local template or hosted browser: which should you use?

A Playwright template describes automation logic; the browser runtime determines where that logic executes. You can begin locally and move to hosted Chromium when you need a remote execution environment.

DecisionLocal browserHosted browser session
SetupInstall and manage a browser on the execution machineObtain a session and connect using provider instructions
DebuggingInspect the browser on your machineUse available remote viewing and session diagnostics
StateManage local browser data and isolationConfigure session and profile behavior with the provider
ScalingProvision machines and manage browser processesEvaluate provider limits, usage controls, and cost
Best starting pointDevelopment on one machineRemote workers, shared infrastructure, or operational workflows

Neither option makes an automation reliable by itself. You still need stable checks, timeouts, access controls, and a plan for failures. Remote Browser provides hosted Chromium, CDP access, a live viewer, persistent profiles, and configurable browser settings. Review the documentation for current setup guidance and pricing for current usage details.

Prepare a template for production

Once you understand how to use a template for a single successful run, decide what must change before the workflow handles real traffic or sensitive data.

  • Define session ownership. Record which component creates, uses, and stops each browser session. Set a cleanup path for timeouts and worker failures.
  • Separate credentials from code. Store secrets outside the repository, restrict access, and rotate them according to your organization’s policy.
  • Choose state deliberately. Persistent profiles can preserve useful login state, but they also contain sensitive data. Use isolated sessions where persistence is unnecessary.
  • Make retries safe. A retry after a read-only page load differs from a retry after submitting an order. Check whether an action already succeeded before repeating it.
  • Add useful diagnostics. Capture the task ID, step, timing, and outcome without logging secrets or unnecessary page content. Apply retention and access rules to screenshots and recordings.
  • Test failure cases. Exercise expired sessions, unavailable pages, changed selectors, missing configuration, and cleanup after an interrupted task.
  • Pin and maintain dependencies. Commit an appropriate lockfile, review updates, and test changes before rolling them out.

For agent-driven workflows, also define which sites and actions the agent is allowed to use and when a human must approve a consequential action. A template can provide structure, but it cannot decide your authorization or risk policy.

For more on the runtime layer behind these workflows, see remote browsers for AI agents. The practical rule is simple: copy a template to get started, then make its behavior, security boundaries, and operating assumptions your own.