title: Laravel Dusk - execute javascript script and wait for promise to be resolved to return the value
body: <p>I want to run a script that will wait for the promise to return the value.</p>
  
  <pre><code>$dusk-&gt;script('return //something');
  </code></pre>
  
  <p>The javascript function I want to run is a promise.</p>
  
  <pre><code>fetch(url).then(r =&gt; r.blob()).then(blob =&gt; {
      var reader = new FileReader();
      reader.onload = function() {
          var b64 = reader.result.replace(/^data:.+;base64,/, '');
          console.log(b64); // I want to return this value
      };
      reader.readAsDataURL(blob);
  });
  </code></pre>
  
  <p>I want to return the <code>b64</code> variable, but this won't happen.</p>
  
  <pre><code>$b64 = $dusk-&gt;script("
      var b64;
  
      fetch(url).then(r =&gt; r.blob()).then(blob =&gt; {
          var reader = new FileReader();
          reader.onload = function() {
              b64 = reader.result.replace(/^data:.+;base64,/, ''); 
          };
          reader.readAsDataURL(blob);
      });        
  
      // When `b64` is ready, I want to return it
      return b64;
  ");
  </code></pre>