Skip to content

customConfig support for browser config changes#66

Merged
iBombit merged 1 commit intomainfrom
feature/browser_configs
Mar 4, 2026
Merged

customConfig support for browser config changes#66
iBombit merged 1 commit intomainfrom
feature/browser_configs

Conversation

@iBombit
Copy link
Owner

@iBombit iBombit commented Mar 4, 2026

PR Notes: Custom Browser Arguments Configuration

Overview

Added support for customizing Puppeteer browser launch arguments through the same configuration system used for Lighthouse settings. Users can now specify different browser arguments for headless and headful modes via customConfig.json.

Changes Made

1. New File: configLoader.js

  • Centralized configuration management hub
  • Exported Functions:
    • loadCustomConfig() - Loads custom config from file
    • getBrowserArgsFromCustomConfig(isHeadless) - Gets browser args based on mode
    • getLighthouseConfigByBrowserType(browserType) - Gets merged lighthouse config
    • createBaseLighthouseConfig(device) - Creates base lighthouse config

2. Updated: browser.js

  • Refactored to use config-driven browser arguments
  • Removed hardcoded browser args
  • Added private method #getArgs(isHeadless) to fetch args from config with fallback to defaults
  • Updated all four getters (headlessDesktop, headfulDesktop, headlessMobile, headfulMobile)
  • Maintains backward compatibility with default args if config not provided

3. Updated: lighthouse.js

  • Simplified to a thin wrapper
  • Re-exports getLighthouseConfigByBrowserType from configLoader as getConfigByBrowserType
  • Maintains backward compatibility for existing imports

4. Updated: browser.js

  • Updated import to use getLighthouseConfigByBrowserType from configLoader
  • No functional changes to browser launching logic

5. Updated: customConfig.json

  • Added browserArgs section with support for:
    • headless - Arguments for headless mode (--headless=true)
    • headful - Arguments for headful/headed mode (--headless=false)
  • Merged seamlessly with existing lighthouse settings

6. Updated: README.md

  • Added browserArgs documentation with examples
  • Explained headless vs headful modes
  • Updated all command examples to include --configFile=customConfig.json
  • Added common browser arguments reference

Usage

Basic Example

npx mocha --timeout 10000 .\test\huge.test.steps.js \
  --browsertype=desktop \
  --headless=false \
  --url="https://demoqa.com/" \
  --configFile=customConfig.json

Custom Browser Args in customConfig.json

{
  "settings": {
    "browserArgs": {
      "headless": [
        "--allow-no-sandbox-job",
        "--no-sandbox",
        "--disable-gpu"
      ],
      "headful": [
        "--allow-no-sandbox-job",
        "--no-sandbox"
      ]
    }
  }
}

Key Features

Config-Driven - Browser args defined in same config file as Lighthouse settings
Mode-Specific - Different args for headless vs headful modes
Backward Compatible - Falls back to defaults if no config provided
Centralized - Single configLoader.js manages all configuration
Consistent - Same pattern as existing Lighthouse config loading

Architecture

customConfig.json
    ↓
configLoader.js (loadCustomConfig)
    ├→ getBrowserArgsFromCustomConfig → browser.js
    ├→ getLighthouseConfigByBrowserType → core/browser.js
    └→ createBaseLighthouseConfig (internal)

Backward Compatibility

  • Existing code continues to work without config file
  • Default browser arguments are used as fallback
  • No breaking changes to public APIs

Testing Recommendations

  • Test with and without --configFile parameter
  • Verify headless (--headless=true) uses correct args
  • Verify headful (--headless=false) uses correct args
  • Test with custom browserArgs in config
  • Verify fallback to defaults when config not provided
  • Test lighthouse config still merges correctly

@iBombit iBombit self-assigned this Mar 4, 2026
@iBombit iBombit merged commit 0624fe3 into main Mar 4, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant