title: Bookmarklet: go to page & fill in form
body: <p>I want to make a bookmarklet to <a href="https://tubecc.herokuapp.com/" rel="nofollow noreferrer">a site where you can watch videos with any subtitle .srt file</a>. The intent is that I can directly click it from a YouTube (or DailyMotion, or ...) video page, and instantly be transported to <a href="https://tubecc.herokuapp.com/" rel="nofollow noreferrer">https://tubecc.herokuapp.com/</a>, with the desired video url <em>already filled in</em>.</p>
  <p>My current attempt is:</p>
  <pre><code>javascript:{vidurl=document.location.href;document.location.href=('https://tubecc.herokuapp.com');document.getElementById(&quot;url&quot;).value=vidurl;void(0);}
  </code></pre>
  <p>However, all this does is navigate to the website - it does not fill in the url in the box.</p>
  <p>When I try to fill in the url box with some nonsense text as a separate operation - i.e. I'm already on <a href="https://tubecc.herokuapp.com/" rel="nofollow noreferrer">https://tubecc.herokuapp.com/</a> and just run <code>document.getElementById(&quot;url&quot;).value=&quot;foobar&quot;</code> from the console, or make a separate bookmarklet which only includes <code>javascript:{document.getElementById(&quot;url&quot;).value=&quot;foobar&quot;;void(0);}</code>, it <em>does</em> work - 'foobar' appears in the text box, as expected.</p>
  <p>It only seems to fail when combined with a larger bookmarklet which navigates to the page first. At one point I suspected it had something to do with asynchronicity so I added a delay for the fill in (<code>javascript:{vidurl=document.location.href;document.location.href('https://tubecc.herokuapp.com');setTimeout(() =&gt; {  document.getElementById(&quot;url&quot;).value=&quot;foobar&quot;; }, 2000);void(0);}</code>), but that didn't seem to help either.</p>
  <p>PS: not a duplicate of <a href="https://stackoverflow.com/questions/11292786/create-bookmarklet-to-fill-form">this question</a> - the basic principle is described there, and I am applying it. My question is about why it goes wrong in this specific situation.</p>