<commit_before>
var WebSocket   = require('ws'),
    forceUpdate = require('./force-update-app')

module.exports = {
  init: function(lrload, port) {
    var ws = lrload.client = new WebSocket('ws://127.0.0.1:' + port)
    ws.onmessage = function() {
      var src = getScriptURL()
      loadScript(src, lrload)
    }
  }
}


function getScriptURL() {
  try {
    throw new Error()
  }
  catch(e) {
    var stackLines = e.stack.split('\n')
    for(var i = 0; i < stackLines.length; i++){
      if (stackLines[i].match(/\(\s*http[s]?:\/\//)) {
        var m = stackLines[i].match(/\(\s*((http[s]?:\/\/.+\/)([^\/]+\.js.*)):\d+\s*\)/)
        return m[1].replace(/:\d+$/, '')
      }
    }
    return ''
  }
}

function cacheBust(src) {
  var uri = src.replace(/[\?&]__livereactloadPreventCache=\d+/, '')
  var idx = uri.indexOf('?')
  if (idx === -1)
    uri += '?'
  else if (idx !== uri.length - 1)
    uri += '&'
  return uri + '__livereactloadPreventCache=' + Date.now()
}

function loadScript(src, lrload) {
  var numTries = 0
  tryLoad()

  function tryLoad() {
    var script = document.createElement('script')
    script.setAttribute('src', cacheBust(src));
    script.addEventListener('error', function() {
      if (numTries < 30) {<commit_msg>Fix broken url detection for Firefox stack traces<commit_after>
var WebSocket   = require('ws'),
    forceUpdate = require('./force-update-app')

module.exports = {
  init: function(lrload, port) {
    var ws = lrload.client = new WebSocket('ws://127.0.0.1:' + port)
    ws.onmessage = function() {
      var src = getScriptURL()
      loadScript(src, lrload)
    }
  }
}


function getScriptURL() {
  try {
    throw new Error()
  }
  catch(e) {
    var stackLines = e.stack.split('\n')
    // chrome
    for (var i = 0; i < stackLines.length; i++){
      if (stackLines[i].match(/\(\s*http[s]?:\/\//)) {
        var mc = stackLines[i].match(/\(\s*((http[s]?:\/\/.+\/)([^\/]+\.js.*)):\d+\s*\)/)
        return mc[1].replace(/:\d+$/, '')
      }
    }
    // firefox
    for (var j = 0; j < stackLines.length; j++) {
      if (stackLines[j].match(/@http[s]?:\/\//)) {
        var mf = stackLines[j].match(/@(http[s]?:\/\/.+)/)
        // drop line and column
        var mfParts = mf[1].split(':')
        return mfParts.slice(0, mfParts.length - 2).join(':')
      }
    }
    return ''
  }
}

function cacheBust(src) {
  var uri = src.replace(/[\?&]__livereactloadPreventCache=\d+/, '')
  var idx = uri.indexOf('?')
  if (idx === -1)
    uri += '?'
  else if (idx !== uri.length - 1)
    uri += '&'
  return uri + '__livereactloadPreventCache=' + Date.now()
}

function loadScript(src, lrload) {
  var numTries = 0
  tryLoad()

  function tryLoad() {
    var script = document.createElement('script')
    script.setAttribute('src', cacheBust(src));
    script.addEventListener('error', function() {
      if (numTries < 30) {
{'fraction_non_alphanumeric': 0.2136158388329281, 'fraction_numerical': 0.010420284821118444, 'mean_word_length': 2.5687732342007434, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '805966', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1050, 'n_words': 209}