title: "Can't Get Document" Error - Javascript & Applescript
body: <p>My Applescript has been encountering this error (sporadically) in Safari.</p>
  
  <pre><code>Result:
     error "Safari got an error: Can’t get document \"DOC TITLE\"." 
     number -1728 from document "DOC TITLE"
  </code></pre>
  
  <p>I assumed this was because the page wasn't loaded, but I have a Javascript to check "complete" before continuing, as well as a try statement to delay another second on error.</p>
  
  <p>Nevertheless, I'm still encountering this issue. It seems to be fairly random.</p>
  
  <p>Any suggestions?</p>
  
  <p><strong>Applescript (entire Tell statement):</strong></p>
  
  <pre><code>tell application "Safari"
  set the URL of the front document to searchURL
  delay 1
  repeat
      if (do JavaScript "document.readyState" in document 1) is "complete" then exit repeat
      delay 1.5 -- wait a second before checking again
  end repeat
  try
      set doc to document "DOC TITLE"
  on error
      delay 1
      set doc to document "DOC TITLE"
  end try
  set theSource to source of doc
  set t to theSource
  end tell
  </code></pre>