or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-8/

User-Agent String Logger

A utility that logs and tracks User-Agent strings from HTTP requests while preserving the original raw format for auditing and analytics purposes.

Capabilities

User-Agent String Extraction

Build a function that accepts a User-Agent string, parses it to extract browser information, and returns both the parsed data and the original unmodified User-Agent string for logging purposes.

  • Given the User-Agent string "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", the function returns an object containing the browser name "Chrome", browser version "120.0.0.0", and the original UA string unchanged @test
  • Given the User-Agent string "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1", the function returns an object with browser name "Safari", browser version "16.0", and the exact original UA string @test
  • Given the User-Agent string "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0", the function returns browser name "Firefox", browser version "115.0", and the original UA string intact @test

User-Agent Validation

Create a function that validates whether a string appears to be a valid User-Agent by attempting to parse it, and returns the original string along with a validity flag.

  • Given a valid Chrome User-Agent string, the function returns true for validity and includes the original UA string @test
  • Given an empty string, the function returns false for validity but still returns the original empty string @test

Implementation

@generates

API

/**
 * Extracts browser information from a User-Agent string and returns
 * both the parsed data and the original User-Agent string.
 *
 * @param {string} userAgent - The User-Agent string to parse
 * @returns {{browserName: string, browserVersion: string, originalUA: string}}
 *          Object containing browser name, version, and original UA string
 */
function extractUserAgent(userAgent) {
  // IMPLEMENTATION HERE
}

/**
 * Validates whether a string is a parseable User-Agent string.
 * Always returns the original string regardless of validity.
 *
 * @param {string} userAgent - The User-Agent string to validate
 * @returns {{isValid: boolean, originalUA: string}}
 *          Object containing validity flag and original UA string
 */
function validateUserAgent(userAgent) {
  // IMPLEMENTATION HERE
}

module.exports = {
  extractUserAgent,
  validateUserAgent,
};

Dependencies { .dependencies }

bowser { .dependency }

Provides User-Agent parsing and browser detection capabilities.