<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>JavaScript API on Grafana Labs</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/</link><description>Recent content in JavaScript API on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/k6/v2.3.x/javascript-api/index.xml" rel="self" type="application/rss+xml"/><item><title>Init context</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/init-context/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/init-context/</guid><content><![CDATA[&lt;h1 id=&#34;init-context&#34;&gt;Init context&lt;/h1&gt;


&lt;div data-shared=&#34;javascript-api/init-context.md&#34;&gt;
            &lt;p&gt;Before the k6 starts the test logic, code in the &lt;em&gt;init context&lt;/em&gt; prepares the script.
A few functions are available only in init context.
For details about the runtime, refer to the 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/test-lifecycle/&#34;&gt;Test lifecycle&lt;/a&gt;.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/init-context/open/&#34;&gt;open( filePath, [mode] )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Opens a file and reads all the contents into memory.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
]]></content><description>&lt;h1 id="init-context">Init context&lt;/h1>
&lt;div data-shared="javascript-api/init-context.md">
&lt;p>Before the k6 starts the test logic, code in the &lt;em>init context&lt;/em> prepares the script.
A few functions are available only in init context.
For details about the runtime, refer to the
&lt;a href="/docs/k6/v2.3.x/using-k6/test-lifecycle/">Test lifecycle&lt;/a>.&lt;/p></description></item><item><title>k6</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6/</guid><content><![CDATA[&lt;h1 id=&#34;k6&#34;&gt;k6&lt;/h1&gt;


&lt;div data-shared=&#34;javascript-api/k6.md&#34;&gt;
            &lt;p&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/&#34;&gt;&lt;code&gt;k6&lt;/code&gt; module&lt;/a&gt; contains k6-specific functionality.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/check/&#34;&gt;check(val, sets, [tags])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Runs one or more checks on a value and generates a pass/fail result but does not throw errors or otherwise interrupt execution upon failure.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/fail/&#34;&gt;fail([err])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Throws an error, failing and aborting the current VU script iteration immediately.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/group/&#34;&gt;group(name, fn)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Runs code inside a group. Used to organize results in a test.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/random-seed/&#34;&gt;randomSeed(int)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Set seed to get a reproducible pseudo-random number using &lt;code&gt;Math.random&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/sleep/&#34;&gt;sleep(t)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Suspends VU execution for the specified duration.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
]]></content><description>&lt;h1 id="k6">k6&lt;/h1>
&lt;div data-shared="javascript-api/k6.md">
&lt;p>The
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6/">&lt;code>k6&lt;/code> module&lt;/a> contains k6-specific functionality.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Function&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6/check/">check(val, sets, [tags])&lt;/a>&lt;/td>
&lt;td>Runs one or more checks on a value and generates a pass/fail result but does not throw errors or otherwise interrupt execution upon failure.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6/fail/">fail([err])&lt;/a>&lt;/td>
&lt;td>Throws an error, failing and aborting the current VU script iteration immediately.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6/group/">group(name, fn)&lt;/a>&lt;/td>
&lt;td>Runs code inside a group. Used to organize results in a test.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6/random-seed/">randomSeed(int)&lt;/a>&lt;/td>
&lt;td>Set seed to get a reproducible pseudo-random number using &lt;code>Math.random&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6/sleep/">sleep(t)&lt;/a>&lt;/td>
&lt;td>Suspends VU execution for the specified duration.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;/div></description></item><item><title>k6/browser</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/</guid><content><![CDATA[&lt;h1 id=&#34;browser&#34;&gt;browser&lt;/h1&gt;
&lt;p&gt;The browser module APIs are inspired by Playwright and other frontend testing frameworks.&lt;/p&gt;
&lt;p&gt;You can find examples of using &lt;a href=&#34;#browser-module-api&#34;&gt;the browser module API&lt;/a&gt; in the 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6-browser/&#34;&gt;getting started guide&lt;/a&gt;.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;To work with the browser module, make sure you are using the latest &lt;a href=&#34;https://github.com/grafana/k6/releases&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;k6 version&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;asynchronous-metric-context&#34;&gt;Asynchronous metric context&lt;/h2&gt;
&lt;p&gt;The experimental and opt-in 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/feature-flags/&#34;&gt;&lt;code&gt;async-metric-context&lt;/code&gt; feature flag&lt;/a&gt; changes how the browser module assigns tags and metadata across asynchronous operations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Page event handlers, predicates passed to &lt;code&gt;page.waitForEvent()&lt;/code&gt; and &lt;code&gt;browserContext.waitForEvent()&lt;/code&gt;, and route handlers run with the metric context active when you register them. Promise reactions and &lt;code&gt;await&lt;/code&gt; continuations created by a callback keep any context changes made by that callback.&lt;/li&gt;
&lt;li&gt;Browser network requests copy the context of the browser operation that most likely initiated them. Request and response metrics keep that context for the request&amp;rsquo;s lifetime, including redirects.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Browser network attribution is best-effort because the Chrome DevTools Protocol doesn&amp;rsquo;t always identify the JavaScript operation that caused a request. k6 uses frame and loader information when available, followed by the active or most recently completed page operation, the page&amp;rsquo;s creation or opener context, and finally the live VU context. Without the feature flag, browser metrics continue to use the context active when k6 emits them.&lt;/p&gt;
&lt;p&gt;For details about the affected network metrics and group tags, refer to 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6-browser/metrics/&#34;&gt;Browser metrics&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;properties&#34;&gt;Properties&lt;/h2&gt;
&lt;p&gt;The table below lists the properties you can import from the browser module (&lt;code&gt;&#39;k6/browser&#39;&lt;/code&gt;).&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Property&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;browser&lt;/td&gt;
              &lt;td&gt;The browser module API is the entry point for all your tests. See the &lt;a href=&#34;#example&#34;&gt;example&lt;/a&gt; and the &lt;a href=&#34;#browser-module-api&#34;&gt;API&lt;/a&gt; below.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;chromium&lt;/td&gt;
              &lt;td&gt;A 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/chromium/&#34;&gt;Chromium&lt;/a&gt; browser type that can attach to an already running Chromium-based browser instead of one that k6 launches. See 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/chromium/connectovercdp/&#34;&gt;chromium.connectOverCDP()&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;devices&lt;/td&gt;
              &lt;td&gt;Returns predefined emulation settings for many end-user devices that can be used to simulate browser behavior on a mobile device. See the &lt;a href=&#34;#devices-example&#34;&gt;devices example&lt;/a&gt; below.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;browser-module-api&#34;&gt;Browser Module API&lt;/h2&gt;
&lt;p&gt;The browser module is the entry point for all your tests, and it is what interacts with the actual web browser via &lt;a href=&#34;https://chromedevtools.github.io/devtools-protocol/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Chrome DevTools Protocol&lt;/a&gt; (CDP). It manages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/browsercontext/&#34;&gt;BrowserContext&lt;/a&gt; which is where you can set a variety of attributes to control the behavior of pages;&lt;/li&gt;
&lt;li&gt;and 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/page/&#34;&gt;Page&lt;/a&gt; which is where your rendered site is displayed.&lt;/li&gt;
&lt;/ul&gt;


&lt;div data-shared=&#34;javascript-api/k6-browser-module.md&#34;&gt;
            &lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Method&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/close/&#34;&gt;browser.close()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Closes the connection to the browser. Only available on a browser returned by 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/chromium/connectovercdp/&#34;&gt;chromium.connectOverCDP()&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/closecontext/&#34;&gt;browser.closeContext()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Closes the current 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/browsercontext/&#34;&gt;BrowserContext&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/context/&#34;&gt;browser.context()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Returns the current 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/browsercontext/&#34;&gt;BrowserContext&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/isconnected/&#34;&gt;browser.isConnected&lt;/a&gt; &lt;span class=&#34;bwipt&#34; x-init=&#34;init()&#34; x-data=&#34;bwipt()&#34; :class=&#34;{ &#39;term-hover&#39; : open }&#34;&gt;
  &lt;span x-ref=&#34;tooltip&#34;&gt;
    &lt;a
      href=&#34;https://github.com/grafana/xk6-browser/issues/453&#34;
      target=&#34;_blank&#34;
      rel=&#34;noopener noreferrer&#34;
    &gt;
      &lt;svg width=&#34;16&#34; height=&#34;16&#34; viewBox=&#34;0 0 16 16&#34; fill=&#34;none&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34; style=&#34;vertical-align: middle;&#34;&gt;&lt;path fill-rule=&#34;evenodd&#34; clip-rule=&#34;evenodd&#34; d=&#34;M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14Zm3-11v1.17c0 .33-.106.651-.306.923L9.297 8l1.397 1.907c.2.272.306.594.306.924V12H5v-1.17c0-.33.106-.651.306-.923L6.703 8 5.306 6.093A1.553 1.553 0 0 1 5 5.169V4h6Zm-1.421 6.923a.567.567 0 0 0-.11-.336L8.26 8.939a.31.31 0 0 0-.113-.095.333.333 0 0 0-.408.095l-1.208 1.648a.567.567 0 0 0-.11.335v.19h3.157v-.19Z&#34; fill=&#34;#F37B2B&#34;&gt;&lt;/path&gt;&lt;/svg&gt;
    &lt;/a&gt;
  &lt;/span&gt;
&lt;/span&gt;
&lt;/td&gt;
              &lt;td&gt;Indicates whether the &lt;a href=&#34;https://chromedevtools.github.io/devtools-protocol/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;CDP&lt;/a&gt; connection to the browser process is active or not.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/newcontext/&#34;&gt;browser.newContext([options])&lt;/a&gt; &lt;span class=&#34;bwipt&#34; x-init=&#34;init()&#34; x-data=&#34;bwipt()&#34; :class=&#34;{ &#39;term-hover&#39; : open }&#34;&gt;
  &lt;span x-ref=&#34;tooltip&#34;&gt;
    &lt;a
      href=&#34;https://github.com/grafana/xk6-browser/issues/455&#34;
      target=&#34;_blank&#34;
      rel=&#34;noopener noreferrer&#34;
    &gt;
      &lt;svg width=&#34;16&#34; height=&#34;16&#34; viewBox=&#34;0 0 16 16&#34; fill=&#34;none&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34; style=&#34;vertical-align: middle;&#34;&gt;&lt;path fill-rule=&#34;evenodd&#34; clip-rule=&#34;evenodd&#34; d=&#34;M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14Zm3-11v1.17c0 .33-.106.651-.306.923L9.297 8l1.397 1.907c.2.272.306.594.306.924V12H5v-1.17c0-.33.106-.651.306-.923L6.703 8 5.306 6.093A1.553 1.553 0 0 1 5 5.169V4h6Zm-1.421 6.923a.567.567 0 0 0-.11-.336L8.26 8.939a.31.31 0 0 0-.113-.095.333.333 0 0 0-.408.095l-1.208 1.648a.567.567 0 0 0-.11.335v.19h3.157v-.19Z&#34; fill=&#34;#F37B2B&#34;&gt;&lt;/path&gt;&lt;/svg&gt;
    &lt;/a&gt;
  &lt;/span&gt;
&lt;/span&gt;
&lt;/td&gt;
              &lt;td&gt;Creates and returns a new 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/browsercontext/&#34;&gt;BrowserContext&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/newpage/&#34;&gt;browser.newPage([options])&lt;/a&gt; &lt;span class=&#34;bwipt&#34; x-init=&#34;init()&#34; x-data=&#34;bwipt()&#34; :class=&#34;{ &#39;term-hover&#39; : open }&#34;&gt;
  &lt;span x-ref=&#34;tooltip&#34;&gt;
    &lt;a
      href=&#34;https://github.com/grafana/xk6-browser/issues/455&#34;
      target=&#34;_blank&#34;
      rel=&#34;noopener noreferrer&#34;
    &gt;
      &lt;svg width=&#34;16&#34; height=&#34;16&#34; viewBox=&#34;0 0 16 16&#34; fill=&#34;none&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34; style=&#34;vertical-align: middle;&#34;&gt;&lt;path fill-rule=&#34;evenodd&#34; clip-rule=&#34;evenodd&#34; d=&#34;M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14Zm3-11v1.17c0 .33-.106.651-.306.923L9.297 8l1.397 1.907c.2.272.306.594.306.924V12H5v-1.17c0-.33.106-.651.306-.923L6.703 8 5.306 6.093A1.553 1.553 0 0 1 5 5.169V4h6Zm-1.421 6.923a.567.567 0 0 0-.11-.336L8.26 8.939a.31.31 0 0 0-.113-.095.333.333 0 0 0-.408.095l-1.208 1.648a.567.567 0 0 0-.11.335v.19h3.157v-.19Z&#34; fill=&#34;#F37B2B&#34;&gt;&lt;/path&gt;&lt;/svg&gt;
    &lt;/a&gt;
  &lt;/span&gt;
&lt;/span&gt;
&lt;/td&gt;
              &lt;td&gt;Creates a new 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/page/&#34;&gt;Page&lt;/a&gt; in a new 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/browsercontext/&#34;&gt;BrowserContext&lt;/a&gt; and returns the page. Pages that have been opened ought to be closed using 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/page/close/&#34;&gt;&lt;code&gt;Page.close&lt;/code&gt;&lt;/a&gt;. Pages left open could potentially distort the results of Web Vital metrics.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/version/&#34;&gt;browser.version()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Returns the browser application&amp;rsquo;s version.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser } from &amp;#39;k6/browser&amp;#39;;

export const options = {
  scenarios: {
    browser: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
  thresholds: {
    checks: [&amp;#39;rate==1.0&amp;#39;],
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    await page.goto(&amp;#39;https://test.k6.io/&amp;#39;);
  } finally {
    await page.close();
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Then, you can run the test with this command. Also, see the 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6-browser/options/&#34;&gt;browser module options&lt;/a&gt; for customizing the browser module&amp;rsquo;s behavior using environment variables.&lt;/p&gt;



  

  

  

  


&lt;div data-element=&#34;tabs&#34;&gt;
  &lt;div data-element=&#34;tabs-bar&#34;&gt;
    
      &lt;div data-element=&#34;tab&#34; data-key=&#34;0&#34; data-label=&#34;Bash&#34;&gt;Bash&lt;/div&gt;
    
      &lt;div data-element=&#34;tab&#34; data-key=&#34;1&#34; data-label=&#34;docker&#34;&gt;docker&lt;/div&gt;
    
      &lt;div data-element=&#34;tab&#34; data-key=&#34;2&#34; data-label=&#34;windows&#34;&gt;windows&lt;/div&gt;
    
      &lt;div data-element=&#34;tab&#34; data-key=&#34;3&#34; data-label=&#34;windows-powershell&#34;&gt;windows-powershell&lt;/div&gt;
    
  &lt;/div&gt;
  &lt;div data-element=&#34;tab-content&#34;&gt;
    
&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;k6 run script.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;docker&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-docker&#34;&gt;# WARNING!
# The grafana/k6:master-with-browser image launches a Chrome browser by setting the
# &amp;#39;no-sandbox&amp;#39; argument. Only use it with trustworthy websites.
#
# As an alternative, you can use a Docker SECCOMP profile instead, and overwrite the
# Chrome arguments to not use &amp;#39;no-sandbox&amp;#39; such as:
# docker container run --rm -i -e K6_BROWSER_ARGS=&amp;#39;&amp;#39; --security-opt seccomp=$(pwd)/chrome.json grafana/k6:master-with-browser run - &amp;lt;script.js
#
# You can find an example of a hardened SECCOMP profile in:
# https://raw.githubusercontent.com/jfrazelle/dotfiles/master/etc/docker/seccomp/chrome.json.
docker run --rm -i grafana/k6:master-with-browser run - &amp;lt;script.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;windows&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-windows&#34;&gt;k6 run script.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;windows-powershell&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-windows-powershell&#34;&gt;k6 run script.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;devices-example&#34;&gt;Devices example&lt;/h3&gt;
&lt;p&gt;To emulate the browser behaviour on a mobile device and approximately measure the browser performance, you can import &lt;code&gt;devices&lt;/code&gt; from &lt;code&gt;k6/browser&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser, devices } from &amp;#39;k6/browser&amp;#39;;

export const options = {
  scenarios: {
    browser: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
  thresholds: {
    checks: [&amp;#39;rate==1.0&amp;#39;],
  },
};

export default async function () {
  const iphoneX = devices[&amp;#39;iPhone X&amp;#39;];
  const context = await browser.newContext(iphoneX);
  const page = await context.newPage();

  try {
    await page.goto(&amp;#39;https://test.k6.io/&amp;#39;);
  } finally {
    page.close();
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;browser-level-apis&#34;&gt;Browser-level APIs&lt;/h2&gt;


&lt;div data-shared=&#34;javascript-api/k6-browser-api.md&#34;&gt;
            &lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;k6 Class&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/browsercontext/&#34;&gt;BrowserContext&lt;/a&gt; &lt;span class=&#34;bwipt&#34; x-init=&#34;init()&#34; x-data=&#34;bwipt()&#34; :class=&#34;{ &#39;term-hover&#39; : open }&#34;&gt;
  &lt;span x-ref=&#34;tooltip&#34;&gt;
    &lt;svg width=&#34;16&#34; height=&#34;16&#34; viewBox=&#34;0 0 16 16&#34; fill=&#34;none&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34; style=&#34;vertical-align: middle;&#34;&gt;&lt;path fill-rule=&#34;evenodd&#34; clip-rule=&#34;evenodd&#34; d=&#34;M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14Zm3-11v1.17c0 .33-.106.651-.306.923L9.297 8l1.397 1.907c.2.272.306.594.306.924V12H5v-1.17c0-.33.106-.651.306-.923L6.703 8 5.306 6.093A1.553 1.553 0 0 1 5 5.169V4h6Zm-1.421 6.923a.567.567 0 0 0-.11-.336L8.26 8.939a.31.31 0 0 0-.113-.095.333.333 0 0 0-.408.095l-1.208 1.648a.567.567 0 0 0-.11.335v.19h3.157v-.19Z&#34; fill=&#34;#F37B2B&#34;&gt;&lt;/path&gt;&lt;/svg&gt;
  &lt;/span&gt;
&lt;/span&gt;
&lt;/td&gt;
              &lt;td&gt;Enables independent browser sessions with separate 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/page/&#34;&gt;Page&lt;/a&gt;s, cache, and cookies.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/elementhandle/&#34;&gt;ElementHandle&lt;/a&gt; &lt;span class=&#34;bwipt&#34; x-init=&#34;init()&#34; x-data=&#34;bwipt()&#34; :class=&#34;{ &#39;term-hover&#39; : open }&#34;&gt;
  &lt;span x-ref=&#34;tooltip&#34;&gt;
    &lt;svg width=&#34;16&#34; height=&#34;16&#34; viewBox=&#34;0 0 16 16&#34; fill=&#34;none&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34; style=&#34;vertical-align: middle;&#34;&gt;&lt;path fill-rule=&#34;evenodd&#34; clip-rule=&#34;evenodd&#34; d=&#34;M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14Zm3-11v1.17c0 .33-.106.651-.306.923L9.297 8l1.397 1.907c.2.272.306.594.306.924V12H5v-1.17c0-.33.106-.651.306-.923L6.703 8 5.306 6.093A1.553 1.553 0 0 1 5 5.169V4h6Zm-1.421 6.923a.567.567 0 0 0-.11-.336L8.26 8.939a.31.31 0 0 0-.113-.095.333.333 0 0 0-.408.095l-1.208 1.648a.567.567 0 0 0-.11.335v.19h3.157v-.19Z&#34; fill=&#34;#F37B2B&#34;&gt;&lt;/path&gt;&lt;/svg&gt;
  &lt;/span&gt;
&lt;/span&gt;
&lt;/td&gt;
              &lt;td&gt;Represents an in-page DOM element.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/frame/&#34;&gt;Frame&lt;/a&gt; &lt;span class=&#34;bwipt&#34; x-init=&#34;init()&#34; x-data=&#34;bwipt()&#34; :class=&#34;{ &#39;term-hover&#39; : open }&#34;&gt;
  &lt;span x-ref=&#34;tooltip&#34;&gt;
    &lt;svg width=&#34;16&#34; height=&#34;16&#34; viewBox=&#34;0 0 16 16&#34; fill=&#34;none&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34; style=&#34;vertical-align: middle;&#34;&gt;&lt;path fill-rule=&#34;evenodd&#34; clip-rule=&#34;evenodd&#34; d=&#34;M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14Zm3-11v1.17c0 .33-.106.651-.306.923L9.297 8l1.397 1.907c.2.272.306.594.306.924V12H5v-1.17c0-.33.106-.651.306-.923L6.703 8 5.306 6.093A1.553 1.553 0 0 1 5 5.169V4h6Zm-1.421 6.923a.567.567 0 0 0-.11-.336L8.26 8.939a.31.31 0 0 0-.113-.095.333.333 0 0 0-.408.095l-1.208 1.648a.567.567 0 0 0-.11.335v.19h3.157v-.19Z&#34; fill=&#34;#F37B2B&#34;&gt;&lt;/path&gt;&lt;/svg&gt;
  &lt;/span&gt;
&lt;/span&gt;
&lt;/td&gt;
              &lt;td&gt;Access and interact with the 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/page/&#34;&gt;&lt;code&gt;Page&lt;/code&gt;&lt;/a&gt;.&amp;rsquo;s &lt;code&gt;Frame&lt;/code&gt;s.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/jshandle/&#34;&gt;JSHandle&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Represents an in-page JavaScript object.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/keyboard/&#34;&gt;Keyboard&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Used to simulate the keyboard interactions with the associated 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/page/&#34;&gt;&lt;code&gt;Page&lt;/code&gt;&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/locator/&#34;&gt;Locator&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;The Locator API makes it easier to work with dynamically changing elements.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/mouse/&#34;&gt;Mouse&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Used to simulate the mouse interactions with the associated 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/page/&#34;&gt;&lt;code&gt;Page&lt;/code&gt;&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/page/&#34;&gt;Page&lt;/a&gt; &lt;span class=&#34;bwipt&#34; x-init=&#34;init()&#34; x-data=&#34;bwipt()&#34; :class=&#34;{ &#39;term-hover&#39; : open }&#34;&gt;
  &lt;span x-ref=&#34;tooltip&#34;&gt;
    &lt;svg width=&#34;16&#34; height=&#34;16&#34; viewBox=&#34;0 0 16 16&#34; fill=&#34;none&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34; style=&#34;vertical-align: middle;&#34;&gt;&lt;path fill-rule=&#34;evenodd&#34; clip-rule=&#34;evenodd&#34; d=&#34;M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14Zm3-11v1.17c0 .33-.106.651-.306.923L9.297 8l1.397 1.907c.2.272.306.594.306.924V12H5v-1.17c0-.33.106-.651.306-.923L6.703 8 5.306 6.093A1.553 1.553 0 0 1 5 5.169V4h6Zm-1.421 6.923a.567.567 0 0 0-.11-.336L8.26 8.939a.31.31 0 0 0-.113-.095.333.333 0 0 0-.408.095l-1.208 1.648a.567.567 0 0 0-.11.335v.19h3.157v-.19Z&#34; fill=&#34;#F37B2B&#34;&gt;&lt;/path&gt;&lt;/svg&gt;
  &lt;/span&gt;
&lt;/span&gt;
&lt;/td&gt;
              &lt;td&gt;Provides methods to interact with a single tab in a browser.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/request/&#34;&gt;Request&lt;/a&gt; &lt;span class=&#34;bwipt&#34; x-init=&#34;init()&#34; x-data=&#34;bwipt()&#34; :class=&#34;{ &#39;term-hover&#39; : open }&#34;&gt;
  &lt;span x-ref=&#34;tooltip&#34;&gt;
    &lt;svg width=&#34;16&#34; height=&#34;16&#34; viewBox=&#34;0 0 16 16&#34; fill=&#34;none&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34; style=&#34;vertical-align: middle;&#34;&gt;&lt;path fill-rule=&#34;evenodd&#34; clip-rule=&#34;evenodd&#34; d=&#34;M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14Zm3-11v1.17c0 .33-.106.651-.306.923L9.297 8l1.397 1.907c.2.272.306.594.306.924V12H5v-1.17c0-.33.106-.651.306-.923L6.703 8 5.306 6.093A1.553 1.553 0 0 1 5 5.169V4h6Zm-1.421 6.923a.567.567 0 0 0-.11-.336L8.26 8.939a.31.31 0 0 0-.113-.095.333.333 0 0 0-.408.095l-1.208 1.648a.567.567 0 0 0-.11.335v.19h3.157v-.19Z&#34; fill=&#34;#F37B2B&#34;&gt;&lt;/path&gt;&lt;/svg&gt;
  &lt;/span&gt;
&lt;/span&gt;
&lt;/td&gt;
              &lt;td&gt;Used to keep track of the request the 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/page/&#34;&gt;&lt;code&gt;Page&lt;/code&gt;&lt;/a&gt; makes.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/response/&#34;&gt;Response&lt;/a&gt; &lt;span class=&#34;bwipt&#34; x-init=&#34;init()&#34; x-data=&#34;bwipt()&#34; :class=&#34;{ &#39;term-hover&#39; : open }&#34;&gt;
  &lt;span x-ref=&#34;tooltip&#34;&gt;
    &lt;svg width=&#34;16&#34; height=&#34;16&#34; viewBox=&#34;0 0 16 16&#34; fill=&#34;none&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34; style=&#34;vertical-align: middle;&#34;&gt;&lt;path fill-rule=&#34;evenodd&#34; clip-rule=&#34;evenodd&#34; d=&#34;M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14Zm3-11v1.17c0 .33-.106.651-.306.923L9.297 8l1.397 1.907c.2.272.306.594.306.924V12H5v-1.17c0-.33.106-.651.306-.923L6.703 8 5.306 6.093A1.553 1.553 0 0 1 5 5.169V4h6Zm-1.421 6.923a.567.567 0 0 0-.11-.336L8.26 8.939a.31.31 0 0 0-.113-.095.333.333 0 0 0-.408.095l-1.208 1.648a.567.567 0 0 0-.11.335v.19h3.157v-.19Z&#34; fill=&#34;#F37B2B&#34;&gt;&lt;/path&gt;&lt;/svg&gt;
  &lt;/span&gt;
&lt;/span&gt;
&lt;/td&gt;
              &lt;td&gt;Represents the response received by the 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/page/&#34;&gt;&lt;code&gt;Page&lt;/code&gt;&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/touchscreen/&#34;&gt;Touchscreen&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Used to simulate touch interactions with the associated 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/page/&#34;&gt;&lt;code&gt;Page&lt;/code&gt;&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/worker/&#34;&gt;Worker&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Represents a &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;WebWorker&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
&lt;h2 id=&#34;browser-module-options&#34;&gt;Browser module options&lt;/h2&gt;
&lt;p&gt;You can customize the behavior of the browser module by providing browser options as environment variables.&lt;/p&gt;


&lt;div data-shared=&#34;browser/env-var-options.md&#34;&gt;
            &lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Environment Variable&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;K6_BROWSER_ARGS&lt;/td&gt;
              &lt;td&gt;Extra command line arguments to include when launching browser process. See the 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6-browser/options/#browser-arguments&#34;&gt;browser arguments&lt;/a&gt; for usage and common arguments.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;K6_BROWSER_DEBUG&lt;/td&gt;
              &lt;td&gt;All CDP messages and internal fine grained logs will be logged if set to &lt;code&gt;true&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;K6_BROWSER_EXECUTABLE_PATH&lt;/td&gt;
              &lt;td&gt;Override search for browser executable in favor of specified absolute path.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;K6_BROWSER_HEADLESS&lt;/td&gt;
              &lt;td&gt;Show browser GUI or not. &lt;code&gt;true&lt;/code&gt; by default.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;K6_BROWSER_IGNORE_DEFAULT_ARGS&lt;/td&gt;
              &lt;td&gt;Ignore any of the 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6-browser/options/#default-arguments&#34;&gt;default arguments&lt;/a&gt; included when launching a browser process.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;K6_BROWSER_TIMEOUT&lt;/td&gt;
              &lt;td&gt;Default timeout for initializing the connection to the browser instance. &lt;code&gt;&#39;30s&#39;&lt;/code&gt; if not set.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;K6_BROWSER_TRACES_METADATA&lt;/td&gt;
              &lt;td&gt;Sets additional &lt;em&gt;key-value&lt;/em&gt; metadata that is included as attributes in every span generated from browser module traces. Example: &lt;code&gt;K6_BROWSER_TRACES_METADATA=attr1=val1,attr2=val2&lt;/code&gt;. This only applies if traces generation is enabled, refer to 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/k6-options/reference/#traces-output&#34;&gt;Traces output&lt;/a&gt; for more details.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;The following command passes the browser options as environment variables to launch a headful browser with custom arguments.&lt;/p&gt;



  

  

  

  


&lt;div data-element=&#34;tabs&#34;&gt;
  &lt;div data-element=&#34;tabs-bar&#34;&gt;
    
      &lt;div data-element=&#34;tab&#34; data-key=&#34;0&#34; data-label=&#34;Bash&#34;&gt;Bash&lt;/div&gt;
    
      &lt;div data-element=&#34;tab&#34; data-key=&#34;1&#34; data-label=&#34;docker&#34;&gt;docker&lt;/div&gt;
    
      &lt;div data-element=&#34;tab&#34; data-key=&#34;2&#34; data-label=&#34;windows&#34;&gt;windows&lt;/div&gt;
    
      &lt;div data-element=&#34;tab&#34; data-key=&#34;3&#34; data-label=&#34;windows-powershell&#34;&gt;windows-powershell&lt;/div&gt;
    
  &lt;/div&gt;
  &lt;div data-element=&#34;tab-content&#34;&gt;
    
&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;K6_BROWSER_HEADLESS=false K6_BROWSER_ARGS=&amp;#39;show-property-changed-rects&amp;#39; k6 run script.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;docker&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-docker&#34;&gt;# WARNING!
# The grafana/k6:master-with-browser image launches a Chrome browser by setting the
# &amp;#39;no-sandbox&amp;#39; argument. Only use it with trustworthy websites.
#
# As an alternative, you can use a Docker SECCOMP profile instead, and overwrite the
# Chrome arguments to not use &amp;#39;no-sandbox&amp;#39; such as:
# docker container run --rm -i -e K6_BROWSER_ARGS=&amp;#39;&amp;#39; --security-opt seccomp=$(pwd)/chrome.json grafana/k6:master-with-browser run - &amp;lt;script.js
#
# You can find an example of a hardened SECCOMP profile in:
# https://raw.githubusercontent.com/jfrazelle/dotfiles/master/etc/docker/seccomp/chrome.json.
docker run --rm -i -e K6_BROWSER_HEADLESS=false -e K6_BROWSER_ARGS=&amp;#39;show-property-changed-rects&amp;#39; grafana/k6:master-with-browser run - &amp;lt;script.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;windows&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-windows&#34;&gt;set &amp;#34;K6_BROWSER_HEADLESS=false&amp;#34; &amp;amp;&amp;amp; set &amp;#34;K6_BROWSER_ARGS=&amp;#39;show-property-changed-rects&amp;#39; &amp;#34; &amp;amp;&amp;amp; k6 run script.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;windows-powershell&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-windows-powershell&#34;&gt;$env:K6_BROWSER_HEADLESS=&amp;#34;false&amp;#34; ; $env:K6_BROWSER_ARGS=&amp;#39;show-property-changed-rects&amp;#39; ; k6 run script.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;browser-arguments&#34;&gt;Browser arguments&lt;/h3&gt;
&lt;p&gt;The following table highlights commonly useful arguments you can pass via the &lt;code&gt;K6_BROWSER_ARGS&lt;/code&gt; environment variable. Most tests run without extra arguments, because the browser module already uses sensible &lt;a href=&#34;#default-arguments&#34;&gt;defaults&lt;/a&gt;. Set these extra arguments only when you need to debug or adapt to your environment. For a complete list, refer to &lt;a href=&#34;https://peter.sh/experiments/chromium-command-line-switches/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Chromium command line switches&lt;/a&gt;.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Arguments should not start with &lt;code&gt;--&lt;/code&gt; when passing them to &lt;code&gt;K6_BROWSER_ARGS&lt;/code&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Argument&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;disable-web-security&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;Disables the same-origin policy. Useful when testing a site whose CORS configuration blocks the browser from interacting with cross-origin iframes or assets.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;ignore-certificate-errors&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;Ignores TLS certificate errors. Useful when testing against hosts with self-signed or otherwise invalid certificates.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;no-sandbox&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;Disables the Chromium sandbox. Needed when running as root inside Docker, CI, or Kubernetes. Only use with trustworthy targets.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;proxy-server&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;Routes browser traffic through an HTTP or SOCKS proxy. Pass the proxy address (&lt;code&gt;host:port&lt;/code&gt;) as the value. Useful for corporate proxies or inspecting traffic with tools like mitmproxy.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;For example, pass the following arguments to the &lt;code&gt;K6_BROWSER_ARGS&lt;/code&gt; environment variable to ignore TLS certificate errors and route browser traffic through a proxy when running a browser test:&lt;/p&gt;



  

  

  

  


&lt;div data-element=&#34;tabs&#34;&gt;
  &lt;div data-element=&#34;tabs-bar&#34;&gt;
    
      &lt;div data-element=&#34;tab&#34; data-key=&#34;0&#34; data-label=&#34;Bash&#34;&gt;Bash&lt;/div&gt;
    
      &lt;div data-element=&#34;tab&#34; data-key=&#34;1&#34; data-label=&#34;docker&#34;&gt;docker&lt;/div&gt;
    
      &lt;div data-element=&#34;tab&#34; data-key=&#34;2&#34; data-label=&#34;windows&#34;&gt;windows&lt;/div&gt;
    
      &lt;div data-element=&#34;tab&#34; data-key=&#34;3&#34; data-label=&#34;windows-powershell&#34;&gt;windows-powershell&lt;/div&gt;
    
  &lt;/div&gt;
  &lt;div data-element=&#34;tab-content&#34;&gt;
    
&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;K6_BROWSER_ARGS=&amp;#39;ignore-certificate-errors,proxy-server=127.0.0.1:8080&amp;#39; k6 run script.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;docker&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-docker&#34;&gt;docker run --rm -i -e K6_BROWSER_ARGS=&amp;#39;ignore-certificate-errors,proxy-server=127.0.0.1:8080&amp;#39; grafana/k6:master-with-browser run - &amp;lt;script.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;windows&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-windows&#34;&gt;set &amp;#34;K6_BROWSER_ARGS=&amp;#39;ignore-certificate-errors,proxy-server=127.0.0.1:8080&amp;#39;&amp;#34; &amp;amp;&amp;amp; k6 run script.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;windows-powershell&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-windows-powershell&#34;&gt;$env:K6_BROWSER_ARGS=&amp;#39;ignore-certificate-errors,proxy-server=127.0.0.1:8080&amp;#39; ; k6 run script.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

  &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

        
]]></content><description>&lt;h1 id="browser">browser&lt;/h1>
&lt;p>The browser module APIs are inspired by Playwright and other frontend testing frameworks.&lt;/p>
&lt;p>You can find examples of using &lt;a href="#browser-module-api">the browser module API&lt;/a> in the
&lt;a href="/docs/k6/v2.3.x/using-k6-browser/">getting started guide&lt;/a>.&lt;/p></description></item><item><title>k6/crypto</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-crypto/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-crypto/</guid><content><![CDATA[&lt;h1 id=&#34;k6crypto&#34;&gt;k6/crypto&lt;/h1&gt;


&lt;div data-shared=&#34;crypto-module.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;A module with a better and standard API exists.
&lt;br&gt;
&lt;br&gt;
The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/crypto/&#34;&gt;crypto module&lt;/a&gt; partially implements the &lt;a href=&#34;https://www.w3.org/TR/WebCryptoAPI/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;WebCrypto API&lt;/a&gt;, supporting more features than 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/&#34;&gt;k6/crypto&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        


&lt;div data-shared=&#34;javascript-api/k6-crypto.md&#34;&gt;
            &lt;p&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/&#34;&gt;&lt;code&gt;k6/crypto&lt;/code&gt; module&lt;/a&gt; provides common hashing functionality available in the GoLang &lt;a href=&#34;https://golang.org/pkg/crypto/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;crypto&lt;/a&gt; package.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/createhash/&#34;&gt;createHash(algorithm)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Create a Hasher object, allowing the user to add data to hash multiple times, and extract hash digests along the way.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/createhmac/&#34;&gt;createHMAC(algorithm, secret)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Create an HMAC hashing object, allowing the user to add data to hash multiple times, and extract hash digests along the way.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/hmac/&#34;&gt;hmac(algorithm, secret, data, outputEncoding)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Use HMAC to sign an input string.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/md4/&#34;&gt;md4(input, outputEncoding)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Use MD4 to hash an input string.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/md5/&#34;&gt;md5(input, outputEncoding)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Use MD5 to hash an input string.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/randombytes/&#34;&gt;randomBytes(int)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Return an array with a number of cryptographically random bytes.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/ripemd160/&#34;&gt;ripemd160(input, outputEncoding)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Use RIPEMD-160 to hash an input string.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/sha1/&#34;&gt;sha1(input, outputEncoding)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Use SHA-1 to hash an input string.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/sha256/&#34;&gt;sha256(input, outputEncoding)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Use SHA-256 to hash an input string.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/sha384/&#34;&gt;sha384(input, outputEncoding)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Use SHA-384 to hash an input string.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/sha512/&#34;&gt;sha512(input, outputEncoding)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Use SHA-512 to hash an input string.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/sha512_224/&#34;&gt;sha512_224(input, outputEncoding)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Use SHA-512/224 to hash an input string.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/sha512_256/&#34;&gt;sha512_256(input, outputEncoding)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Use SHA-512/256 to hash an input string.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Class&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/hasher/&#34;&gt;Hasher&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Object returned by 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-crypto/createhash/&#34;&gt;crypto.createHash()&lt;/a&gt;. It allows adding more data to be hashed and to extract digests along the way.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
]]></content><description>&lt;h1 id="k6crypto">k6/crypto&lt;/h1>
&lt;div data-shared="crypto-module.md">
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>A module with a better and standard API exists.
&lt;br>
&lt;br>
The
&lt;a href="/docs/k6/v2.3.x/javascript-api/crypto/">crypto module&lt;/a> partially implements the &lt;a href="https://www.w3.org/TR/WebCryptoAPI/" target="_blank" rel="noopener noreferrer">WebCrypto API&lt;/a>, supporting more features than
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-crypto/">k6/crypto&lt;/a>.&lt;/p>&lt;/blockquote>&lt;/div>
&lt;/div>
&lt;div data-shared="javascript-api/k6-crypto.md">
&lt;p>The
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-crypto/">&lt;code>k6/crypto&lt;/code> module&lt;/a> provides common hashing functionality available in the GoLang &lt;a href="https://golang.org/pkg/crypto/" target="_blank" rel="noopener noreferrer">crypto&lt;/a> package.&lt;/p></description></item><item><title>k6/data</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-data/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-data/</guid><content><![CDATA[&lt;h1 id=&#34;k6data&#34;&gt;k6/data&lt;/h1&gt;


&lt;div data-shared=&#34;javascript-api/k6-data.md&#34;&gt;
            &lt;p&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-data/&#34;&gt;&lt;code&gt;k6/data&lt;/code&gt; module&lt;/a&gt; provides helpers to work with data.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Class/Method&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-data/sharedarray/&#34;&gt;SharedArray&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;read-only array like structure that shares memory between VUs&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
]]></content><description>&lt;h1 id="k6data">k6/data&lt;/h1>
&lt;div data-shared="javascript-api/k6-data.md">
&lt;p>The
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-data/">&lt;code>k6/data&lt;/code> module&lt;/a> provides helpers to work with data.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Class/Method&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-data/sharedarray/">SharedArray&lt;/a>&lt;/td>
&lt;td>read-only array like structure that shares memory between VUs&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;/div></description></item><item><title>k6/encoding</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-encoding/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-encoding/</guid><content><![CDATA[&lt;h1 id=&#34;k6encoding&#34;&gt;k6/encoding&lt;/h1&gt;


&lt;div data-shared=&#34;javascript-api/k6-encoding.md&#34;&gt;
            &lt;p&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-encoding/&#34;&gt;&lt;code&gt;k6/encoding&lt;/code&gt; module&lt;/a&gt; provides &lt;a href=&#34;https://en.wikipedia.org/wiki/Base64&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;base64&lt;/a&gt;
encoding/decoding as defined by &lt;a href=&#34;https://tools.ietf.org/html/rfc4648&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;RFC4648&lt;/a&gt;.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-encoding/b64decode/&#34;&gt;b64decode(input, [encoding], [format])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Base64 decode a string.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-encoding/b64encode/&#34;&gt;b64encode(input, [encoding])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Base64 encode a string.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
]]></content><description>&lt;h1 id="k6encoding">k6/encoding&lt;/h1>
&lt;div data-shared="javascript-api/k6-encoding.md">
&lt;p>The
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-encoding/">&lt;code>k6/encoding&lt;/code> module&lt;/a> provides &lt;a href="https://en.wikipedia.org/wiki/Base64" target="_blank" rel="noopener noreferrer">base64&lt;/a>
encoding/decoding as defined by &lt;a href="https://tools.ietf.org/html/rfc4648" target="_blank" rel="noopener noreferrer">RFC4648&lt;/a>.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Function&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-encoding/b64decode/">b64decode(input, [encoding], [format])&lt;/a>&lt;/td>
&lt;td>Base64 decode a string.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-encoding/b64encode/">b64encode(input, [encoding])&lt;/a>&lt;/td>
&lt;td>Base64 encode a string.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;/div></description></item><item><title>k6/execution</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-execution/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-execution/</guid><content><![CDATA[&lt;h1 id=&#34;k6execution&#34;&gt;k6/execution&lt;/h1&gt;


&lt;div data-shared=&#34;javascript-api/k6-execution-intro.md&#34;&gt;
            &lt;p&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-execution/&#34;&gt;&lt;code&gt;k6/execution&lt;/code&gt; module&lt;/a&gt; provides the capability to get information about the current test execution state inside the test script. You can read in your script the execution state during the test execution and change your script logic based on the current state.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;k6/execution&lt;/code&gt; provides the test execution information with the following properties:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-execution/#instance&#34;&gt;instance&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-execution/#scenario&#34;&gt;scenario&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-execution/#test&#34;&gt;test&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-execution/#vu&#34;&gt;vu&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

        
&lt;div class=&#34;code-group&#34; data-props=&#39;{&#34;labels&#34;: [], &#34;lineNumbers&#34;: [true]}&#39;&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import exec from &amp;#39;k6/execution&amp;#39;;

export const options = {
  scenarios: {
    myscenario: {
      // this will be the returned name
      executor: &amp;#39;shared-iterations&amp;#39;,
      maxDuration: &amp;#39;30m&amp;#39;,
    },
  },
};

export default function () {
  console.log(exec.scenario.name); // myscenario
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;ℹ️ &lt;strong&gt;Identifiers&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;All unique identifiers are sequentially generated starting from a base of zero (iterations) or one (VU IDs). In distributed/cloud test runs, the test-wide iteration numbers and VU identifiers are still going to be unique across instances, though there might be gaps in the sequences when, for example, some instances execute faster iterations than others or allocate more VUs mid-test.&lt;/p&gt;&lt;/blockquote&gt;
&lt;h3 id=&#34;instance&#34;&gt;instance&lt;/h3&gt;
&lt;p&gt;The instance object provides information associated with the load generator instance. You can think of it as the current running k6 process, which will likely be a single process if you are running k6 on your local machine. When running a cloud/distributed test with multiple load generator instances, the values of the following properties can differ across instances.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Property&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;iterationsInterrupted&lt;/td&gt;
              &lt;td&gt;integer&lt;/td&gt;
              &lt;td&gt;The number of prematurely interrupted iterations in the current instance.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;iterationsCompleted&lt;/td&gt;
              &lt;td&gt;integer&lt;/td&gt;
              &lt;td&gt;The number of completed iterations in the current instance.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;vusActive&lt;/td&gt;
              &lt;td&gt;integer&lt;/td&gt;
              &lt;td&gt;The number of active VUs.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;vusInitialized&lt;/td&gt;
              &lt;td&gt;integer&lt;/td&gt;
              &lt;td&gt;The number of currently initialized VUs.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;currentTestRunDuration&lt;/td&gt;
              &lt;td&gt;float&lt;/td&gt;
              &lt;td&gt;The time passed from the start of the current test run in milliseconds.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;scenario&#34;&gt;scenario&lt;/h3&gt;
&lt;p&gt;Meta information and execution details about the current running 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/&#34;&gt;scenario&lt;/a&gt;.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Property&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;name&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;The assigned name of the running scenario.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;executor&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;The name of the running 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/#executors&#34;&gt;Executor&lt;/a&gt; type.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;startTime&lt;/td&gt;
              &lt;td&gt;integer&lt;/td&gt;
              &lt;td&gt;The Unix timestamp in milliseconds when the scenario started.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;progress&lt;/td&gt;
              &lt;td&gt;float&lt;/td&gt;
              &lt;td&gt;Percentage in a 0 to 1 interval of the scenario progress.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;iterationInInstance&lt;/td&gt;
              &lt;td&gt;integer&lt;/td&gt;
              &lt;td&gt;The unique and zero-based sequential number of the current iteration in the scenario, across the current instance.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;iterationInTest&lt;/td&gt;
              &lt;td&gt;integer&lt;/td&gt;
              &lt;td&gt;The unique and zero-based sequential number of the current iteration in the scenario. It is unique in all k6 execution modes - in local, cloud and distributed/segmented test runs. However, while every instance will get non-overlapping index values in cloud/distributed tests, they might iterate over them at different speeds, so the values won&amp;rsquo;t be sequential across them.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;test&#34;&gt;test&lt;/h3&gt;
&lt;p&gt;Control the test execution.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Property&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;abort([String])&lt;/td&gt;
              &lt;td&gt;function&lt;/td&gt;
              &lt;td&gt;It aborts the test run with the exit code &lt;code&gt;108&lt;/code&gt;, and an optional string parameter can provide an error message. Aborting the test will not prevent the &lt;code&gt;teardown()&lt;/code&gt; execution.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;fail([String])&lt;/td&gt;
              &lt;td&gt;function&lt;/td&gt;
              &lt;td&gt;It fails the test run with the exit code &lt;code&gt;110&lt;/code&gt;, and an optional string parameter can provide an error message. Failing the test will not interrupt test execution, allowing iterations to finish normally.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;options&lt;/td&gt;
              &lt;td&gt;Object&lt;/td&gt;
              &lt;td&gt;It returns an object with all the test options as properties. The options&amp;rsquo; values are consolidated following the 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/k6-options/how-to/#order-of-precedence&#34;&gt;order of precedence&lt;/a&gt; and derived if shortcuts have been used. It returns &lt;code&gt;null&lt;/code&gt; for properties where the relative option hasn&amp;rsquo;t been defined.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;vu&#34;&gt;vu&lt;/h3&gt;
&lt;p&gt;Meta information and execution details about the current vu.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Property&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;iterationInInstance&lt;/td&gt;
              &lt;td&gt;integer&lt;/td&gt;
              &lt;td&gt;The identifier of the iteration in the current instance for this VU. This is only unique for current VU and this instance (if multiple instances). This keeps being aggregated if a given VU is reused between multiple scenarios.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;iterationInScenario&lt;/td&gt;
              &lt;td&gt;integer&lt;/td&gt;
              &lt;td&gt;The identifier of the iteration in the current scenario for this VU. This is only unique for current VU and scenario it is currently executing.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;idInInstance&lt;/td&gt;
              &lt;td&gt;integer&lt;/td&gt;
              &lt;td&gt;The identifier of the VU across the instance. Not unique across multiple instances.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;idInTest&lt;/td&gt;
              &lt;td&gt;integer&lt;/td&gt;
              &lt;td&gt;The globally unique (across the whole test run) identifier of the VU.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;metrics.tags&lt;/td&gt;
              &lt;td&gt;object&lt;/td&gt;
              &lt;td&gt;The map that gives control over 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/tags-and-groups/#tags&#34;&gt;VU&amp;rsquo;s Tags&lt;/a&gt;. The Tags will be included in every metric emitted by the VU and the Tags&amp;rsquo; state is maintained across different iterations of the same Scenario while the VU exists. Check how to use it in the &lt;a href=&#34;#tags&#34;&gt;example&lt;/a&gt; below.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;metrics.metadata&lt;/td&gt;
              &lt;td&gt;object&lt;/td&gt;
              &lt;td&gt;The map that gives control over VU&amp;rsquo;s Metadata. The Metadata will be included in every metric emitted by the VU and the Metadata&amp;rsquo;s state is maintained across different iterations of the same Scenario while the VU exists. Check how to use it in the &lt;a href=&#34;#metadata&#34;&gt;example&lt;/a&gt; below.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;div class=&#34;collapse&#34; x-data=&#34;app_collapse()&#34;&gt;
  &lt;button class=&#34;collapse-trigger&#34; @click=&#34;toggle()&#34;&gt;
    &lt;span class=&#34;body-large&#34;&gt;Setting vu.metrics.tags&lt;/span&gt;
    &lt;span class=&#34;collapse-trigger__icon&#34; :class=&#34;{ &#39;collapse-trigger__icon-open&#39; : open }&#34;&gt;
      
  &lt;svg width=&#34;27&#34; height=&#34;26&#34; viewBox=&#34;0 0 27 26&#34; fill=&#34;none&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;
&lt;path opacity=&#34;0.2&#34; d=&#34;M1.73047 12.8359C1.73047 19.4634 7.10305 24.8359 13.7305 24.8359C20.3579 24.8359 25.7305 19.4634 25.7305 12.8359C25.7305 6.20852 20.3579 0.835937 13.7305 0.835937C7.10305 0.835937 1.73047 6.20852 1.73047 12.8359Z&#34; stroke=&#34;black&#34; stroke-width=&#34;1.5&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;/&gt;
&lt;path d=&#34;M18.2344 12.8359L9.23438 12.8359&#34; stroke=&#34;black&#34; stroke-width=&#34;1.5&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;/&gt;
&lt;path d=&#34;M13.7344 8.33594L13.7344 17.3359&#34; stroke=&#34;black&#34; stroke-width=&#34;1.5&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;/&gt;
&lt;/svg&gt;


    &lt;/span&gt;
  &lt;/button&gt;
  &lt;div class=&#34;collapse-content&#34; x-ref=&#34;content&#34; hidden=&#34;until-found&#34;&gt;
    &lt;div class=&#34;collapse-content__inner&#34; x-ref=&#34;content-inner&#34;&gt;&lt;p&gt;Setting a Tag with the same key as a 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/k6-options/reference/#system-tags&#34;&gt;system tag&lt;/a&gt; is allowed, but it requires attention to avoid unexpected results. Overwriting system tags will not throw an error, but in most cases will not actually change the value of the emitted metrics as expected. For example, trying to set the &lt;code&gt;url&lt;/code&gt; tag value will not result in a changed tag value when &lt;code&gt;http.get()&lt;/code&gt; is called, since the tag value is determined by the HTTP request itself. However, it will add the tag &lt;code&gt;url&lt;/code&gt; to the metric samples emitted by a &lt;code&gt;check()&lt;/code&gt; or &lt;code&gt;metric.add()&lt;/code&gt;, which is probably not the desired behavior. On the other hand, setting the &lt;code&gt;name&lt;/code&gt; tag will work as expected, since that was already supported for &lt;code&gt;http.*&lt;/code&gt; methods, for the purposes of the 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/http-requests/#url-grouping&#34;&gt;URL Grouping&lt;/a&gt; feature.&lt;/p&gt;
&lt;p&gt;Not all the types are accepted as a tag value: k6 supports strings, numbers and boolean types. Under the hood, the &lt;code&gt;tags&lt;/code&gt; object handles a Tag as a &lt;code&gt;String&lt;/code&gt; key-value pair, so all the types will be implicitly converted into a string. If one of the denied types is used (e.g. Object or Array) and the 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/k6-options/reference/#throw&#34;&gt;&lt;code&gt;throw&lt;/code&gt; option&lt;/a&gt; is set, an exception will be thrown. Otherwise, only a warning is printed and the tag value will be discarded.&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&#34;examples-and-use-cases&#34;&gt;Examples and use cases&lt;/h2&gt;
&lt;h3 id=&#34;getting-unique-data-once&#34;&gt;Getting unique data once&lt;/h3&gt;
&lt;p&gt;This is a common use case for data parameterization, you can read the 
    &lt;a href=&#34;/docs/k6/v2.3.x/examples/data-parameterization/#retrieving-unique-data&#34;&gt;examples&lt;/a&gt; using &lt;code&gt;scenario.iterationInTest&lt;/code&gt; and &lt;code&gt;vu.idInTest&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;timing-operations&#34;&gt;Timing operations&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;startTime&lt;/code&gt; property from the &lt;code&gt;scenario&lt;/code&gt; object can be used to time operations.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import exec from &amp;#39;k6/execution&amp;#39;;

export default function () {
  // do some long operations
  // ...
  console.log(`step1: scenario ran for ${new Date() - new Date(exec.scenario.startTime)}ms`);

  // some more long operations
  //...
  console.log(`step2: scenario ran for ${new Date() - new Date(exec.scenario.startTime)}ms`);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;script-naming&#34;&gt;Script naming&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;name&lt;/code&gt; property can be used for executing the logic based on which script is currently running.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip&lt;/strong&gt;:
If you need to run 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/advanced-examples/#using-multiple-scenarios&#34;&gt;multiple scenarios&lt;/a&gt; in your script you can use &lt;code&gt;exec&lt;/code&gt; option achieve a similar goal&lt;/p&gt;&lt;/blockquote&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import exec from &amp;#39;k6/execution&amp;#39;;

export const options = {
  scenarios: {
    &amp;#39;the-first&amp;#39;: {
      // ...
    },
    &amp;#39;the-second&amp;#39;: {
      // ...
    },
  },
};

export default function () {
  if (exec.scenario.name === &amp;#39;the-first&amp;#39;) {
    // do some logic during this scenario
  } else {
    // do some other logic in the others
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;test-abort&#34;&gt;Test Abort&lt;/h3&gt;
&lt;p&gt;Aborting is possible during initialization:&lt;/p&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import exec from &amp;#39;k6/execution&amp;#39;;
exec.test.abort();&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As well as inside the &lt;code&gt;default&lt;/code&gt; function:&lt;/p&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import exec from &amp;#39;k6/execution&amp;#39;;

export default function () {
  // Note that you can abort with a specific message too
  exec.test.abort(&amp;#39;this is the reason&amp;#39;);
}

export function teardown() {
  console.log(&amp;#39;teardown will still be called after test.abort()&amp;#39;);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;test-fail&#34;&gt;Test Fail&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;execution.test.fail&lt;/code&gt; function enables controlled test failure reporting without interrupting the test execution. When called, this method marks the entire test run as failed while allowing all iterations to complete normally. The test will exit with code &lt;code&gt;110&lt;/code&gt;, making failures detectable by external systems. This provides graceful error handling for scenarios akin to &lt;a href=&#34;https://github.com/grafana/k6-jslib-testing&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;functional testing&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import http from &amp;#39;k6/http&amp;#39;;
import exec from &amp;#39;k6/execution&amp;#39;;

export const options = {
  iterations: 10,
};

export default function () {
  http.get(&amp;#39;https://quickpizza.grafana.com&amp;#39;);

  if (exec.vu.iterationInInstance === 3) {
    exec.test.fail(`iteration ${exec.vu.iterationInInstance}: marked the test as failed`);
  }

  console.log(`iteration ${exec.vu.iterationInInstance} executed`);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;get-test-options&#34;&gt;Get test options&lt;/h3&gt;
&lt;p&gt;Get the consolidated and derived options&amp;rsquo; values&lt;/p&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import exec from &amp;#39;k6/execution&amp;#39;;

export const options = {
  stages: [
    { duration: &amp;#39;5s&amp;#39;, target: 100 },
    { duration: &amp;#39;5s&amp;#39;, target: 50 },
  ],
};

export default function () {
  console.log(exec.test.options.paused); // null
  console.log(exec.test.options.scenarios.default.stages[0].target); // 100
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;tags&#34;&gt;Tags&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;vu.metrics.tags&lt;/code&gt; property can be used for getting or setting 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/tags-and-groups/#tags&#34;&gt;VU&amp;rsquo;s tags&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import http from &amp;#39;k6/http&amp;#39;;
import exec from &amp;#39;k6/execution&amp;#39;;

export default function () {
  exec.vu.metrics.tags[&amp;#39;mytag&amp;#39;] = &amp;#39;value1&amp;#39;;
  exec.vu.metrics.tags[&amp;#39;mytag2&amp;#39;] = 2;

  // the metrics these HTTP requests emit will get tagged with `mytag` and `mytag2`:
  http.batch([&amp;#39;https://test.k6.io&amp;#39;, &amp;#39;https://quickpizza.grafana.com&amp;#39;]);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;vu.tags&lt;/code&gt; (without &lt;code&gt;metrics&lt;/code&gt;) can also be used, but is deprecated for the more context-specific variant.&lt;/p&gt;
&lt;h3 id=&#34;metadata&#34;&gt;Metadata&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;vu.metrics.metadata&lt;/code&gt; property can be used for getting or setting VU&amp;rsquo;s metadata. It is similar to &lt;code&gt;tags&lt;/code&gt;, but can be used for high cardinality data. It also can not be used in thresholds and will likely be handled differently by each output.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import http from &amp;#39;k6/http&amp;#39;;
import exec from &amp;#39;k6/execution&amp;#39;;

export default function () {
  exec.vu.metrics.metadata[&amp;#39;trace_id&amp;#39;] = &amp;#39;somecoolide&amp;#39;;

  // the metrics these HTTP requests emit will get the metadata `trace_id`:
  http.batch([&amp;#39;https://test.k6.io&amp;#39;, &amp;#39;https://quickpizza.grafana.com&amp;#39;]);

  delete exec.vu.metrics.metadata[&amp;#39;trace_id&amp;#39;]; // this will unset it
  // which will make the metrics these requests to not have the metadata `trace_id` set on them.
  http.batch([&amp;#39;https://test.k6.io&amp;#39;, &amp;#39;https://quickpizza.grafana.com&amp;#39;]);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="k6execution">k6/execution&lt;/h1>
&lt;div data-shared="javascript-api/k6-execution-intro.md">
&lt;p>The
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-execution/">&lt;code>k6/execution&lt;/code> module&lt;/a> provides the capability to get information about the current test execution state inside the test script. You can read in your script the execution state during the test execution and change your script logic based on the current state.&lt;/p></description></item><item><title>k6/experimental</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/</guid><content><![CDATA[&lt;h1 id=&#34;k6experimental&#34;&gt;k6/experimental&lt;/h1&gt;


&lt;div data-shared=&#34;experimental-module.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;This is an experimental module.
&lt;br&gt;
&lt;br&gt;
While we intend to keep experimental modules as stable as possible, we may need to introduce breaking changes. This could happen at future k6 releases until the module becomes fully stable and graduates as a k6 core module. For more information, refer to the 
    &lt;a href=&#34;/docs/k6/v2.3.x/reference/versioning-and-stability-guarantees/#experimental&#34;&gt;versioning and stability guarantees document&lt;/a&gt;.
&lt;br&gt;
&lt;br&gt;
Experimental modules maintain a high level of stability and follow regular maintenance and security measures. Feel free to &lt;a href=&#34;https://github.com/grafana/k6/issues&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;open an issue&lt;/a&gt; if you have any feedback or suggestions.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        


&lt;div data-shared=&#34;javascript-api/k6-experimental.md&#34;&gt;
            &lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Modules&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/&#34;&gt;csv&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Provides support for efficient and convenient parsing of CSV files.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/fs/&#34;&gt;fs&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Provides a memory-efficient way to handle file interactions within your test scripts.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/&#34;&gt;streams&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Provides an implementation of the Streams API specification, offering support for defining and consuming readable streams.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
]]></content><description>&lt;h1 id="k6experimental">k6/experimental&lt;/h1>
&lt;div data-shared="experimental-module.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>This is an experimental module.
&lt;br>
&lt;br>
While we intend to keep experimental modules as stable as possible, we may need to introduce breaking changes. This could happen at future k6 releases until the module becomes fully stable and graduates as a k6 core module. For more information, refer to the
&lt;a href="/docs/k6/v2.3.x/reference/versioning-and-stability-guarantees/#experimental">versioning and stability guarantees document&lt;/a>.
&lt;br>
&lt;br>
Experimental modules maintain a high level of stability and follow regular maintenance and security measures. Feel free to &lt;a href="https://github.com/grafana/k6/issues" target="_blank" rel="noopener noreferrer">open an issue&lt;/a> if you have any feedback or suggestions.&lt;/p></description></item><item><title>k6/html</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-html/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-html/</guid><content><![CDATA[&lt;h1 id=&#34;k6html&#34;&gt;k6/html&lt;/h1&gt;


&lt;div data-shared=&#34;javascript-api/k6-html.md&#34;&gt;
            &lt;p&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-html/&#34;&gt;&lt;code&gt;k6/html&lt;/code&gt; module&lt;/a&gt; contains functionality for HTML parsing.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-html/parsehtml/&#34;&gt;parseHTML(src)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Parse an HTML string and populate a 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-html/selection/&#34;&gt;Selection&lt;/a&gt; object.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Class&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-html/element/&#34;&gt;Element&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;An HTML DOM element as returned by the 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-html/selection/&#34;&gt;Selection&lt;/a&gt; API.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-html/selection/&#34;&gt;Selection&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A jQuery-like API for accessing HTML DOM elements.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
]]></content><description>&lt;h1 id="k6html">k6/html&lt;/h1>
&lt;div data-shared="javascript-api/k6-html.md">
&lt;p>The
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-html/">&lt;code>k6/html&lt;/code> module&lt;/a> contains functionality for HTML parsing.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Function&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-html/parsehtml/">parseHTML(src)&lt;/a>&lt;/td>
&lt;td>Parse an HTML string and populate a
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-html/selection/">Selection&lt;/a> object.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Class&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-html/element/">Element&lt;/a>&lt;/td>
&lt;td>An HTML DOM element as returned by the
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-html/selection/">Selection&lt;/a> API.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-html/selection/">Selection&lt;/a>&lt;/td>
&lt;td>A jQuery-like API for accessing HTML DOM elements.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;/div></description></item><item><title>k6/http</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-http/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-http/</guid><content><![CDATA[&lt;h1 id=&#34;k6http&#34;&gt;k6/http&lt;/h1&gt;


&lt;div data-shared=&#34;javascript-api/k6-http.md&#34;&gt;
            &lt;p&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/&#34;&gt;&lt;code&gt;k6/http&lt;/code&gt; module&lt;/a&gt; contains functionality for performing HTTP transactions.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/batch/&#34;&gt;batch( requests )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Issue multiple HTTP requests in parallel (like e.g. browsers tend to do).&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/cookiejar-method/&#34;&gt;cookieJar()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Get active HTTP Cookie jar.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/del/&#34;&gt;del( url, [body], [params] )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Issue an HTTP DELETE request.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/file/&#34;&gt;file( data, [filename], [contentType] )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Create a file object that is used for building multi-part requests.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/get/&#34;&gt;get( url, [params] )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Issue an HTTP GET request.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/head/&#34;&gt;head( url, [params] )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Issue an HTTP HEAD request.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/options/&#34;&gt;options( url, [body], [params] )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Issue an HTTP OPTIONS request.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/patch/&#34;&gt;patch( url, [body], [params] )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Issue an HTTP PATCH request.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/post/&#34;&gt;post( url, [body], [params] )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Issue an HTTP POST request.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/put/&#34;&gt;put( url, [body], [params] )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Issue an HTTP PUT request.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/request/&#34;&gt;request( method, url, [body], [params] )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Issue any type of HTTP request.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/asyncrequest/&#34;&gt;asyncRequest( method, url, [body], [params] )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Issue any type of HTTP request asynchronously.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/set-response-callback/&#34;&gt;setResponseCallback(expectedStatuses)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Sets a response callback to mark responses as expected.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/url/&#34;&gt;url`url`&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Creates a URL with a name tag. Read more on 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/http-requests/#url-grouping&#34;&gt;URL Grouping&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/expected-statuses/&#34;&gt;expectedStatuses( statusCodes )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Create a callback for setResponseCallback that checks status codes.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Class&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/cookiejar/&#34;&gt;CookieJar&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Used for storing cookies, set by the server and/or added by the client.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/filedata/&#34;&gt;FileData&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Used for wrapping data representing a file when doing multipart requests (file uploads).&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/params/&#34;&gt;Params&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Used for setting various HTTP request-specific parameters such as headers, cookies, etc.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/response/&#34;&gt;Response&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Returned by the http.* methods that generate HTTP requests.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
]]></content><description>&lt;h1 id="k6http">k6/http&lt;/h1>
&lt;div data-shared="javascript-api/k6-http.md">
&lt;p>The
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/">&lt;code>k6/http&lt;/code> module&lt;/a> contains functionality for performing HTTP transactions.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Function&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/batch/">batch( requests )&lt;/a>&lt;/td>
&lt;td>Issue multiple HTTP requests in parallel (like e.g. browsers tend to do).&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/cookiejar-method/">cookieJar()&lt;/a>&lt;/td>
&lt;td>Get active HTTP Cookie jar.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/del/">del( url, [body], [params] )&lt;/a>&lt;/td>
&lt;td>Issue an HTTP DELETE request.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/file/">file( data, [filename], [contentType] )&lt;/a>&lt;/td>
&lt;td>Create a file object that is used for building multi-part requests.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/get/">get( url, [params] )&lt;/a>&lt;/td>
&lt;td>Issue an HTTP GET request.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/head/">head( url, [params] )&lt;/a>&lt;/td>
&lt;td>Issue an HTTP HEAD request.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/options/">options( url, [body], [params] )&lt;/a>&lt;/td>
&lt;td>Issue an HTTP OPTIONS request.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/patch/">patch( url, [body], [params] )&lt;/a>&lt;/td>
&lt;td>Issue an HTTP PATCH request.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/post/">post( url, [body], [params] )&lt;/a>&lt;/td>
&lt;td>Issue an HTTP POST request.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/put/">put( url, [body], [params] )&lt;/a>&lt;/td>
&lt;td>Issue an HTTP PUT request.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/request/">request( method, url, [body], [params] )&lt;/a>&lt;/td>
&lt;td>Issue any type of HTTP request.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/asyncrequest/">asyncRequest( method, url, [body], [params] )&lt;/a>&lt;/td>
&lt;td>Issue any type of HTTP request asynchronously.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/set-response-callback/">setResponseCallback(expectedStatuses)&lt;/a>&lt;/td>
&lt;td>Sets a response callback to mark responses as expected.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/url/">url`url`&lt;/a>&lt;/td>
&lt;td>Creates a URL with a name tag. Read more on
&lt;a href="/docs/k6/v2.3.x/using-k6/http-requests/#url-grouping">URL Grouping&lt;/a>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/expected-statuses/">expectedStatuses( statusCodes )&lt;/a>&lt;/td>
&lt;td>Create a callback for setResponseCallback that checks status codes.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Class&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/cookiejar/">CookieJar&lt;/a>&lt;/td>
&lt;td>Used for storing cookies, set by the server and/or added by the client.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/filedata/">FileData&lt;/a>&lt;/td>
&lt;td>Used for wrapping data representing a file when doing multipart requests (file uploads).&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/params/">Params&lt;/a>&lt;/td>
&lt;td>Used for setting various HTTP request-specific parameters such as headers, cookies, etc.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/response/">Response&lt;/a>&lt;/td>
&lt;td>Returned by the http.* methods that generate HTTP requests.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;/div></description></item><item><title>k6/metrics</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-metrics/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-metrics/</guid><content><![CDATA[&lt;h1 id=&#34;k6metrics&#34;&gt;k6/metrics&lt;/h1&gt;


&lt;div data-shared=&#34;javascript-api/k6-metrics.md&#34;&gt;
            &lt;p&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-metrics/&#34;&gt;&lt;code&gt;k6/metrics&lt;/code&gt; module&lt;/a&gt; provides functionality to 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/metrics/create-custom-metrics/&#34;&gt;create custom metrics&lt;/a&gt; of various types.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Metric type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-metrics/counter/&#34;&gt;Counter&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A metric that cumulatively sums added values.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-metrics/gauge/&#34;&gt;Gauge&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A metric that stores the min, max and last values added to it.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-metrics/rate/&#34;&gt;Rate&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A metric that tracks the percentage of added values that are non-zero.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-metrics/trend/&#34;&gt;Trend&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A metric that calculates statistics on the added values (min, max, average, and percentiles).&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
]]></content><description>&lt;h1 id="k6metrics">k6/metrics&lt;/h1>
&lt;div data-shared="javascript-api/k6-metrics.md">
&lt;p>The
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-metrics/">&lt;code>k6/metrics&lt;/code> module&lt;/a> provides functionality to
&lt;a href="/docs/k6/v2.3.x/using-k6/metrics/create-custom-metrics/">create custom metrics&lt;/a> of various types.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Metric type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-metrics/counter/">Counter&lt;/a>&lt;/td>
&lt;td>A metric that cumulatively sums added values.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-metrics/gauge/">Gauge&lt;/a>&lt;/td>
&lt;td>A metric that stores the min, max and last values added to it.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-metrics/rate/">Rate&lt;/a>&lt;/td>
&lt;td>A metric that tracks the percentage of added values that are non-zero.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-metrics/trend/">Trend&lt;/a>&lt;/td>
&lt;td>A metric that calculates statistics on the added values (min, max, average, and percentiles).&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;/div></description></item><item><title>k6/net/grpc</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-net-grpc/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-net-grpc/</guid><content><![CDATA[&lt;h1 id=&#34;k6netgrpc&#34;&gt;k6/net/grpc&lt;/h1&gt;


&lt;div data-shared=&#34;javascript-api/k6-net-grpc.md&#34;&gt;
            &lt;p&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/&#34;&gt;&lt;code&gt;k6/net/grpc&lt;/code&gt; module&lt;/a&gt; provides a &lt;a href=&#34;https://grpc.io/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;gRPC&lt;/a&gt; client for Remote Procedure Calls (RPC) over HTTP/2.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Class/Method&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/client/&#34;&gt;Client&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;gRPC client used for making RPC calls to a gRPC Server.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/client/client-load/&#34;&gt;Client.load(importPaths, &amp;hellip;protoFiles)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Loads and parses the given protocol buffer definitions to be made available for RPC requests.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/client/client-connect/&#34;&gt;Client.connect(address [,params])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Connects to a given gRPC service.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/client/client-invoke/&#34;&gt;Client.invoke(url, request [,params])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Makes an unary RPC for the given service/method and returns a 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/response/&#34;&gt;Response&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/client/client-async-invoke/&#34;&gt;Client.asyncInvoke(url, request [,params])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Asynchronously makes an unary RPC for the given service/method and returns a Promise with 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/response/&#34;&gt;Response&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/client/client-close/&#34;&gt;Client.close()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Close the connection to the gRPC service.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/params/&#34;&gt;Params&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;RPC Request specific options.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/response/&#34;&gt;Response&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Returned by RPC requests.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/constants/&#34;&gt;Constants&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Define constants to distinguish between 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/response/&#34;&gt;gRPC Response&lt;/a&gt; statuses.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/stream/&#34;&gt;Stream(client, url, [,params])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Creates a new gRPC stream.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/stream/stream-on/&#34;&gt;Stream.on(event, handler)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Adds a new listener to one of the possible stream events.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/stream/stream-write/&#34;&gt;Stream.write(message)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Writes a message to the stream.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/stream/stream-end/&#34;&gt;Stream.end()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Signals to the server that the client has finished sending.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/stream/event-handler/&#34;&gt;EventHandler&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;The function to call for various events on the gRPC stream.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-net-grpc/stream/message-metadata/&#34;&gt;Metadata&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;The metadata of a gRPC stream’s message.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
&lt;h2 id=&#34;grpc-metrics&#34;&gt;gRPC metrics&lt;/h2&gt;
&lt;p&gt;k6 takes specific measurements for gRPC requests.
For the complete list, refer to the 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/metrics/reference/#grpc&#34;&gt;Metrics reference&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import grpc from &amp;#39;k6/net/grpc&amp;#39;;
import { check, sleep } from &amp;#39;k6&amp;#39;;

const client = new grpc.Client();
client.load(null, &amp;#39;quickpizza.proto&amp;#39;);

export default () =&amp;gt; {
  client.connect(&amp;#39;grpc-quickpizza.grafana.com:443&amp;#39;, {
    // plaintext: false
  });

  const data = { ingredients: [&amp;#39;Cheese&amp;#39;], dough: &amp;#39;Thick&amp;#39; };
  const response = client.invoke(&amp;#39;quickpizza.GRPC/RatePizza&amp;#39;, data);

  check(response, {
    &amp;#39;status is OK&amp;#39;: (r) =&amp;gt; r &amp;amp;&amp;amp; r.status === grpc.StatusOK,
  });

  console.log(JSON.stringify(response.message));

  client.close();
  sleep(1);
};&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="k6netgrpc">k6/net/grpc&lt;/h1>
&lt;div data-shared="javascript-api/k6-net-grpc.md">
&lt;p>The
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/">&lt;code>k6/net/grpc&lt;/code> module&lt;/a> provides a &lt;a href="https://grpc.io/" target="_blank" rel="noopener noreferrer">gRPC&lt;/a> client for Remote Procedure Calls (RPC) over HTTP/2.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Class/Method&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/client/">Client&lt;/a>&lt;/td>
&lt;td>gRPC client used for making RPC calls to a gRPC Server.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/client/client-load/">Client.load(importPaths, &amp;hellip;protoFiles)&lt;/a>&lt;/td>
&lt;td>Loads and parses the given protocol buffer definitions to be made available for RPC requests.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/client/client-connect/">Client.connect(address [,params])&lt;/a>&lt;/td>
&lt;td>Connects to a given gRPC service.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/client/client-invoke/">Client.invoke(url, request [,params])&lt;/a>&lt;/td>
&lt;td>Makes an unary RPC for the given service/method and returns a
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/response/">Response&lt;/a>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/client/client-async-invoke/">Client.asyncInvoke(url, request [,params])&lt;/a>&lt;/td>
&lt;td>Asynchronously makes an unary RPC for the given service/method and returns a Promise with
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/response/">Response&lt;/a>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/client/client-close/">Client.close()&lt;/a>&lt;/td>
&lt;td>Close the connection to the gRPC service.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/params/">Params&lt;/a>&lt;/td>
&lt;td>RPC Request specific options.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/response/">Response&lt;/a>&lt;/td>
&lt;td>Returned by RPC requests.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/constants/">Constants&lt;/a>&lt;/td>
&lt;td>Define constants to distinguish between
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/response/">gRPC Response&lt;/a> statuses.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/stream/">Stream(client, url, [,params])&lt;/a>&lt;/td>
&lt;td>Creates a new gRPC stream.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/stream/stream-on/">Stream.on(event, handler)&lt;/a>&lt;/td>
&lt;td>Adds a new listener to one of the possible stream events.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/stream/stream-write/">Stream.write(message)&lt;/a>&lt;/td>
&lt;td>Writes a message to the stream.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/stream/stream-end/">Stream.end()&lt;/a>&lt;/td>
&lt;td>Signals to the server that the client has finished sending.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/stream/event-handler/">EventHandler&lt;/a>&lt;/td>
&lt;td>The function to call for various events on the gRPC stream.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-net-grpc/stream/message-metadata/">Metadata&lt;/a>&lt;/td>
&lt;td>The metadata of a gRPC stream’s message.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;/div>
&lt;h2 id="grpc-metrics">gRPC metrics&lt;/h2>
&lt;p>k6 takes specific measurements for gRPC requests.
For the complete list, refer to the
&lt;a href="/docs/k6/v2.3.x/using-k6/metrics/reference/#grpc">Metrics reference&lt;/a>.&lt;/p></description></item><item><title>k6/secrets</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-secrets/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-secrets/</guid><content><![CDATA[&lt;h1 id=&#34;k6secrets&#34;&gt;k6/secrets&lt;/h1&gt;


&lt;div data-shared=&#34;javascript-api/k6-secrets.md&#34;&gt;
            &lt;p&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-secrets/&#34;&gt;&lt;code&gt;k6/secrets&lt;/code&gt; module&lt;/a&gt; gives access to secrets provided by configured 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/secret-source/&#34;&gt;secret sources&lt;/a&gt;.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Property&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-secrets/#get&#34;&gt;get([String])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;asynchrounsly get a secret from the default secret source&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-secrets/#source&#34;&gt;source([String])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;returns a source for the provided name that can than be used to get a secret from a concrete source&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
&lt;h2 id=&#34;get&#34;&gt;get&lt;/h2&gt;
&lt;p&gt;get returns the value of the secret for the provided name from the default secret source. If there is no default secret source, there is no secret with that name or some other error is returned an exception will thrown.&lt;/p&gt;
&lt;h2 id=&#34;source&#34;&gt;source&lt;/h2&gt;
&lt;p&gt;source returns a secret source for the name provided. The name is defined when running k6.&lt;/p&gt;
&lt;p&gt;The returned object has one method get with the same functionality as the global 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-secrets/#get&#34;&gt;get&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;A simple example where we get a secret by its name from the default source (if defined).&lt;/p&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import secrets from &amp;#39;k6/secrets&amp;#39;;

export default async () =&amp;gt; {
  const my_secret = await secrets.get(&amp;#39;my_secret&amp;#39;); // get from 1 secret source if only 1, exception if more than 1 secret source or if no secret sources
  console.log(my_secret);
};&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;We can also get a secret source by its name then get a secret specifically from it.&lt;/p&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import secrets from &amp;#39;k6/secrets&amp;#39;;

export default async () =&amp;gt; {
  const my_secret = await secrets.source(&amp;#39;identifier&amp;#39;).get(&amp;#39;my_secret&amp;#39;); // get secret from a source with the provided identifier
  console.log(my_secret);
};&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In both of those cases the end logs will have &lt;code&gt;***SECRET_REDACTED***&lt;/code&gt; in place of any secret that has been outputed.&lt;/p&gt;
&lt;h3 id=&#34;a-full-example-with-multiple-secret-sources-and-names&#34;&gt;A full example with multiple secret sources and names&lt;/h3&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import secrets from &amp;#39;k6/secrets&amp;#39;;

export default async () =&amp;gt; {
  const my_secret = await secrets.get(&amp;#39;cool&amp;#39;); // get secret from a source with the provided identifier
  console.log(my_secret == &amp;#39;cool secret&amp;#39;);
  const anothersource = await secrets.source(&amp;#39;another&amp;#39;);
  console.log((await anothersource.get(&amp;#39;cool&amp;#39;)) == &amp;#39;cool secret&amp;#39;);
  console.log((await anothersource.get(&amp;#39;cool&amp;#39;)) == &amp;#39;not cool secret&amp;#39;);
};&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And if we ran we will see that when we get from the default secret source we get one secret and we get a different one from the not default one. This also shows that the internal parts of the scripts can use the actual value of the script even if it is redacted in the logs.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;$ k6 run --secret-source=mock=default,cool=&amp;#34;cool secret&amp;#34; --secret-source=mock=name=another,cool=&amp;#34;not cool secret&amp;#34; multi-source.test.js
...
INFO[0000] true                                          source=console
INFO[0000] false                                         source=console
INFO[0000] true                                          source=console&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="k6secrets">k6/secrets&lt;/h1>
&lt;div data-shared="javascript-api/k6-secrets.md">
&lt;p>The
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-secrets/">&lt;code>k6/secrets&lt;/code> module&lt;/a> gives access to secrets provided by configured
&lt;a href="/docs/k6/v2.3.x/using-k6/secret-source/">secret sources&lt;/a>.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Property&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-secrets/#get">get([String])&lt;/a>&lt;/td>
&lt;td>asynchrounsly get a secret from the default secret source&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-secrets/#source">source([String])&lt;/a>&lt;/td>
&lt;td>returns a source for the provided name that can than be used to get a secret from a concrete source&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;/div>
&lt;h2 id="get">get&lt;/h2>
&lt;p>get returns the value of the secret for the provided name from the default secret source. If there is no default secret source, there is no secret with that name or some other error is returned an exception will thrown.&lt;/p></description></item><item><title>k6/timers</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-timers/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-timers/</guid><content><![CDATA[&lt;h1 id=&#34;k6timers&#34;&gt;k6/timers&lt;/h1&gt;


&lt;div data-shared=&#34;javascript-api/k6-timers.md&#34;&gt;
            &lt;p&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-timers/&#34;&gt;&lt;code&gt;k6/timers&lt;/code&gt; module&lt;/a&gt; implements timers to work with k6&amp;rsquo;s event loop. They mimic the functionality found in browsers and other JavaScript runtimes.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Function&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/setTimeout&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;setTimeout&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Sets a function to be run after a given timeout.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/clearTimeout&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;clearTimeout&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Clears a previously set timeout with &lt;code&gt;setTimeout&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/setInterval&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;setInterval&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Sets a function to be run on a given interval.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/setInterval&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;clearInterval&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Clears a previously set interval with &lt;code&gt;setInterval&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;

&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The timer methods are available globally, so you can use them in your script without including an import statement.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;When you enable the experimental 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/feature-flags/&#34;&gt;&lt;code&gt;async-metric-context&lt;/code&gt; feature flag&lt;/a&gt;, &lt;code&gt;setTimeout()&lt;/code&gt; and &lt;code&gt;setInterval()&lt;/code&gt; capture the tags and metadata active when you register their callbacks. Each callback runs with a copy of that context. Repeating intervals reuse the original registration context for every invocation, so changes made by one invocation don&amp;rsquo;t leak into the next one or into the calling code.&lt;/p&gt;
&lt;p&gt;Promise reactions and &lt;code&gt;await&lt;/code&gt; continuations created inside a timer callback keep any context changes made by that callback.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;export default function () {
  const intervalId = setInterval(() =&amp;gt; {
    console.log(&amp;#39;This runs every 200ms&amp;#39;);
  }, 200);

  const timeoutId = setTimeout(() =&amp;gt; {
    console.log(&amp;#39;This runs after 2s&amp;#39;);

    // clear the timeout and interval to exit k6
    clearInterval(intervalId);
    clearTimeout(timeoutId);
  }, 2000);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="k6timers">k6/timers&lt;/h1>
&lt;div data-shared="javascript-api/k6-timers.md">
&lt;p>The
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-timers/">&lt;code>k6/timers&lt;/code> module&lt;/a> implements timers to work with k6&amp;rsquo;s event loop. They mimic the functionality found in browsers and other JavaScript runtimes.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align: left">Function&lt;/th>
&lt;th style="text-align: left">Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align: left">&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/setTimeout" target="_blank" rel="noopener noreferrer">setTimeout&lt;/a>&lt;/td>
&lt;td style="text-align: left">Sets a function to be run after a given timeout.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align: left">&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/clearTimeout" target="_blank" rel="noopener noreferrer">clearTimeout&lt;/a>&lt;/td>
&lt;td style="text-align: left">Clears a previously set timeout with &lt;code>setTimeout&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align: left">&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/setInterval" target="_blank" rel="noopener noreferrer">setInterval&lt;/a>&lt;/td>
&lt;td style="text-align: left">Sets a function to be run on a given interval.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align: left">&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/setInterval" target="_blank" rel="noopener noreferrer">clearInterval&lt;/a>&lt;/td>
&lt;td style="text-align: left">Clears a previously set interval with &lt;code>setInterval&lt;/code>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p></description></item><item><title>k6/ws</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-ws/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-ws/</guid><content><![CDATA[&lt;h1 id=&#34;k6ws&#34;&gt;k6/ws&lt;/h1&gt;


&lt;div data-shared=&#34;ws-module.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;A module with a better and standard API exists.
&lt;br&gt;
&lt;br&gt;
The new 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/&#34;&gt;k6/websockets API&lt;/a&gt; partially implements the &lt;a href=&#34;https://websockets.spec.whatwg.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;WebSockets API living standard&lt;/a&gt;.
&lt;br&gt;
&lt;br&gt;
When possible, we recommend using the new API. It uses a global event loop for consistency with other k6 APIs and better performance.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        


&lt;div data-shared=&#34;javascript-api/k6-ws.md&#34;&gt;
            &lt;p&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-ws/&#34;&gt;&lt;code&gt;k6/ws&lt;/code&gt; module&lt;/a&gt; provides a &lt;a href=&#34;https://en.wikipedia.org/wiki/WebSocket&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;WebSocket&lt;/a&gt; client implementing the &lt;a href=&#34;http://www.rfc-editor.org/rfc/rfc6455.txt&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;WebSocket protocol&lt;/a&gt;.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-ws/connect/&#34;&gt;connect( url, params, callback )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Create a WebSocket connection, and provides a 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-ws/socket/&#34;&gt;Socket&lt;/a&gt; client to interact with the service. The method blocks the test finalization until the connection is closed.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Class/Method&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-ws/params/&#34;&gt;Params&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Used for setting various WebSocket connection parameters such as headers, cookie jar, compression, etc.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-ws/socket/&#34;&gt;Socket&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;WebSocket client used to interact with a WS connection.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-ws/socket/socket-close/&#34;&gt;Socket.close()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Close the WebSocket connection.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-ws/socket/socket-on/&#34;&gt;Socket.on(event, callback)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Set up an event listener on the connection for any of the following events:&lt;br /&gt;- open&lt;br /&gt;- binaryMessage&lt;br /&gt;- message&lt;br /&gt;- ping&lt;br /&gt;- pong&lt;br /&gt;- close&lt;br /&gt;- error.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-ws/socket/socket-ping/&#34;&gt;Socket.ping()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Send a ping.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-ws/socket/socket-send/&#34;&gt;Socket.send(data)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Send string data.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-ws/socket/socket-sendbinary/&#34;&gt;Socket.sendBinary(data)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Send binary data.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-ws/socket/socket-setinterval/&#34;&gt;Socket.setInterval(callback, interval)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Call a function repeatedly at certain intervals, while the connection is open.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-ws/socket/socket-settimeout/&#34;&gt;Socket.setTimeout(callback, period)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Call a function with a delay, if the connection is open.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
]]></content><description>&lt;h1 id="k6ws">k6/ws&lt;/h1>
&lt;div data-shared="ws-module.md">
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>A module with a better and standard API exists.
&lt;br>
&lt;br>
The new
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-websockets/">k6/websockets API&lt;/a> partially implements the &lt;a href="https://websockets.spec.whatwg.org/" target="_blank" rel="noopener noreferrer">WebSockets API living standard&lt;/a>.
&lt;br>
&lt;br>
When possible, we recommend using the new API. It uses a global event loop for consistency with other k6 APIs and better performance.&lt;/p></description></item><item><title>k6/x/dns</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-x-dns/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-x-dns/</guid><content><![CDATA[&lt;h1 id=&#34;k6xdns&#34;&gt;k6/x/dns&lt;/h1&gt;


&lt;div data-shared=&#34;extension.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;This module is implemented as an official extension and is available natively in k6, requiring no additional installation or build steps. Refer to the 
    &lt;a href=&#34;/docs/k6/v2.3.x/extensions/explore/&#34;&gt;extensions documentation&lt;/a&gt; for available extensions and details.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;k6/x/dns&lt;/code&gt; module enables DNS resolution testing in k6, allowing you to resolve DNS names to IP addresses using custom DNS servers or the system&amp;rsquo;s default DNS configuration. This module is useful for testing DNS server performance, validating DNS configurations, and incorporating DNS resolution into your load testing scenarios.&lt;/p&gt;
&lt;h2 id=&#34;key-features&#34;&gt;Key features&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-dns/resolve/&#34;&gt;&lt;code&gt;dns.resolve()&lt;/code&gt;&lt;/a&gt; function resolves DNS names using a specified DNS server, allowing you to test custom DNS configurations and server performance.&lt;/li&gt;
&lt;li&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-dns/lookup/&#34;&gt;&lt;code&gt;dns.lookup()&lt;/code&gt;&lt;/a&gt; function resolves DNS names using the system&amp;rsquo;s default DNS servers, providing a way to test standard DNS resolution behavior.&lt;/li&gt;
&lt;li&gt;Support for A (IPv4) and AAAA (IPv6) record types.&lt;/li&gt;
&lt;li&gt;Automatic metrics collection for DNS resolution performance analysis.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;use-cases&#34;&gt;Use cases&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Load testing DNS servers to ensure they can handle high query volumes.&lt;/li&gt;
&lt;li&gt;Validating DNS configurations in staging and production environments.&lt;/li&gt;
&lt;li&gt;Testing DNS failover mechanisms and redundancy.&lt;/li&gt;
&lt;li&gt;Incorporating DNS resolution time into overall application performance testing.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;api&#34;&gt;API&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function/Object&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-dns/resolve/&#34;&gt;resolve&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Resolves a DNS name to IP addresses using a specified DNS server.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-dns/lookup/&#34;&gt;lookup&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Resolves a DNS name to IP addresses using the system&amp;rsquo;s default DNS servers.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;metrics&#34;&gt;Metrics&lt;/h2&gt;
&lt;p&gt;The extension automatically generates the following metrics:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;dns_resolutions&lt;/code&gt;: Counter tracking the number of DNS resolution attempts.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dns_resolution_duration&lt;/code&gt;: Trend measuring DNS resolution response times.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dns_lookups&lt;/code&gt;: Counter tracking the number of DNS lookup attempts.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dns_lookup_duration&lt;/code&gt;: Trend measuring DNS lookup response times.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;!-- md-k6:skipall --&gt;
&lt;h3 id=&#34;basic-dns-resolution-with-custom-server&#34;&gt;Basic DNS resolution with custom server&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import dns from &amp;#39;k6/x/dns&amp;#39;;

export default async function () {
  // Resolve k6.io using Cloudflare&amp;#39;s DNS server
  const ips = await dns.resolve(&amp;#39;k6.io&amp;#39;, &amp;#39;A&amp;#39;, &amp;#39;1.1.1.1:53&amp;#39;);
  console.log(&amp;#39;k6.io resolves to:&amp;#39;, ips);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;dns-lookup-using-system-defaults&#34;&gt;DNS lookup using system defaults&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import dns from &amp;#39;k6/x/dns&amp;#39;;

export default async function () {
  // Resolve k6.io using system DNS servers
  const ips = await dns.lookup(&amp;#39;k6.io&amp;#39;);
  console.log(&amp;#39;k6.io resolves to:&amp;#39;, ips);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;comprehensive-dns-testing&#34;&gt;Comprehensive DNS testing&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import dns from &amp;#39;k6/x/dns&amp;#39;;
import { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

export const options = {
  vus: 10,
  duration: &amp;#39;30s&amp;#39;,
};

export default async function () {
  // Test both IPv4 and IPv6 resolution
  const ipv4Results = await dns.resolve(&amp;#39;example.com&amp;#39;, &amp;#39;A&amp;#39;, &amp;#39;8.8.8.8:53&amp;#39;);
  const ipv6Results = await dns.resolve(&amp;#39;example.com&amp;#39;, &amp;#39;AAAA&amp;#39;, &amp;#39;[2606:4700:4700::1111]:53&amp;#39;);

  // Test system DNS
  const systemResults = await dns.lookup(&amp;#39;example.com&amp;#39;);

  // Validate results
  expect(ipv4Results.length).toBeGreaterThan(0);
  expect(ipv6Results.length).toBeGreaterThan(0);
  expect(systemResults.length).toBeGreaterThan(0);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="k6xdns">k6/x/dns&lt;/h1>
&lt;div data-shared="extension.md">
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>This module is implemented as an official extension and is available natively in k6, requiring no additional installation or build steps. Refer to the
&lt;a href="/docs/k6/v2.3.x/extensions/explore/">extensions documentation&lt;/a> for available extensions and details.&lt;/p></description></item><item><title>k6/x/icmp</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-x-icmp/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-x-icmp/</guid><content><![CDATA[&lt;h1 id=&#34;k6xicmp&#34;&gt;k6/x/icmp&lt;/h1&gt;


&lt;div data-shared=&#34;official-extension.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;This module is implemented as an official extension and is not part of k6 by default. However, k6&amp;rsquo;s 
    &lt;a href=&#34;/docs/k6/v2.3.x/extensions/run/&#34;&gt;automatic extension resolution&lt;/a&gt; makes it available seamlessly when you import it in your script. Refer to the 
    &lt;a href=&#34;/docs/k6/v2.3.x/extensions/explore/&#34;&gt;extensions documentation&lt;/a&gt; for available extensions and details.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;k6/x/icmp&lt;/code&gt; module adds support for sending ICMP echo requests (pings) to measure network latency and availability. This allows you to measure network latency and reachability of hosts directly within your load testing and synthetic monitoring scenarios.&lt;/p&gt;
&lt;p&gt;The main use case for this extension is integration with Grafana&amp;rsquo;s Synthetic Monitoring product to make a quick reachability check after a scripted check fails. It can also be used directly in k6 scripts, for example as a pre-check to verify network connectivity before running your main test.&lt;/p&gt;
&lt;h2 id=&#34;key-features&#34;&gt;Key features&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Send ICMP echo requests (ping) to any host&lt;/li&gt;
&lt;li&gt;Synchronous and asynchronous ping functions&lt;/li&gt;
&lt;li&gt;Support for multiple ping attempts with configurable count and interval&lt;/li&gt;
&lt;li&gt;Configurable timeouts and deadlines&lt;/li&gt;
&lt;li&gt;Detailed ping results via callback function&lt;/li&gt;
&lt;li&gt;Support for IPv4 and IPv6&lt;/li&gt;
&lt;li&gt;Custom packet size and TTL settings&lt;/li&gt;
&lt;li&gt;Automatic metrics collection&lt;/li&gt;
&lt;li&gt;Success threshold configuration for multiple pings&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;use-cases&#34;&gt;Use cases&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Network connectivity pre-checks before load tests&lt;/li&gt;
&lt;li&gt;Host reachability validation in synthetic monitoring&lt;/li&gt;
&lt;li&gt;Network latency measurement across different hosts&lt;/li&gt;
&lt;li&gt;Testing network infrastructure reliability&lt;/li&gt;
&lt;li&gt;Monitoring service availability at the network layer&lt;/li&gt;
&lt;li&gt;Validating network paths and routing&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;api&#34;&gt;API&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function/Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-icmp/ping/&#34;&gt;ping( target, [options] )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Send ICMP echo requests synchronously&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-icmp/ping-async/&#34;&gt;pingAsync( target, [optsOrCallback], [callback] )&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Send ICMP echo requests asynchronously&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-icmp/ping-options/&#34;&gt;PingOptions&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Configuration options for ping operations&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-icmp/ping-detail/&#34;&gt;PingDetail&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Detailed information about ping results&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-icmp/ip/&#34;&gt;IP&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;IP protocol version enumeration&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;metrics&#34;&gt;Metrics&lt;/h2&gt;
&lt;p&gt;The extension automatically generates metrics for ICMP operations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;icmp_pings&lt;/code&gt;: Counter tracking the number of ping attempts&lt;/li&gt;
&lt;li&gt;&lt;code&gt;icmp_ping_duration&lt;/code&gt;: Trend measuring round-trip time for successful pings&lt;/li&gt;
&lt;li&gt;&lt;code&gt;icmp_ping_failed&lt;/code&gt;: Counter tracking failed ping attempts&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;!-- md-k6:skipall --&gt;
&lt;h3 id=&#34;basic-usage&#34;&gt;Basic Usage&lt;/h3&gt;
&lt;p&gt;Here is a basic example showing how to use the &lt;code&gt;ping()&lt;/code&gt; function:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { ping } from &amp;#34;k6/x/icmp&amp;#34;

export default function () {
  const host = &amp;#34;8.8.8.8&amp;#34;

  console.log(`Pinging ${host}:`);

  if (ping(host)) {
    console.log(`Host ${host} is reachable`);
  } else {
    console.error(`Host ${host} is unreachable`);
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;advanced-usage&#34;&gt;Advanced Usage&lt;/h3&gt;
&lt;p&gt;A more advanced example below demonstrates how to use the &lt;code&gt;PingCallback&lt;/code&gt; to access detailed ping results for each request.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { pingAsync } from &amp;#34;k6/x/icmp&amp;#34;

export default async function () {
  const host = &amp;#34;8.8.8.8&amp;#34;

  console.log(`Pinging ${host} with callback:`);

  const opts = {
    timeout: 3000,
    count: 5
  };

  const result = await pingAsync(host, opts, (err, { target, sent_at, received_at, seq, ttl, size }) =&amp;gt; {
    if (err) {
      console.error(`${target}: ${err}`);

      return
    }

    const rtt = received_at - sent_at;

    console.log(`${size} bytes from ${target}: icmp_seq=${seq} ttl=${ttl} time=${rtt} ms`);
  });

  if (result) {
    console.log(`Host ${host} is reachable`);
  } else {
    console.error(`Host ${host} is unreachable`);
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="k6xicmp">k6/x/icmp&lt;/h1>
&lt;div data-shared="official-extension.md">
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>This module is implemented as an official extension and is not part of k6 by default. However, k6&amp;rsquo;s
&lt;a href="/docs/k6/v2.3.x/extensions/run/">automatic extension resolution&lt;/a> makes it available seamlessly when you import it in your script. Refer to the
&lt;a href="/docs/k6/v2.3.x/extensions/explore/">extensions documentation&lt;/a> for available extensions and details.&lt;/p></description></item><item><title>k6/x/mqtt</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/</guid><content><![CDATA[&lt;h1 id=&#34;k6xmqtt&#34;&gt;k6/x/mqtt&lt;/h1&gt;


&lt;div data-shared=&#34;official-extension.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;This module is implemented as an official extension and is not part of k6 by default. However, k6&amp;rsquo;s 
    &lt;a href=&#34;/docs/k6/v2.3.x/extensions/run/&#34;&gt;automatic extension resolution&lt;/a&gt; makes it available seamlessly when you import it in your script. Refer to the 
    &lt;a href=&#34;/docs/k6/v2.3.x/extensions/explore/&#34;&gt;extensions documentation&lt;/a&gt; for available extensions and details.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;k6/x/mqtt&lt;/code&gt; module adds first-class support for the &lt;a href=&#34;https://mqtt.org&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;MQTT protocol&lt;/a&gt; to your load testing and performance scripts. With this extension, you can connect to MQTT brokers, publish and subscribe to topics, and interact with MQTT systems directly from your k6 tests.&lt;/p&gt;
&lt;p&gt;The API is designed to feel familiar to users of &lt;a href=&#34;https://github.com/mqttjs/MQTT.js&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;MQTT.js&lt;/a&gt;, the popular JavaScript MQTT client. This means you can use event-driven programming, both synchronous and asynchronous operations, and migrate existing MQTT.js-based test logic with minimal changes.&lt;/p&gt;
&lt;h2 id=&#34;key-features&#34;&gt;Key features&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Event-driven architecture with support for connection lifecycle events (&lt;code&gt;connect&lt;/code&gt;, &lt;code&gt;message&lt;/code&gt;, &lt;code&gt;end&lt;/code&gt;, &lt;code&gt;reconnect&lt;/code&gt;, &lt;code&gt;error&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Both synchronous and asynchronous methods for all operations (subscribe, publish, unsubscribe, end)&lt;/li&gt;
&lt;li&gt;Support for Quality of Service (QoS) levels: 0 (at most once), 1 (at least once), 2 (exactly once)&lt;/li&gt;
&lt;li&gt;Message retention and Last Will and Testament (LWT) support&lt;/li&gt;
&lt;li&gt;Multiple broker URL schemas: &lt;code&gt;mqtt://&lt;/code&gt;, &lt;code&gt;mqtts://&lt;/code&gt;, &lt;code&gt;tcp://&lt;/code&gt;, &lt;code&gt;ssl://&lt;/code&gt;, &lt;code&gt;tls://&lt;/code&gt;, &lt;code&gt;ws://&lt;/code&gt;, &lt;code&gt;wss://&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;SSL/TLS support using standard 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/protocols/ssl-tls/&#34;&gt;k6 TLS configuration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Automatic metrics collection for MQTT operations&lt;/li&gt;
&lt;li&gt;Support for binary payloads using ArrayBuffer&lt;/li&gt;
&lt;li&gt;Credentials provider for dynamic authentication&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;use-cases&#34;&gt;Use cases&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Load testing MQTT brokers and IoT infrastructure&lt;/li&gt;
&lt;li&gt;Testing publish/subscribe patterns under high load&lt;/li&gt;
&lt;li&gt;Validating message delivery and QoS guarantees&lt;/li&gt;
&lt;li&gt;Simulating thousands of concurrent MQTT clients&lt;/li&gt;
&lt;li&gt;Testing MQTT-based microservices and event-driven architectures&lt;/li&gt;
&lt;li&gt;Monitoring MQTT broker performance and message throughput&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;api&#34;&gt;API&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Class/Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/client/&#34;&gt;Client&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;MQTT client for connecting to brokers and managing operations&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/client/connect/&#34;&gt;Client.connect()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Connect to an MQTT broker&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/client/reconnect/&#34;&gt;Client.reconnect()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Reconnect to the broker&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/client/subscribe/&#34;&gt;Client.subscribe()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Subscribe to MQTT topics&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/client/subscribe-async/&#34;&gt;Client.subscribeAsync()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Subscribe to topics asynchronously&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/client/unsubscribe/&#34;&gt;Client.unsubscribe()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Unsubscribe from topics&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/client/unsubscribe-async/&#34;&gt;Client.unsubscribeAsync()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Unsubscribe from topics asynchronously&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/client/publish/&#34;&gt;Client.publish()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Publish messages to MQTT topics&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/client/publish-async/&#34;&gt;Client.publishAsync()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Publish messages asynchronously&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/client/on/&#34;&gt;Client.on()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Register event handlers&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/client/end/&#34;&gt;Client.end()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Disconnect from the MQTT broker&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/client/end-async/&#34;&gt;Client.endAsync()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Disconnect asynchronously&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-mqtt/client/#qos&#34;&gt;QoS&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Quality of Service enumeration&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;metrics&#34;&gt;Metrics&lt;/h2&gt;
&lt;p&gt;The extension automatically generates metrics for MQTT operations, allowing you to monitor performance:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;mqtt_connects&lt;/code&gt;: Counter tracking the number of connection attempts&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mqtt_connect_duration&lt;/code&gt;: Trend measuring connection time&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mqtt_publishes&lt;/code&gt;: Counter tracking the number of publish operations&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mqtt_subscribes&lt;/code&gt;: Counter tracking the number of subscribe operations&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mqtt_messages_received&lt;/code&gt;: Counter tracking received messages&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mqtt_messages_sent&lt;/code&gt;: Counter tracking sent messages&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;event-driven-architecture&#34;&gt;Event-driven architecture&lt;/h2&gt;
&lt;p&gt;Unlike HTTP-based tests that continuously loop the main function, MQTT tests use an asynchronous event loop. Each VU creates an MQTT connection and registers event handlers. The VU remains active until the connection is closed.&lt;/p&gt;
&lt;p&gt;When you call &lt;code&gt;client.connect()&lt;/code&gt;, the &lt;code&gt;connect&lt;/code&gt; event handler is immediately called. Inside this handler, you set up other event handlers and perform MQTT operations. The VU blocks until &lt;code&gt;client.end()&lt;/code&gt; is called or the connection is closed by the broker.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;!-- md-k6:skipall --&gt;
&lt;h3 id=&#34;hello-world&#34;&gt;Hello World&lt;/h3&gt;
&lt;p&gt;Comparing HTTP-based tests to MQTT ones, you&amp;rsquo;ll find differences in both structure and inner workings. The primary difference is that instead of continuously looping the main function (&lt;code&gt;export default function() { ... }&lt;/code&gt;) over and over, each VU now runs an asynchronous event loop.&lt;/p&gt;
&lt;p&gt;When the MQTT connection is created, the &lt;code&gt;connect&lt;/code&gt; handler function is immediately called, all code inside it is executed (usually code to set up other event handlers), and then blocked until the MQTT connection is closed (by the remote host or by using &lt;code&gt;client.end()&lt;/code&gt;).&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { Client } from &amp;#39;k6/x/mqtt&amp;#39;;

export default function () {
  const client = new Client();

  client.on(&amp;#39;connect&amp;#39;, async () =&amp;gt; {
    console.log(&amp;#39;Connected to MQTT broker&amp;#39;);
    client.subscribe(&amp;#39;greeting&amp;#39;);
    client.publish(&amp;#39;greeting&amp;#39;, &amp;#39;Hello MQTT!&amp;#39;);
  });

  client.on(&amp;#39;message&amp;#39;, (topic, message) =&amp;gt; {
    const str = new TextDecoder().decode(message);
    console.info(&amp;#39;topic:&amp;#39;, topic, &amp;#39;message:&amp;#39;, str);
    client.end();
  });

  client.on(&amp;#39;end&amp;#39;, () =&amp;gt; {
    console.log(&amp;#39;Disconnected from MQTT broker&amp;#39;);
  });

  client.connect(__ENV[&amp;#39;MQTT_BROKER_ADDRESS&amp;#39;] || &amp;#39;mqtt://broker.emqx.io:1883&amp;#39;);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;async-programming&#34;&gt;Async Programming&lt;/h3&gt;
&lt;p&gt;Async and event-based programming is fully supported. You can use &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;setTimeout()&lt;/a&gt;, &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/Window/setInterval&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;setInterval()&lt;/a&gt;, and other async patterns with xk6-mqtt event handlers.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { Client } from &amp;#39;k6/x/mqtt&amp;#39;;

export default function () {
  const client = new Client();

  client.on(&amp;#39;connect&amp;#39;, async () =&amp;gt; {
    console.log(&amp;#39;Connected to MQTT broker&amp;#39;);
    await client.subscribeAsync(&amp;#39;probe&amp;#39;);

    const intervalId = setInterval(() =&amp;gt; {
      client.publish(&amp;#39;probe&amp;#39;, &amp;#39;ping MQTT!&amp;#39;);
    }, 1000);

    setTimeout(() =&amp;gt; {
      clearInterval(intervalId);
      client.end();
    }, 3100);
  });

  client.on(&amp;#39;message&amp;#39;, (topic, message) =&amp;gt; {
    console.info(new TextDecoder().decode(message));
  });

  client.on(&amp;#39;end&amp;#39;, () =&amp;gt; {
    console.log(&amp;#39;Disconnected from MQTT broker&amp;#39;);
  });

  client.connect(__ENV[&amp;#39;MQTT_BROKER_ADDRESS&amp;#39;] || &amp;#39;mqtt://broker.emqx.io:1883&amp;#39;);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="k6xmqtt">k6/x/mqtt&lt;/h1>
&lt;div data-shared="official-extension.md">
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>This module is implemented as an official extension and is not part of k6 by default. However, k6&amp;rsquo;s
&lt;a href="/docs/k6/v2.3.x/extensions/run/">automatic extension resolution&lt;/a> makes it available seamlessly when you import it in your script. Refer to the
&lt;a href="/docs/k6/v2.3.x/extensions/explore/">extensions documentation&lt;/a> for available extensions and details.&lt;/p></description></item><item><title>k6/x/tcp</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-x-tcp/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-x-tcp/</guid><content><![CDATA[&lt;h1 id=&#34;k6xtcp&#34;&gt;k6/x/tcp&lt;/h1&gt;


&lt;div data-shared=&#34;official-extension.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;This module is implemented as an official extension and is not part of k6 by default. However, k6&amp;rsquo;s 
    &lt;a href=&#34;/docs/k6/v2.3.x/extensions/run/&#34;&gt;automatic extension resolution&lt;/a&gt; makes it available seamlessly when you import it in your script. Refer to the 
    &lt;a href=&#34;/docs/k6/v2.3.x/extensions/explore/&#34;&gt;extensions documentation&lt;/a&gt; for available extensions and details.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;k6/x/tcp&lt;/code&gt; module adds first-class support for raw TCP socket communication to your performance testing scripts. With this extension, you can establish TCP connections and send and receive data directly from your k6 tests.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;ve used Node.js&amp;rsquo;s &lt;a href=&#34;https://nodejs.org/api/net.html#class-netsocket&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;&lt;code&gt;net.Socket&lt;/code&gt;&lt;/a&gt;, the API will feel familiar, with event-driven programming, Promise-based operations, and comprehensive lifecycle management.&lt;/p&gt;
&lt;h2 id=&#34;key-features&#34;&gt;Key features&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Event-driven architecture with support for socket lifecycle events (&lt;code&gt;connect&lt;/code&gt;, &lt;code&gt;data&lt;/code&gt;, &lt;code&gt;close&lt;/code&gt;, &lt;code&gt;error&lt;/code&gt;, &lt;code&gt;timeout&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Promise-based &lt;code&gt;connect()&lt;/code&gt; and &lt;code&gt;write()&lt;/code&gt; methods for use with &lt;code&gt;async&lt;/code&gt;/&lt;code&gt;await&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;TLS/SSL support using standard 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/protocols/ssl-tls/&#34;&gt;k6 TLS configuration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Binary data handling: send and receive strings and &lt;code&gt;ArrayBuffer&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Automatic metrics collection for all socket operations&lt;/li&gt;
&lt;li&gt;Optional custom tags for filtering and grouping metrics&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;use-cases&#34;&gt;Use cases&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Load testing TCP-based services and custom binary protocols&lt;/li&gt;
&lt;li&gt;Testing raw network protocol implementations under high concurrency&lt;/li&gt;
&lt;li&gt;Validating server behavior and connection handling under load&lt;/li&gt;
&lt;li&gt;Performance testing services that don&amp;rsquo;t use HTTP&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;api&#34;&gt;API&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Class&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-tcp/socket/&#34;&gt;Socket&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;TCP socket for connecting to servers and managing operations&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-tcp/socket/connect/&#34;&gt;Socket.connect()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Establish a TCP connection&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-tcp/socket/write/&#34;&gt;Socket.write()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Send data over the socket&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-tcp/socket/destroy/&#34;&gt;Socket.destroy()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Close and destroy the socket&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-tcp/socket/set-timeout/&#34;&gt;Socket.setTimeout()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Set inactivity timeout&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-tcp/socket/on/&#34;&gt;Socket.on()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Register event handlers&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;metrics&#34;&gt;Metrics&lt;/h2&gt;
&lt;p&gt;The extension automatically generates metrics for TCP socket operations:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Metric&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tcp_socket_connecting&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Trend&lt;/td&gt;
              &lt;td&gt;Time to establish TCP connection (ms)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tcp_socket_resolving&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Trend&lt;/td&gt;
              &lt;td&gt;Time to resolve hostname (ms)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tcp_socket_duration&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Trend&lt;/td&gt;
              &lt;td&gt;Total duration of socket connection (ms)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tcp_sockets&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Counter&lt;/td&gt;
              &lt;td&gt;Number of TCP socket connections established&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tcp_reads&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Counter&lt;/td&gt;
              &lt;td&gt;Number of read operations&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tcp_writes&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Counter&lt;/td&gt;
              &lt;td&gt;Number of write operations&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tcp_errors&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Counter&lt;/td&gt;
              &lt;td&gt;Number of TCP errors&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tcp_timeouts&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Counter&lt;/td&gt;
              &lt;td&gt;Number of socket timeouts&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tcp_partial_writes&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Counter&lt;/td&gt;
              &lt;td&gt;Number of partial write failures&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;data_sent&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Counter&lt;/td&gt;
              &lt;td&gt;Total bytes sent (builtin k6 metric)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;data_received&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Counter&lt;/td&gt;
              &lt;td&gt;Total bytes received (builtin k6 metric)&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;You can pass custom &lt;code&gt;tags&lt;/code&gt; in the Socket constructor, connection options, or write options to attach additional metadata to each metric.&lt;/p&gt;
&lt;h2 id=&#34;event-driven-architecture&#34;&gt;Event-driven architecture&lt;/h2&gt;
&lt;p&gt;Unlike HTTP-based tests, TCP tests use an asynchronous event loop. Each VU creates a Socket, registers event handlers, and connects to a server. The VU remains active until &lt;code&gt;socket.destroy()&lt;/code&gt; is called or the connection is closed.&lt;/p&gt;
&lt;p&gt;Register handlers with &lt;code&gt;socket.on()&lt;/code&gt; before calling &lt;code&gt;socket.connect()&lt;/code&gt;. The &lt;code&gt;connect&lt;/code&gt; handler fires when the connection is established; the &lt;code&gt;data&lt;/code&gt; handler fires each time data is received; the &lt;code&gt;close&lt;/code&gt; handler fires when the connection is fully closed.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;!-- md-k6:skipall --&gt;
&lt;h3 id=&#34;basic-usage&#34;&gt;Basic usage&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { Socket } from &amp;#39;k6/x/tcp&amp;#39;;

export default async function () {
  const socket = new Socket();

  const closed = new Promise((resolve) =&amp;gt; {
    socket.on(&amp;#39;close&amp;#39;, () =&amp;gt; {
      console.log(&amp;#39;Connection closed&amp;#39;);
      resolve();
    });
  });

  socket.on(&amp;#39;error&amp;#39;, (err) =&amp;gt; {
    console.error(&amp;#39;Error:&amp;#39;, err);
  });

  const host = __ENV.TCP_HOST || &amp;#39;localhost&amp;#39;;
  const port = __ENV.TCP_PORT || &amp;#39;8080&amp;#39;;

  await socket.connect(port, host);
  console.log(&amp;#39;Connected&amp;#39;);
  socket.destroy();

  await closed;
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;tls-connection&#34;&gt;TLS connection&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { Socket } from &amp;#39;k6/x/tcp&amp;#39;;

export default async function () {
  const socket = new Socket();

  const closed = new Promise((resolve) =&amp;gt; {
    socket.on(&amp;#39;close&amp;#39;, resolve);
  });

  socket.on(&amp;#39;data&amp;#39;, (data) =&amp;gt; {
    const response = new TextDecoder().decode(data);
    console.log(&amp;#39;Received:&amp;#39;, response.substring(0, 100));
    socket.destroy();
  });

  socket.on(&amp;#39;error&amp;#39;, (err) =&amp;gt; {
    console.error(&amp;#39;Error:&amp;#39;, err);
  });

  const host = __ENV.TLS_HOST || &amp;#39;example.com&amp;#39;;

  await socket.connect({ port: 443, host, tls: true });
  await socket.write(`GET / HTTP/1.1\r\nHost: ${host}\r\nConnection: close\r\n\r\n`);

  await closed;
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="k6xtcp">k6/x/tcp&lt;/h1>
&lt;div data-shared="official-extension.md">
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>This module is implemented as an official extension and is not part of k6 by default. However, k6&amp;rsquo;s
&lt;a href="/docs/k6/v2.3.x/extensions/run/">automatic extension resolution&lt;/a> makes it available seamlessly when you import it in your script. Refer to the
&lt;a href="/docs/k6/v2.3.x/extensions/explore/">extensions documentation&lt;/a> for available extensions and details.&lt;/p></description></item><item><title>k6/x/tls</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-x-tls/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-x-tls/</guid><content><![CDATA[&lt;h1 id=&#34;k6xtls&#34;&gt;k6/x/tls&lt;/h1&gt;


&lt;div data-shared=&#34;extension.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;This module is implemented as an official extension and is available natively in k6, requiring no additional installation or build steps. Refer to the 
    &lt;a href=&#34;/docs/k6/v2.3.x/extensions/explore/&#34;&gt;extensions documentation&lt;/a&gt; for available extensions and details.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;k6/x/tls&lt;/code&gt; module provides functionality for TLS certificate validation and inspection, allowing you to fetch certificate details and validate their properties directly from your k6 tests.&lt;/p&gt;
&lt;h2 id=&#34;use-cases&#34;&gt;Use cases&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Fetch TLS certificate information from any host&lt;/li&gt;
&lt;li&gt;Validate certificate expiration and properties&lt;/li&gt;
&lt;li&gt;Access certificate details (for example subject, issuer, fingerprint)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;api&#34;&gt;API&lt;/h2&gt;
&lt;h3 id=&#34;getcertificate-hostname-&#34;&gt;getCertificate( hostname )&lt;/h3&gt;
&lt;p&gt;Fetches TLS certificate information from a specified host.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;tls.getCertificate&lt;/code&gt; function retrieves TLS certificate details from a given hostname and returns a promise that resolves to a certificate object containing various properties such as expiration date, subject, issuer, and fingerprint information.&lt;/p&gt;
&lt;h4 id=&#34;parameters&#34;&gt;Parameters&lt;/h4&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;hostname&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;string&lt;/td&gt;
              &lt;td&gt;The hostname to fetch the TLS certificate from. For example, &amp;ldquo;example.com&amp;rdquo; or &amp;ldquo;k6.io&amp;rdquo;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h4 id=&#34;returns&#34;&gt;Returns&lt;/h4&gt;
&lt;p&gt;A promise resolving to a certificate object containing the following properties:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Property&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;subject&lt;/td&gt;
              &lt;td&gt;object&lt;/td&gt;
              &lt;td&gt;The certificate subject information (pkixName object)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;issuer&lt;/td&gt;
              &lt;td&gt;object&lt;/td&gt;
              &lt;td&gt;The certificate issuer information (pkixName object)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;issued&lt;/td&gt;
              &lt;td&gt;number&lt;/td&gt;
              &lt;td&gt;The certificate issued timestamp in milliseconds since Unix epoch&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;expires&lt;/td&gt;
              &lt;td&gt;number&lt;/td&gt;
              &lt;td&gt;The certificate expiration timestamp in milliseconds since Unix epoch&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;fingerprint&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;The certificate fingerprint&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;!-- md-k6:skipall --&gt;
&lt;h3 id=&#34;check-if-a-certificate-is-expired&#34;&gt;Check if a certificate is expired&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import tls from &amp;#34;k6/x/tls&amp;#34;;
import { check } from &amp;#34;k6&amp;#34;;

export default async function () {
  const cert = await tls.getCertificate(&amp;#34;example.com&amp;#34;);

  check(cert, {
    &amp;#34;certificate is not expired&amp;#34;: (c) =&amp;gt; c.expires &amp;gt; Date.now(),
  });

  console.log(`Certificate expires: ${new Date(cert.expires)}`);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="k6xtls">k6/x/tls&lt;/h1>
&lt;div data-shared="extension.md">
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>This module is implemented as an official extension and is available natively in k6, requiring no additional installation or build steps. Refer to the
&lt;a href="/docs/k6/v2.3.x/extensions/explore/">extensions documentation&lt;/a> for available extensions and details.&lt;/p></description></item><item><title>k6/x/redis</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-x-redis/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-x-redis/</guid><content><![CDATA[&lt;h1 id=&#34;k6xredis&#34;&gt;k6/x/redis&lt;/h1&gt;
&lt;p&gt;The &lt;a href=&#34;https://redis.io/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Redis&lt;/a&gt; module provides a client library that makes it possible to interact with Redis directly from a k6 script.
With this module, you can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Load test Redis&lt;/li&gt;
&lt;li&gt;Use Redis as a data store for test-script logic.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Though the API intends to be thorough and extensive, it does not expose the whole Redis API.
Instead, the intent is to expose Redis for use cases most appropriate to k6.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Class&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-redis/client/&#34;&gt;Client&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Client that exposes allowed interactions with Redis.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-redis/redis-options/&#34;&gt;Options&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Options used to configure the behavior of the 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-x-redis/client/&#34;&gt;Redis Client&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;notes-on-usage&#34;&gt;Notes on usage&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;Client&lt;/code&gt; exposes a &lt;a href=&#34;https://javascript.info/promise-basics&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;promise&lt;/a&gt;-based API.
Unlike most other current k6 modules and extensions,
which operate in a synchronous manner,
the Redis &lt;code&gt;Client&lt;/code&gt; operates in an asynchronous manner.
In practice, this means that using the Redis &lt;code&gt;Client&lt;/code&gt;&amp;rsquo;s methods won&amp;rsquo;t block test execution,
and that the test will continue to run even if the Redis &lt;code&gt;Client&lt;/code&gt; isn&amp;rsquo;t ready to respond to the request.
The &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; keywords enable asynchronous, promise-based behavior to be written in a cleaner style, avoiding the need to explicitly configure promise chains
(for details, refer to the &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;MDN documentation&lt;/a&gt;).&lt;/p&gt;
]]></content><description>&lt;h1 id="k6xredis">k6/x/redis&lt;/h1>
&lt;p>The &lt;a href="https://redis.io/" target="_blank" rel="noopener noreferrer">Redis&lt;/a> module provides a client library that makes it possible to interact with Redis directly from a k6 script.
With this module, you can:&lt;/p></description></item><item><title>Error Codes</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/error-codes/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/error-codes/</guid><content><![CDATA[&lt;h1 id=&#34;error-codes&#34;&gt;Error Codes&lt;/h1&gt;
&lt;p&gt;Error codes are unique numbers that can be used to identify and handle different application and network errors more easily. For the moment, these error codes are applicable only for errors that happen during HTTP requests, but they will be reused and extended to support other protocols in future k6 releases.&lt;/p&gt;
&lt;p&gt;When an error occurs, its code is determined and returned as both the &lt;code&gt;error_code&lt;/code&gt; field of the 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/response/&#34;&gt;&lt;code&gt;http.Response&lt;/code&gt;&lt;/a&gt; object, and also attached as the &lt;code&gt;error_code&lt;/code&gt; 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/tags-and-groups/&#34;&gt;tag&lt;/a&gt; to any 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/metrics/&#34;&gt;metrics&lt;/a&gt; associated with that request. Additionally, for more details, the &lt;code&gt;error&lt;/code&gt; metric tag and &lt;code&gt;http.Response&lt;/code&gt; field will still contain the actual string error message.&lt;/p&gt;
&lt;p&gt;Error codes for different errors are as distinct as possible, but for easier handling and grouping, codes in different error categories are also grouped in broad ranges. The current error code ranges are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;1000-1099 - General errors&lt;/li&gt;
&lt;li&gt;1100-1199 - DNS errors&lt;/li&gt;
&lt;li&gt;1200-1299 - TCP errors&lt;/li&gt;
&lt;li&gt;1300-1399 - TLS errors&lt;/li&gt;
&lt;li&gt;1400-1499 - HTTP 4xx errors&lt;/li&gt;
&lt;li&gt;1500-1599 - HTTP 5xx errors&lt;/li&gt;
&lt;li&gt;1600-1699 - HTTP/2 specific errors&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The following specific error codes are currently defined:&lt;/p&gt;


&lt;div data-shared=&#34;javascript-api/k6-errors-list.md&#34;&gt;
            &lt;ul&gt;
&lt;li&gt;1000: A generic error that isn&amp;rsquo;t any of the ones listed below.&lt;/li&gt;
&lt;li&gt;1010: A non-TCP network error - this is a place holder there is no error currently known to trigger it.&lt;/li&gt;
&lt;li&gt;1020: An invalid URL was specified.&lt;/li&gt;
&lt;li&gt;1050: The HTTP request has timed out.&lt;/li&gt;
&lt;li&gt;1100: A generic DNS error that isn&amp;rsquo;t any of the ones listed below.&lt;/li&gt;
&lt;li&gt;1101: No IP for the provided host was found.&lt;/li&gt;
&lt;li&gt;1110: Blacklisted IP was resolved or a connection to such was tried to be established.&lt;/li&gt;
&lt;li&gt;1111: Blacklisted hostname using The 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/k6-options/reference/#block-hostnames&#34;&gt;Block Hostnames&lt;/a&gt; option.&lt;/li&gt;
&lt;li&gt;1200: A generic TCP error that isn&amp;rsquo;t any of the ones listed below.&lt;/li&gt;
&lt;li&gt;1201: A &amp;ldquo;broken pipe&amp;rdquo; on write - the other side has likely closed the connection.&lt;/li&gt;
&lt;li&gt;1202: An unknown TCP error - We got an error that we don&amp;rsquo;t recognize but it is from the operating system and has &lt;code&gt;errno&lt;/code&gt; set on it. The message in &lt;code&gt;error&lt;/code&gt; includes the operation(write,read) and the errno, the OS, and the original message of the error.&lt;/li&gt;
&lt;li&gt;1210: General TCP dial error.&lt;/li&gt;
&lt;li&gt;1211: Dial timeout error - the timeout for the dial was reached.&lt;/li&gt;
&lt;li&gt;1212: Dial connection refused - the connection was refused by the other party on dial.&lt;/li&gt;
&lt;li&gt;1213: Dial unknown error.&lt;/li&gt;
&lt;li&gt;1220: Reset by peer - the connection was reset by the other party, most likely a server.&lt;/li&gt;
&lt;li&gt;1300: General TLS error&lt;/li&gt;
&lt;li&gt;1310: Unknown authority - the certificate issuer is unknown.&lt;/li&gt;
&lt;li&gt;1311: The certificate doesn&amp;rsquo;t match the hostname.&lt;/li&gt;
&lt;li&gt;1400 to 1499: error codes that correspond to the &lt;a href=&#34;https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_errors&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;HTTP 4xx status codes for client errors&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;1500 to 1599: error codes that correspond to the &lt;a href=&#34;https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_errors&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;HTTP 5xx status codes for server errors&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;1600: A generic HTTP/2 error that isn&amp;rsquo;t any of the ones listed below.&lt;/li&gt;
&lt;li&gt;1610: A general HTTP/2 GoAway error.&lt;/li&gt;
&lt;li&gt;1611 to 1629: HTTP/2 GoAway errors with the value of the specific &lt;a href=&#34;https://tools.ietf.org/html/rfc7540#section-7&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;HTTP/2 error code&lt;/a&gt; added to 1611.&lt;/li&gt;
&lt;li&gt;1630: A general HTTP/2 stream error.&lt;/li&gt;
&lt;li&gt;1631 to 1649: HTTP/2 stream errors with the value of the specific &lt;a href=&#34;https://tools.ietf.org/html/rfc7540#section-7&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;HTTP/2 error code&lt;/a&gt; added to 1631.&lt;/li&gt;
&lt;li&gt;1650: A general HTTP/2 connection error.&lt;/li&gt;
&lt;li&gt;1651 to 1669: HTTP/2 connection errors with the value of the specific &lt;a href=&#34;https://tools.ietf.org/html/rfc7540#section-7&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;HTTP/2 error code&lt;/a&gt; added to 1651.&lt;/li&gt;
&lt;li&gt;1701: Decompression error.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

        
]]></content><description>&lt;h1 id="error-codes">Error Codes&lt;/h1>
&lt;p>Error codes are unique numbers that can be used to identify and handle different application and network errors more easily. For the moment, these error codes are applicable only for errors that happen during HTTP requests, but they will be reused and extended to support other protocols in future k6 releases.&lt;/p></description></item><item><title>crypto</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/crypto/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/crypto/</guid><content><![CDATA[&lt;h1 id=&#34;crypto&#34;&gt;crypto&lt;/h1&gt;
&lt;p&gt;With this module, you can use the &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;WebCrypto API&lt;/a&gt; in your k6 scripts. However, note that this API is not yet fully implemented and some algorithms and features might still be missing.&lt;/p&gt;
&lt;p&gt;The Web Crypto API is a JavaScript API for performing cryptographic operations such as encryption, decryption, digital signature generation and verification, and key generation and management. It provides a standard interface to access cryptographic functionality, which can help ensure that cryptographic operations are performed correctly and securely.&lt;/p&gt;
&lt;h2 id=&#34;api&#34;&gt;API&lt;/h2&gt;
&lt;p&gt;The module is a top-level &lt;code&gt;crypto&lt;/code&gt; object with the following properties and methods:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Interface/Function&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/crypto/getrandomvalues/&#34;&gt;getRandomValues&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Fills the passed &lt;code&gt;TypedArray&lt;/code&gt; with cryptographically sound random values.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/crypto/randomuuid/&#34;&gt;randomUUID&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Returns a randomly generated, 36 character long v4 UUID.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/crypto/subtlecrypto/&#34;&gt;subtle&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/crypto/subtlecrypto/&#34;&gt;SubtleCrypto&lt;/a&gt; interface provides access to common cryptographic primitives, such as hashing, signing, encryption, or decryption.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;export default async function () {
  const plaintextText = &amp;#39;Hello, World!&amp;#39;;
  const plaintext = new TextEncoder().encode(plaintextText);

  /**
   * Generate a symmetric key using the AES-CBC algorithm.
   */
  const key = await crypto.subtle.generateKey(
    {
      name: &amp;#39;AES-CBC&amp;#39;,
      length: 256,
    },
    true,
    [&amp;#39;encrypt&amp;#39;, &amp;#39;decrypt&amp;#39;]
  );

  /**
   * Encrypt the plaintext using the AES-CBC key with
   * have generated.
   */
  const iv = crypto.getRandomValues(new Uint8Array(16));
  const ciphertext = await crypto.subtle.encrypt(
    {
      name: &amp;#39;AES-CBC&amp;#39;,
      iv: iv,
    },
    key,
    plaintext
  );

  /**
   * Decrypt the ciphertext using the same key to verify
   * that the resulting plaintext is the same as the original.
   */
  const deciphered = await crypto.subtle.decrypt(
    {
      name: &amp;#39;AES-CBC&amp;#39;,
      iv: iv,
    },
    key,
    ciphertext
  );

  console.log(
    &amp;#39;deciphered text == original plaintext: &amp;#39;,
    new TextDecoder().decode(deciphered) === plaintextText
  );
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="crypto">crypto&lt;/h1>
&lt;p>With this module, you can use the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API" target="_blank" rel="noopener noreferrer">WebCrypto API&lt;/a> in your k6 scripts. However, note that this API is not yet fully implemented and some algorithms and features might still be missing.&lt;/p></description></item><item><title>jslib</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/</guid><content><![CDATA[&lt;h1 id=&#34;jslib&#34;&gt;jslib&lt;/h1&gt;


&lt;div data-shared=&#34;javascript-api/jslib.md&#34;&gt;
            &lt;p&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/&#34;&gt;jslib&lt;/a&gt; is a collection of JavaScript libraries maintained by the k6 team that can be used in k6 scripts.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Library&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/aws/&#34;&gt;aws&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Library allowing to interact with Amazon AWS services&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/&#34;&gt;httpx&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Wrapper around 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/#k6http&#34;&gt;k6/http&lt;/a&gt; to simplify session handling&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/&#34;&gt;k6chaijs&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;BDD assertion style&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/&#34;&gt;http-instrumentation-pyroscope&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Library to instrument k6/http to send baggage headers for pyroscope to read back&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-tempo/&#34;&gt;http-instrumentation-tempo&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Library to instrument k6/http to send tracing data&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/&#34;&gt;testing&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Advanced assertion library with Playwright-inspired API for protocol and browser testing&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/totp/&#34;&gt;totp&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;TOTP (Time-based One-Time Password) generation and verification&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/utils/&#34;&gt;utils&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Small utility functions useful in every day load testing&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
]]></content><description>&lt;h1 id="jslib">jslib&lt;/h1>
&lt;div data-shared="javascript-api/jslib.md">
&lt;p>
&lt;a href="/docs/k6/v2.3.x/javascript-api/jslib/">jslib&lt;/a> is a collection of JavaScript libraries maintained by the k6 team that can be used in k6 scripts.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Library&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/jslib/aws/">aws&lt;/a>&lt;/td>
&lt;td>Library allowing to interact with Amazon AWS services&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/jslib/httpx/">httpx&lt;/a>&lt;/td>
&lt;td>Wrapper around
&lt;a href="/docs/k6/v2.3.x/javascript-api/#k6http">k6/http&lt;/a> to simplify session handling&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/">k6chaijs&lt;/a>&lt;/td>
&lt;td>BDD assertion style&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/">http-instrumentation-pyroscope&lt;/a>&lt;/td>
&lt;td>Library to instrument k6/http to send baggage headers for pyroscope to read back&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-tempo/">http-instrumentation-tempo&lt;/a>&lt;/td>
&lt;td>Library to instrument k6/http to send tracing data&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/jslib/testing/">testing&lt;/a>&lt;/td>
&lt;td>Advanced assertion library with Playwright-inspired API for protocol and browser testing&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/jslib/totp/">totp&lt;/a>&lt;/td>
&lt;td>TOTP (Time-based One-Time Password) generation and verification&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/jslib/utils/">utils&lt;/a>&lt;/td>
&lt;td>Small utility functions useful in every day load testing&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;/div></description></item><item><title>websockets</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-websockets/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-websockets/</guid><content><![CDATA[&lt;h1 id=&#34;websockets&#34;&gt;websockets&lt;/h1&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The &lt;code&gt;k6/experimental/websockets&lt;/code&gt; module has been deprecated. Use &lt;code&gt;k6/websockets&lt;/code&gt; instead.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;This module implements the browser &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/WebSocket&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;WebSocket API&lt;/a&gt; with additional k6-specific functionalities (cookies, tags, headers and so on).&lt;/p&gt;
&lt;p&gt;The main difference between this module and 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-ws/&#34;&gt;&lt;code&gt;k6/ws&lt;/code&gt;&lt;/a&gt; is that this module uses a global event loop instead of a local one.
A global event loop lets a single VU have multiple concurrent connections, which improves performance.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;When you enable the experimental 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/feature-flags/&#34;&gt;&lt;code&gt;async-metric-context&lt;/code&gt; feature flag&lt;/a&gt;, handlers assigned to WebSocket event properties, such as &lt;code&gt;onopen&lt;/code&gt; and &lt;code&gt;onmessage&lt;/code&gt;, and handlers registered with &lt;code&gt;addEventListener()&lt;/code&gt; capture the tags and metadata active at registration. Metrics emitted by a handler use a copy of that context, and k6 restores the interrupted context after the handler returns or throws. Promise reactions and &lt;code&gt;await&lt;/code&gt; continuations created by the handler keep its context.&lt;/p&gt;
&lt;p&gt;This behavior applies to &lt;code&gt;k6/websockets&lt;/code&gt;, but not to the legacy &lt;code&gt;k6/ws&lt;/code&gt; module.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Class/Method&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/params/&#34;&gt;Params&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Used for setting various WebSocket connection parameters such as headers, cookie jar, compression, etc.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/websocket/&#34;&gt;WebSocket(url, protocols, params)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Constructs a new WebSocket connection.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/websocket/websocket-close/&#34;&gt;WebSocket.close()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Close the WebSocket connection.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/websocket/websocket-ping/&#34;&gt;WebSocket.ping()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Send a ping.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/websocket/websocket-send/&#34;&gt;WebSocket.send(data)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Send data.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/websocket/websocket-addeventlistener/&#34;&gt;WebSocket.addEventListener(event, handler)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Add an event listener on the connection for specific event.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/blob/&#34;&gt;Blob&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Interface that represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data, or converted into a 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestream/&#34;&gt;ReadableStream&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;A WebSocket instance also has the following properties:&lt;/p&gt;
&lt;!-- vale off --&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Class/Property&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;WebSocket.readyState&lt;/td&gt;
              &lt;td&gt;The current state of the connection. Could be one of &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;the four states&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;WebSocket.url&lt;/td&gt;
              &lt;td&gt;The URL of the connection as resolved by the constructor.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;WebSocket.bufferedAmount&lt;/td&gt;
              &lt;td&gt;The number of bytes of data that have been queued using calls to &lt;code&gt;send()&lt;/code&gt; but not yet transmitted to the network.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;WebSocket.binaryType&lt;/td&gt;
              &lt;td&gt;The &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;&lt;code&gt;binaryType&lt;/code&gt;&lt;/a&gt; controls the type of binary data being received over the WebSocket connection. Use &lt;code&gt;&amp;quot;blob&amp;quot;&lt;/code&gt; to receive it as &lt;code&gt;Blob&lt;/code&gt;, or &lt;code&gt;&amp;quot;arraybuffer&amp;quot;&lt;/code&gt; to receive it as &lt;code&gt;ArrayBuffer&lt;/code&gt;. The default value is &lt;code&gt;&amp;quot;blob&amp;quot;&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/websocket/websocket-onmessage/&#34;&gt;WebSocket.onmessage&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A handler for &lt;code&gt;message&lt;/code&gt; events.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/websocket/websocket-onerror/&#34;&gt;WebSocket.onerror&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A handler for &lt;code&gt;error&lt;/code&gt; events.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/websocket/websocket-onopen/&#34;&gt;WebSocket.onopen&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A handler for &lt;code&gt;open&lt;/code&gt; events.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/websocket/websocket-onclose/&#34;&gt;WebSocket.onclose&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A handler for &lt;code&gt;close&lt;/code&gt; events.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/websocket/websocket-onping/&#34;&gt;WebSocket.onping&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A handler for &lt;code&gt;ping&lt;/code&gt; events.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/websocket/websocket-onpong/&#34;&gt;WebSocket.onpong&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A handler for &lt;code&gt;pong&lt;/code&gt; events.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;!-- vale on --&gt;
&lt;p&gt;Compare &lt;code&gt;readyState&lt;/code&gt; with the 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-websockets/websocket/#ready-state-constants&#34;&gt;ready-state constants&lt;/a&gt;, such as &lt;code&gt;WebSocket.OPEN&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;websocket-metrics&#34;&gt;Websocket metrics&lt;/h2&gt;
&lt;p&gt;k6 takes specific measurements for Websockets.
For the complete list, refer to the 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/metrics/reference/#websockets&#34;&gt;Metrics reference&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;This example shows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How a single VU can run multiple WebSockets connections asynchronously.&lt;/li&gt;
&lt;li&gt;How to use the timeout and interval functions to stop the connections after some period.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { randomString, randomIntBetween } from &amp;#39;https://jslib.k6.io/k6-utils/1.1.0/index.js&amp;#39;;
import { WebSocket } from &amp;#39;k6/websockets&amp;#39;;

const sessionDuration = randomIntBetween(1000, 3000); // user session between 1s and 3s

export default function () {
  for (let i = 0; i &amp;lt; 4; i&amp;#43;&amp;#43;) {
    startWSWorker(i);
  }
}

function startWSWorker(id) {
  // create a new websocket connection
  const ws = new WebSocket(`wss://quickpizza.grafana.com/ws`);
  ws.binaryType = &amp;#39;arraybuffer&amp;#39;;

  ws.addEventListener(&amp;#39;open&amp;#39;, () =&amp;gt; {
    // change the user name
    ws.send(JSON.stringify({ event: &amp;#39;SET_NAME&amp;#39;, new_name: `VU ${__VU}:${id}` }));

    // listen for messages/errors and log them into console
    ws.addEventListener(&amp;#39;message&amp;#39;, (e) =&amp;gt; {
      const msg = JSON.parse(e.data);
      if (msg.event === &amp;#39;CHAT_MSG&amp;#39;) {
        console.log(`VU ${__VU}:${id} received: ${msg.user} says: ${msg.message}`);
      } else if (msg.event === &amp;#39;ERROR&amp;#39;) {
        console.error(`VU ${__VU}:${id} received:: ${msg.message}`);
      } else {
        console.log(`VU ${__VU}:${id} received unhandled message: ${msg.message}`);
      }
    });

    // send a message every 2-8 seconds
    const intervalId = setInterval(() =&amp;gt; {
      ws.send(JSON.stringify({ event: &amp;#39;SAY&amp;#39;, message: `I&amp;#39;m saying ${randomString(5)}` }));
    }, randomIntBetween(2000, 8000)); // say something every 2-8 seconds

    // after a sessionDuration stop sending messages and leave the room
    const timeout1id = setTimeout(function () {
      clearInterval(intervalId);
      console.log(`VU ${__VU}:${id}: ${sessionDuration}ms passed, leaving the chat`);
      ws.send(JSON.stringify({ event: &amp;#39;LEAVE&amp;#39; }));
    }, sessionDuration);

    // after a sessionDuration &amp;#43; 3s close the connection
    const timeout2id = setTimeout(function () {
      console.log(`Closing the socket forcefully 3s after graceful LEAVE`);
      ws.close();
    }, sessionDuration &amp;#43; 3000);

    // when connection is closing, clean up the previously created timers
    ws.addEventListener(&amp;#39;close&amp;#39;, () =&amp;gt; {
      clearTimeout(timeout1id);
      clearTimeout(timeout2id);
      console.log(`VU ${__VU}:${id}: disconnected`);
    });
  });
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="websockets">websockets&lt;/h1>
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>The &lt;code>k6/experimental/websockets&lt;/code> module has been deprecated. Use &lt;code>k6/websockets&lt;/code> instead.&lt;/p>&lt;/blockquote>&lt;/div>
&lt;p>This module implements the browser &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/WebSocket" target="_blank" rel="noopener noreferrer">WebSocket API&lt;/a> with additional k6-specific functionalities (cookies, tags, headers and so on).&lt;/p></description></item><item><title>import.meta</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/import.meta/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/import.meta/</guid><content><![CDATA[&lt;h1 id=&#34;importmeta&#34;&gt;import.meta&lt;/h1&gt;


&lt;div data-shared=&#34;javascript-api/import.meta.md&#34;&gt;
            &lt;p&gt;The &lt;code&gt;import.meta&lt;/code&gt; object provides the &lt;code&gt;resolve&lt;/code&gt; function, which resolves a path to a URL string in the same way an import statement does.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;import.meta&lt;/code&gt; object is only available in ECMAScript modules, not in CommonJS modules.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/import.meta/resolve/&#34;&gt;import.meta.resolve&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Resolves a path to a URL string the same way an import statement does.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
]]></content><description>&lt;h1 id="importmeta">import.meta&lt;/h1>
&lt;div data-shared="javascript-api/import.meta.md">
&lt;p>The &lt;code>import.meta&lt;/code> object provides the &lt;code>resolve&lt;/code> function, which resolves a path to a URL string in the same way an import statement does.&lt;/p></description></item></channel></rss>