Skip to main content
Sanitizes and cleans HTML content by removing unwanted elements, attributes, and whitespace. Provides fine-grained control over each cleaning operation through configurable options.
export declare function sanitizeHtml(options: SanitizeHtmlOptions): string;

Examples

import { BrowserContext, Page } from "playwright";
import { sanitizeHtml } from "@intuned/browser";

interface Params {}

export default async function handler(
  params: Params,
  page: Page,
  context: BrowserContext
) {
  await page.goto("https://books.toscrape.com");
  const firstRow = page.locator("ol.row").locator("li").first();
  // Get the HTML of the first row.
  const html = await firstRow.innerHTML();
  // Sanitize the HTML.
  const sanitizedHtml = sanitizeHtml({ html });
  // Log the sanitized HTML.
  console.log(sanitizedHtml);
  // Return the sanitized HTML.
  return sanitizedHtml;
}

Arguments

options
SanitizeHtmlOptions
required
Configuration options for sanitization

Returns: string

The sanitized HTML string