title: How to measure test execution duration with NewRelic Syntethics Scripts?
body: <p>I'm using the newrelic synthetics scripted browser to check some user transaction flows for reliability and performance.</p>
  <p>However the tracked duration is only about 8-10s which matches initial page load time, but not the async lazy loading of a large dataset (which is approx. 40s).</p>
  <ul>
  <li><em>How can I make new relic synthetics scripted browser tests to show actual test execution duration and not only the duration of inital request?</em></li>
  <li><em>How can I track actual synthetics scripted browser test execution time and plot on a diagram with new relic?</em></li>
  </ul>
  <p><strong>The following I already tried and seems not to fix the issue:</strong></p>
  <p><strong>Using a custom insight</strong></p>
  <p>See <a href="https://docs.newrelic.com/docs/synthetics/synthetic-monitoring/scripting-monitors/add-custom-attributes-synthetic-monitoring-data" rel="nofollow noreferrer">new relic docs for custom insights</a>.</p>
  <p>In script use:</p>
  <pre><code>var timeStart = Date.now();
  var timeEnd = Date.now();
  $util.insights.set('testDuration', (timeEnd - timeStart) );
  </code></pre>
  <p>with NRQL:</p>
  <pre><code>FROM SyntheticCheck SELECT numeric(custom.testDurration) WHERE numeric(custom.testDurration) &gt; 0 SINCE 1 day ago
  </code></pre>
  <p>However in newrelic browser this data is shown as strings and thus cannot be plot on a chart as measurement.</p>
  <ul>
  <li><em>What do I need to do to be able to make this a numeric measurement to be drawable as chart?</em></li>
  </ul>
  <p><strong>Timetracking with $har</strong></p>
  <p><a href="https://docs.newrelic.com/docs/synthetics/synthetic-monitoring/scripting-monitors/custom-timing-details/" rel="nofollow noreferrer">New relic docs recommend using $har</a></p>
  <pre><code>const testTimer = $har.addResource('Test Timer');
  testTimer.startTimer();
  await sleep(100);
  testTimer.endTimer();
  </code></pre>
  <p>However $har is resulting in error: <code>Check failed with reference error. $har is not defined</code>;</p>
  <ul>
  <li><em>How do I use $har correctly?</em></li>
  </ul>
  <p>** Checking KeySet, the custom properties show us stings**</p>
  <p>As proposed on <a href="https://discuss.newrelic.com/t/response-time-log-table/155215" rel="nofollow noreferrer">new relic forum</a> I checked the field type and it appears to be registered as string</p>
  <p>NRQL <code>FROM SyntheticCheck SELECT keyset()</code> returns</p>
  <pre><code>[
    {
      &quot;results&quot;: [
        {
          &quot;stringKeys&quot;: [
            &quot;custom.duration&quot;
            &quot;custom.testDuration&quot;,
  </code></pre>
  <p>Any other ideas how to achieve this?</p>
  <p>Thx in advance, I really appreciate your expertise!</p>