or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-4/

Browser Information Extractor

Build a simple command-line tool that analyzes User-Agent strings and outputs structured browser information. The tool should read User-Agent strings from standard input and output browser details in a consistent format.

Requirements

Create a program that:

  1. Reads User-Agent strings from standard input (one per line)
  2. For each User-Agent string, extracts and displays:
    • Browser name
    • Browser version
  3. Outputs the information in the following format for each input line:
    Browser: <name> <version>
  4. If the browser name or version cannot be determined, display "Unknown" for that field

Test Cases

  • Given a Chrome 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 output should be "Browser: Chrome 120.0.0.0" @test

  • Given a Firefox User-Agent string "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0", the output should be "Browser: Firefox 121.0" @test

  • Given a Safari User-Agent string "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.15", the output should be "Browser: Safari 17.1" @test

  • Given an Edge 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 Edg/120.0.0.0", the output should be "Browser: Microsoft Edge 120.0.0.0" @test

Implementation

@generates

API

/**
 * Extracts browser information from a User-Agent string
 * @param {string} userAgent - The User-Agent string to parse
 * @returns {Object} An object with browserName and browserVersion properties
 */
function extractBrowserInfo(userAgent) {
  // Implementation here
}

/**
 * Formats browser information as a string
 * @param {string} browserName - The name of the browser
 * @param {string} browserVersion - The version of the browser
 * @returns {string} Formatted string "Browser: <name> <version>"
 */
function formatBrowserOutput(browserName, browserVersion) {
  // Implementation here
}

module.exports = {
  extractBrowserInfo,
  formatBrowserOutput
};

Dependencies { .dependencies }

bowser { .dependency }

Provides browser detection and User-Agent parsing capabilities.

@satisfied-by