title: window.location.reload(); stuck in infinite loop
body: <p>I want this function to loop through all items, if it finds the right item to load its page, and if it doesn't find the right item it should reload the page and for loop again. When I delete the window.location.reload(); it loads normally to the item page. This is the code:</p>
  <pre><code>var item_name = &quot;Washed&quot;;
  var item_color = &quot;Red&quot;;
  
  function pickItem() {
      let items = document.getElementsByClassName(&quot;name-link&quot;);
  
          for(i = 0; i &lt; items.length; i++) {
              if((items[i].innerHTML).includes(item_name)) {
                  for(j = 0; j &lt; items.length; j++) {
                      if((items[j].innerHTML).includes(item_color)) {
                          if(items[i].href == items[j].href) {
                              window.location.assign(items[i, j].href);
                          }
                      }
                  }
              }
          }
      window.location.reload();
  }
  </code></pre>
  <p>In the following form it works as I want, but why does it need the chrome.storage function to work?(I used it with the chrome.storage before, but it was too slow for my purposes so I had to change it.)</p>
  <pre><code>var item_name = &quot;Washed&quot;;
  var item_color = &quot;Red&quot;;
  
  function pickItem() {
      let items = document.getElementsByClassName(&quot;name-link&quot;);
  
      chrome.storage.sync.get([&quot;itemName&quot;, &quot;color&quot;], function(data) {
          for(i = 0; i &lt; items.length; i++) {
              if((items[i].innerHTML).includes(item_name)) {
                  for(j = 0; j &lt; items.length; j++) {
                      if((items[j].innerHTML).includes(item_color)) {
                              if(items[i].href == items[j].href) {
                                  window.location.assign(items[i, j].href);
                                  chrome.storage.sync.set({&quot;item_url&quot;: items[i, j].href});
                              }
                      }
                  }
              }
          }
      })
      window.location.reload()
  }
  </code></pre>