title: Can chrome.browserAction.setBadgeText load string from a script?
body: <p>I am aware that using the following will load in the text with a background over my Google Chrome extension and that it will truncate it to the first four letters.</p>
  <pre><code>chrome.browserAction.setBadgeBackgroundColor({ color: [255, 0, 0, 255] });
  chrome.browserAction.setBadgeText ( { text: &quot;loading&quot; } );
  </code></pre>
  <p>But what I am want to do is allowing the part were it says <code>loading</code> to display the string result from a js script. I have check around the web and on StackOverflow for answers but I am yet to find anything relevant to what I am trying to do so I decided to ask the question here.</p>
  <p>My manifest.json has the background,js loaded:</p>
  <pre><code>&quot;background&quot;: {
    &quot;scripts&quot;:[&quot;background.js&quot;]
  }
  </code></pre>
  <p><strong>background.js</strong> -Then inside the <code>background.js</code> I have been trying to get it to work by loading the results from <code>number.js</code> but I am just not been able to make it work what so ever. I know the code is wrong here becuase I have messed it up but I will include it so you can get an understanding of what I am trying to do:</p>
  <pre><code>var imported = document.createElement('script');
  imported.src = 'number.js';
  document.head.appendChild(imported);
  
  chrome.browserAction.setBadgeBackgroundColor({ color: [255, 0, 0, 255] });
  chrome.browserAction.setBadgeText ( { text: &quot;loading&quot; } );
  
  chrome.tabs.executeScript(null,
  {code:&quot;globalVarName = {'scriptOptions': {...}};&quot; },
  chrome.tabs.executeScript(null, {file: &quot;number.js&quot;},
  </code></pre>
  <p><strong>number.js</strong> - And then what I am finally trying to load is the string from <code>number.js</code>:</p>
  <pre><code>var ip = &quot;chromahills.net&quot;;
  
  var xhr = new XMLHttpRequest();
  xhr.open(&quot;GET&quot;, &quot;http://minecraft-api.com/v1/get/?server=&quot; + ip, true);
  xhr.onreadystatechange = function() {
          if (xhr.readyState == 4) {
                  data = JSON.parse(xhr.responseText);
                  if (data.status) {
                          document.write(data.players.online);
                  } else {
                          document.write(&quot;Fail&quot;);
                  }
          }
  }
  
  xhr.send();
  </code></pre>
  <p><strong>Question</strong></p>
  <p>So, to get straight to the point my questions are as follows:</p>
  <ul>
  <li>Is it possible to include a javascript string in the <code>.setBadgeText</code>?</li>
  <li>And if so what would be the most effective way of doing this?</li>
  </ul>
  <p>I know this is quite a long block of text but I tried to include as much detail as possible so you can understand what I am trying to do and hopefully explain a better way to do what I am doing or even if it is actually possible.</p>
  <h1>Edit</h1>
  <p>I have removed my progress to avoid confusion now the issue is fixed. If you wish to view what I tried then click here -&gt; <a href="http://jsfiddle.net/lukexf/5d72Q/" rel="nofollow noreferrer">http://jsfiddle.net/lukexf/5d72Q/</a> or read below for the solution</p>