title: TypeError document.querySelector(...) is null
body: <p>I'm making a FF extension and I hit a snag. Here's what I have:</p>
  
  <pre><code>var canLink = document.querySelector('link[rel="service"]').href;
  </code></pre>
  
  <p>This finds a link with rel="service" and it works great. However, if the page does not have a link with rel=service, it returns null and breaks out of the rest of the program. How can I make it so that if canLink = null, it doesn't break?</p>
  
  <p>Is there a way to catch this error?</p>
  
  <p>Here is the file. Line 12 is self.port.emit, which works fine.</p>
  
  <pre><code>//Get link if it exists
  var elem = document.querySelector('link[rel="service"]').href,
  canLink = elem ? elem.href : "";
  
  if (canLink){
      self.port.emit("link", canLink);
  }
  
  else {
          canLink = "";
          self.port.emit("link", canLink);
  }
  </code></pre>