or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-2/

Browser Compatibility Checker

Build a browser compatibility checking system that determines whether a given browser meets specified version requirements.

Requirements

Create a module that exports a function checkBrowserCompatibility(userAgent, requirements) which:

  1. Accepts a User-Agent string as the first parameter
  2. Accepts a requirements object as the second parameter with version constraint properties
  3. Returns an object containing:
    • compatible: boolean indicating if the browser meets all requirements
    • browserInfo: object with browser name and version
    • failedChecks: array of requirement keys that failed (empty if all pass)

The requirements object can contain any of these properties:

  • minVersion: Browser version must be greater than or equal to this value
  • maxVersion: Browser version must be less than or equal to this value
  • exactVersion: Browser version must exactly match this value
  • notVersion: Browser version must not match this value

Functionality

The system should:

  1. Parse the User-Agent string to extract browser information
  2. Apply each version requirement check to the detected browser
  3. Determine which requirements pass and which fail
  4. Return a comprehensive compatibility report

Dependencies { .dependencies }

bowser { .dependency }

Provides browser detection and version comparison capabilities.

Test Cases

Test Case 1: Compatible Browser { .test-case @test }

Input:

  • User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
  • Requirements: { minVersion: "100.0.0" }

Expected Output:

{
  compatible: true,
  browserInfo: { name: "Chrome", version: "120.0.0.0" },
  failedChecks: []
}

Test Case 2: Incompatible Browser { .test-case @test }

Input:

  • User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
  • Requirements: { minVersion: "100.0.0" }

Expected Output:

{
  compatible: false,
  browserInfo: { name: "Chrome", version: "95.0.4638.69" },
  failedChecks: ["minVersion"]
}

Test Case 3: Version Range Check { .test-case @test }

Input:

  • User-Agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15"
  • Requirements: { minVersion: "14.0", maxVersion: "16.0" }

Expected Output:

{
  compatible: true,
  browserInfo: { name: "Safari", version: "15.6.1" },
  failedChecks: []
}

Test Case 4: Exact Version Match { .test-case @test }

Input:

  • User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0"
  • Requirements: { exactVersion: "115.0" }

Expected Output:

{
  compatible: true,
  browserInfo: { name: "Firefox", version: "115.0" },
  failedChecks: []
}

Implementation Files

  • src/compatibility-checker.js: Main compatibility checking logic
  • src/compatibility-checker.test.js: Test file containing the test cases above