Access JavaScript variables with Synthetics

Imagine that window.myVar is a JavaScript variable on example.com. I want my Synthetic which tests example.com to access that variable and use its value to inform the next steps in my script.

So far, I’ve tried variations of this:
$browser.get(‘https://example.com’).then(function() {
$browser.getWindowHandle().then(function(handle) {
console.log(handle.myVar)
});
})

Hi, @systems26: Try this:

$browser.get('https://example.com')
  .then(function() {
    return $browser.executeScript('return window.myVar;');
  })
  .then(function(value) {
    console.log(value);
  });