<commit_before>/*
 * This Source Code is subject to the terms of the Mozilla Public License
 * version 2.0 (the "License"). You can obtain a copy of the License at
 * http://mozilla.org/MPL/2.0/.
 */

"use strict";

let tabs = require("sdk/tabs");
let {URL} = require("sdk/url");

function getCurrentHost()
{
  let tab = tabs.activeTab;
  if (!tab)
    return "";

  let url = new URL(tab.url);
  if (url.protocol != "http:" && url.protocol != "https:")
    return "";

  return url.hostname;
}
exports.getCurrentHost = getCurrentHost;<commit_msg>Consider the scenario where tab.url is null because the tab didn't start loading yet<commit_after>/*
 * This Source Code is subject to the terms of the Mozilla Public License
 * version 2.0 (the "License"). You can obtain a copy of the License at
 * http://mozilla.org/MPL/2.0/.
 */

"use strict";

let tabs = require("sdk/tabs");
let {URL} = require("sdk/url");

function getCurrentHost()
{
  let tab = tabs.activeTab;
  if (!tab)
    return "";

  let url;
  try
  {
    url = new URL(tab.url);
  }
  catch (e)
  {
    return "";
  }

  if (url.protocol != "http:" && url.protocol != "https:")
    return "";

  return url.hostname;
}
exports.getCurrentHost = getCurrentHost;
{'fraction_non_alphanumeric': 0.1503267973856209, 'fraction_numerical': 0.006535947712418301, 'mean_word_length': 3.2832167832167833, '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': '4892287', 'n_tokens_mistral': 411, 'n_tokens_neox': 392, 'n_words': 133}