<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Developer console code is not working under JavaScript of browser monitor in Open Q&amp;A</title>
    <link>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/203100#M24230</link>
    <description>&lt;P&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/2080"&gt;@AK&lt;/a&gt;&amp;nbsp;Sure you can do multiple fetch calls in your single JavaScript synthetic event. Just it must finish within a reasonable time ( I think the timeout is 100 seconds for the whole JavaScript event ).&lt;/P&gt;</description>
    <pubDate>Sat, 21 Jan 2023 21:58:09 GMT</pubDate>
    <dc:creator>Julius_Loman</dc:creator>
    <dc:date>2023-01-21T21:58:09Z</dc:date>
    <item>
      <title>Developer console code is not working under JavaScript of browser monitor</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/202557#M24113</link>
      <description>&lt;P&gt;Hello Folks,&lt;/P&gt;&lt;P&gt;I wanted to use JavaScript event of Browser click path monitor. I developed one code which ultimately returning me a string.&lt;/P&gt;&lt;P&gt;The dilemma is, when I tried to paste that code in JavaScript event space of browser click path it throws lot of syntax error like for example,&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var response = await fetch(https://someapi.com/api/);
var data = await response.json();&lt;/LI-CODE&gt;&lt;P&gt;here it gives &lt;EM&gt;&lt;STRONG&gt;Missing ";" before statement&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I build a code on developer console of chrome browser. It worked&amp;nbsp;really well there. I generally use it as a terminal&amp;nbsp;to develop and test small JScript&amp;nbsp;and modify (e.g.- console.log will get change&amp;nbsp;to api.info) it according to requirement of HTTP or Browser monitor.&lt;/P&gt;&lt;P&gt;How can I resolve above syntax errors or is it something not at all supported under JavaScript event of Browse click path monitor?&lt;/P&gt;&lt;P&gt;Can someone help here.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;AK&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 19:55:27 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/202557#M24113</guid>
      <dc:creator>AK</dc:creator>
      <dc:date>2023-01-16T19:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: Developer console code is not working under JavaScript of browser monitor</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/202570#M24118</link>
      <description>&lt;P&gt;Looks like the editor does not know the await keyword at all and . Using your snippet above gives me the following error:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;SPAN&gt;Exception was thrown by the JavaScript code: await is only valid in async functions and the top level bodies of modules&lt;/SPAN&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;which probably pretty explains why it is also not working even if you save the JavaScript synthetic event.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If you need to call an external API in your JavaScript event, you can do it &lt;A href="https://www.dynatrace.com/support/help/how-to-use-dynatrace/synthetic-monitoring/browser-monitors/browser-clickpath-events#expand--example-2-get-a-random-first-name-last-name-from-an-api-endpoint-and-set-it-during-a-sign-up-process--4" target="_self"&gt;this way&lt;/A&gt;.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;api.startAsyncSyntheticEvent();
fetch('https://randomuser.me/api/').then((resp) =&amp;gt; resp.json()).then(function(data) {
    document.getElementById('firstName').value = data.results[0].name.first;
    document.getElementById('lastName').value = data.results[0].name.lastname;
    api.finish();
}).catch(function(error) {
    api.fail('Fetch request to randomuser.me failed');
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2023 08:29:17 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/202570#M24118</guid>
      <dc:creator>Julius_Loman</dc:creator>
      <dc:date>2023-01-17T08:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: Developer console code is not working under JavaScript of browser monitor</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/203098#M24228</link>
      <description>&lt;P&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/3364"&gt;@Julius_Loman&lt;/a&gt;, Will it allow to iterate through multiple fetch call under one JavaScript event like below,&lt;/P&gt;&lt;P&gt;fetch('&lt;A href="https://someapi.com/api/'+numbers+'/values" target="_blank"&gt;https://someapi.com/api/'+numbers+'/values&lt;/A&gt;')&lt;/P&gt;&lt;P&gt;I wanted to save each value on each iteration of fetch call and use it for further processing.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Jan 2023 21:09:55 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/203098#M24228</guid>
      <dc:creator>AK</dc:creator>
      <dc:date>2023-01-21T21:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Developer console code is not working under JavaScript of browser monitor</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/203100#M24230</link>
      <description>&lt;P&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/2080"&gt;@AK&lt;/a&gt;&amp;nbsp;Sure you can do multiple fetch calls in your single JavaScript synthetic event. Just it must finish within a reasonable time ( I think the timeout is 100 seconds for the whole JavaScript event ).&lt;/P&gt;</description>
      <pubDate>Sat, 21 Jan 2023 21:58:09 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/203100#M24230</guid>
      <dc:creator>Julius_Loman</dc:creator>
      <dc:date>2023-01-21T21:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Developer console code is not working under JavaScript of browser monitor</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/203109#M24236</link>
      <description>&lt;P&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/3364"&gt;@Julius_Loman&lt;/a&gt;, yes all my calls could finish in &amp;lt; 1000ms however, my code returns &lt;SPAN&gt;[object Promise] and I'm stuck there. I tried lot of solutions from forums but none them worked.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Have you encountered&amp;nbsp;in such situation&amp;nbsp;and resolve it successfully.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jan 2023 11:30:00 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/203109#M24236</guid>
      <dc:creator>AK</dc:creator>
      <dc:date>2023-01-22T11:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Developer console code is not working under JavaScript of browser monitor</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/203114#M24237</link>
      <description>&lt;P&gt;I'm lame with JS and promises, but I guess you need something like this if I understood your requirements - fetching multiple APIs in parallel and do something with the data in a browser monitor step:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;api.startAsyncSyntheticEvent();
api.info("About to fetch some APIs");
urls = ["https://pokeapi.co/api/v2/pokemon/1", "https://pokeapi.co/api/v2/pokemon/2", "https://pokeapi.co/api/v2/pokemon/3"];
Promise.all(urls.map(url =&amp;gt;
    fetch(url).then(response =&amp;gt; response.json())
)).then(responses =&amp;gt; {
    responses.map(response =&amp;gt; api.info(response.name));
    api.finish();
}, responses =&amp;gt; {
    api.fail("Failed to fetch responses");
});&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jan 2023 19:35:24 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/203114#M24237</guid>
      <dc:creator>Julius_Loman</dc:creator>
      <dc:date>2023-01-22T19:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: Developer console code is not working under JavaScript of browser monitor</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/203115#M24238</link>
      <description>&lt;P&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/3364"&gt;@Julius_Loman&lt;/a&gt;, I'm able to resolve it. Thank you for your suggestions and taking a time to respond.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jan 2023 19:43:21 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Developer-console-code-is-not-working-under-JavaScript-of/m-p/203115#M24238</guid>
      <dc:creator>AK</dc:creator>
      <dc:date>2023-01-22T19:43:21Z</dc:date>
    </item>
  </channel>
</rss>

