<commit_before>'use strict';

const path = require('path');
const firefox = require('selenium-webdriver/firefox');
const proxy = require('selenium-webdriver/proxy');
const pick = require('lodash.pick');
const isEmpty = require('lodash.isempty');
const log = require('intel').getLogger('browsertime.firefox');
const get = require('lodash.get');
const geckodriver = require('@sitespeed.io/geckodriver');
const defaultFirefoxPreferences = require('./firefoxPreferences');
const util = require('../../support/util');

module.exports.configureBuilder = function(builder, baseDir, options) {
  const firefoxConfig = options.firefox || {};
  const moduleRootPath = path.resolve(__dirname, '..', '..', '..');
  const ffOptions = new firefox.Options();

  const profileTemplatePath = path.resolve(
    moduleRootPath,
    'browsersupport',
    'firefox-profile'
  );

  ffOptions.setProfile(profileTemplatePath);

  if (options.userAgent) {
    ffOptions.setPreference('general.useragent.override', options.userAgent);
  }

  if (firefoxConfig.collectMozLog) {
    process.env.MOZ_LOG =
      'timestamp,nsHttp:5,cache2:5,nsSocketTransport:5,nsHostResolver:5';
    process.env.MOZ_LOG_FILE = `${baseDir}/moz_log.txt`;
  }

  // try to remove the caching between runs
  /*
   profile.setPreference('dom.enable_resource_timing', true);
   */
  Object.keys(defaultFirefoxPreferences).forEach(function(pref) {
    ffOptions.setPreference(pref, defaultFirefoxPreferences[pref]);
  });

  if (!options.skipHar) {
    // Hack for opening the toolbar
    // In Firefox 61 we need to have devtools open but do not need to choose netmonitor
    ffOptions.setPreference('devtools.toolbox.selectedTool', 'netmonitor');
    ffOptions.setPreference('devtools.toolbox.footer.height', 0);

    ffOptions.addExtensions(
      path.resolve(
        moduleRootPath,
        'vendor',
        'har_export_trigger-0.6.0-an+fx.xpi'
      )
    );
  }

  // Browsertime own extension
  ffOptions.addExtensions(
    path.resolve(moduleRootPath, 'vendor', 'browsertime-0.18.0-an+fx.xpi')
  );

  if (options.extension) {
    const extensions = !Array.isArray(options.extension)
      ? [options.extension]
      : options.extension;
    for (const extension of extensions) {
      ffOptions.addExtension(extension);
    }
  }

  ffOptions.setPreference('devtools.chrome.enabled', true);

  const userPrefs = util.toArray(firefoxConfig.preference);
  for (const pref of userPrefs) {<commit_msg>Fix running extensions in FF #954 (#955)<commit_after>'use strict';

const path = require('path');
const firefox = require('selenium-webdriver/firefox');
const proxy = require('selenium-webdriver/proxy');
const pick = require('lodash.pick');
const isEmpty = require('lodash.isempty');
const log = require('intel').getLogger('browsertime.firefox');
const get = require('lodash.get');
const geckodriver = require('@sitespeed.io/geckodriver');
const defaultFirefoxPreferences = require('./firefoxPreferences');
const util = require('../../support/util');

module.exports.configureBuilder = function(builder, baseDir, options) {
  const firefoxConfig = options.firefox || {};
  const moduleRootPath = path.resolve(__dirname, '..', '..', '..');
  const ffOptions = new firefox.Options();

  const profileTemplatePath = path.resolve(
    moduleRootPath,
    'browsersupport',
    'firefox-profile'
  );

  ffOptions.setProfile(profileTemplatePath);

  if (options.userAgent) {
    ffOptions.setPreference('general.useragent.override', options.userAgent);
  }

  if (firefoxConfig.collectMozLog) {
    process.env.MOZ_LOG =
      'timestamp,nsHttp:5,cache2:5,nsSocketTransport:5,nsHostResolver:5';
    process.env.MOZ_LOG_FILE = `${baseDir}/moz_log.txt`;
  }

  // try to remove the caching between runs
  /*
   profile.setPreference('dom.enable_resource_timing', true);
   */
  Object.keys(defaultFirefoxPreferences).forEach(function(pref) {
    ffOptions.setPreference(pref, defaultFirefoxPreferences[pref]);
  });

  if (!options.skipHar) {
    // Hack for opening the toolbar
    // In Firefox 61 we need to have devtools open but do not need to choose netmonitor
    ffOptions.setPreference('devtools.toolbox.selectedTool', 'netmonitor');
    ffOptions.setPreference('devtools.toolbox.footer.height', 0);

    ffOptions.addExtensions(
      path.resolve(
        moduleRootPath,
        'vendor',
        'har_export_trigger-0.6.0-an+fx.xpi'
      )
    );
  }

  // Browsertime own extension
  ffOptions.addExtensions(
    path.resolve(moduleRootPath, 'vendor', 'browsertime-0.18.0-an+fx.xpi')
  );

  if (options.extension) {
    const extensions = !Array.isArray(options.extension)
      ? [options.extension]
      : options.extension;
    for (const extension of extensions) {
      ffOptions.addExtensions(extension);
    }
  }

  ffOptions.setPreference('devtools.chrome.enabled', true);

  const userPrefs = util.toArray(firefoxConfig.preference);
  for (const pref of userPrefs) {
{'fraction_non_alphanumeric': 0.1378892033966842, 'fraction_numerical': 0.007278608976951072, 'mean_word_length': 4.169278996865204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3285206', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1520, 'n_words': 280}