|
| 1 | +--- |
| 2 | +title: Version 1.4.0 release notes |
| 3 | +menuTitle: v1.4.0 |
| 4 | +description: The release notes for Grafana k6 version 1.4.0 |
| 5 | +weight: 9985 |
| 6 | +--- |
| 7 | + |
| 8 | +# Version 1.4.0 release notes |
| 9 | + |
| 10 | +<!-- md-k6:skipall --> |
| 11 | + |
| 12 | +k6 `v1.4.0` is here 🎉! This release includes: |
| 13 | + |
| 14 | +- OpenTelemetry output graduated from experimental to stable status. |
| 15 | +- Changes in the Browser module: |
| 16 | + - `page.waitForRequest` for waiting on specific HTTP requests. |
| 17 | + - `QueryAll` methods now return elements in DOM order. |
| 18 | + - `locator.evaluate` and `locator.evaluateHandle` for executing JavaScript code in the page context with access to the matching element. |
| 19 | + - `page.unroute(url)` and `page.unrouteAll` for removing routes registered with `page.route`. |
| 20 | + |
| 21 | +## Breaking changes |
| 22 | + |
| 23 | +As per our [stability guarantees](https://grafana.com/docs/k6/latest/reference/versioning-and-stability-guarantees/), breaking changes across minor releases are allowed only for experimental features. |
| 24 | + |
| 25 | +### Breaking changes for experimental modules |
| 26 | + |
| 27 | +- [#5164](https://github.com/grafana/k6/pull/5164) OpenTelemetry output now exports rate metrics as a single counter with `zero`/`nonzero` labels instead of separate metrics. |
| 28 | +- [#5333](https://github.com/grafana/k6/pull/5333) OpenTelemetry output configuration: `K6_OTEL_EXPORTER_TYPE` is deprecated in favor of `K6_OTEL_EXPORTER_PROTOCOL` to align with OpenTelemetry standards. |
| 29 | + |
| 30 | +### Breaking changes for undefined behaviours |
| 31 | +- [#5320](https://github.com/grafana/k6/pull/5320), [#5239](https://github.com/grafana/k6/pull/5239), [#5342](https://github.com/grafana/k6/pull/5342) Automatic extension resolution now only inspects ES module `import` statements and no longer supports CommonJS `require()` calls. CommonJS `require()` calls are dynamic, and it is not possible to know for certain if they will be called, or if they will be called with static strings - the only way they were even previously loaded. This functionality was a quirk of the previous implementation and had numerous problems. Additionally, `use k6` directives are now only recognized when they appear at the beginning of files (after optional shebang and whitespace/comments). This was the original intention, but due to implementation bugs, it did not accurately reflect what was happening. |
| 32 | + |
| 33 | +## New features |
| 34 | + |
| 35 | +### OpenTelemetry output graduation [#5334](https://github.com/grafana/k6/pull/5334) |
| 36 | + |
| 37 | +The OpenTelemetry output has graduated from experimental status and is now available as a stable output using the name `opentelemetry`. This change makes OpenTelemetry the recommended vendor-agnostic solution for exporting k6 telemetry data. |
| 38 | + |
| 39 | +You can now use the stable output name in your k6 commands: |
| 40 | + |
| 41 | +```bash |
| 42 | +# Previous experimental usage (still supported for backward compatibility) |
| 43 | +k6 run --out experimental-opentelemetry script.js |
| 44 | + |
| 45 | +# New stable usage |
| 46 | +k6 run --out opentelemetry script.js |
| 47 | +``` |
| 48 | + |
| 49 | +The `experimental-opentelemetry` name will continue to work for backward compatibility for now but it's deprecated and we might remove it in future versions. We recommend migrating to use the new `opentelemetry` name. |
| 50 | + |
| 51 | +### `page.waitForRequest` [#5330](https://github.com/grafana/k6/pull/5330) |
| 52 | + |
| 53 | +The browser module now supports [`page.waitForRequest()`](https://grafana.com/docs/k6/latest/javascript-api/k6-browser/page/waitforrequest/), which allows you to wait for HTTP requests that match specific URL patterns during browser automation. This method is particularly valuable for testing scenarios where you need to ensure specific network requests are initiated before proceeding with test actions. |
| 54 | + |
| 55 | +The method supports multiple URL pattern matching strategies: |
| 56 | + |
| 57 | +```javascript |
| 58 | +// Wait for exact URL match |
| 59 | +const requestPromise = page.waitForRequest('https://api.example.com/data'); |
| 60 | +await page.click('button[data-testid="load-data"]'); |
| 61 | +const request = await requestPromise; |
| 62 | + |
| 63 | +// Wait for regex pattern match |
| 64 | +await page.waitForRequest(/\/api\/.*\.json$/); |
| 65 | + |
| 66 | +// Use with Promise.all for coordinated actions |
| 67 | +await Promise.all([ |
| 68 | + page.waitForRequest('https://api.example.com/user-data'), |
| 69 | + page.click('button[data-testid="load-user-data"]') |
| 70 | +]); |
| 71 | +``` |
| 72 | + |
| 73 | +This complements the existing [`page.waitForResponse()`](https://grafana.com/docs/k6/latest/javascript-api/k6-browser/page/waitforresponse/) method by focusing on HTTP requests rather than responses, providing more granular control over network-dependent test scenarios. |
| 74 | + |
| 75 | +### `page.unroute(url)` and `page.unrouteAll()` [#5223](https://github.com/grafana/k6/pull/5223) |
| 76 | + |
| 77 | +The browser module now supports [`page.unroute(url)`](https://grafana.com/docs/k6/latest/javascript-api/k6-browser/page/unroute/) and [`page.unrouteAll()`](https://grafana.com/docs/k6/latest/javascript-api/k6-browser/page/unrouteall/), allowing you to remove routes previously registered with `page.route`. |
| 78 | + |
| 79 | +Example usage: |
| 80 | +```javascript |
| 81 | +await page.route(/.*\/api\/pizza/, function (route) { |
| 82 | + console.log('Modifying request to /api/pizza'); |
| 83 | + route.continue({ |
| 84 | + postData: JSON.stringify({ |
| 85 | + customName: 'My Pizza', |
| 86 | + }), |
| 87 | + }); |
| 88 | +}); |
| 89 | +... |
| 90 | + |
| 91 | +await page.unroute(/.*\/api\/pizza/); // The URL needs to be exactly the same as the one used in the call to the `route` function |
| 92 | +``` |
| 93 | + |
| 94 | +```javascript |
| 95 | +await page.route(/.*\/api\/pizza/, function (route) { |
| 96 | + console.log('Modifying request to /api/pizza'); |
| 97 | + route.continue({ |
| 98 | + postData: JSON.stringify({ |
| 99 | + customName: 'My Pizza', |
| 100 | + }), |
| 101 | + }); |
| 102 | +}); |
| 103 | +... |
| 104 | + |
| 105 | +await page.unrouteAll(); |
| 106 | +``` |
| 107 | + |
| 108 | +### `locator.evaluate` and `locator.evaluateHandle` [#5306](https://github.com/grafana/k6/pull/5306) |
| 109 | + |
| 110 | +The browser module now supports [`locator.evaluate`](https://grafana.com/docs/k6/latest/javascript-api/k6-browser/locator/evaluate/) and [`locator.evaluateHandle`](https://grafana.com/docs/k6/latest/javascript-api/k6-browser/locator/evaluatehandle/), allowing you to execute JavaScript code in the page context with access to the matching element. The only difference between `evaluate` and `evaluateHandle` is that `evaluateHandle` returns a [JSHandle](https://grafana.com/docs/k6/latest/javascript-api/k6-browser/jshandle/). |
| 111 | + |
| 112 | +Example usage: |
| 113 | +```javascript |
| 114 | +await check(page, { |
| 115 | + 'calling evaluate': async p => { |
| 116 | + const n = await p.locator('#pizza-name').evaluate(pizzaName => pizzaName.textContent); |
| 117 | + return n == 'Our recommendation:'; |
| 118 | + } |
| 119 | +}); |
| 120 | + |
| 121 | +await check(page, { |
| 122 | + 'calling evaluate with arguments': async p => { |
| 123 | + const n = await p.locator('#pizza-name').evaluate((pizzaName, extra) => pizzaName.textContent + extra, ' Super pizza!'); |
| 124 | + return n == 'Our recommendation: Super pizza!'; |
| 125 | + } |
| 126 | +}); |
| 127 | +``` |
| 128 | + |
| 129 | +```javascript |
| 130 | +const jsHandle = await page.locator('#pizza-name').evaluateHandle((pizzaName) => pizzaName); |
| 131 | + |
| 132 | +const obj = await jsHandle.evaluateHandle((handle) => { |
| 133 | + return { innerText: handle.innerText }; |
| 134 | +}); |
| 135 | +console.log(await obj.jsonValue()); // {"innerText":"Our recommendation:"} |
| 136 | +``` |
| 137 | + |
| 138 | +### New officially supported [k6 DNS extension](https://github.com/grafana/xk6-dns) |
| 139 | + |
| 140 | +The [`xk6-dns` extension](https://grafana.com/docs/k6/latest/javascript-api/k6-x-dns) is now officially supported in k6 OSS and k6 Cloud. You can import `k6/x/dns` directly in your scripts thanks to [automatic extension resolution](https://grafana.com/docs/grafana-cloud/testing/k6/author-run/use-k6-extensions/), with no custom build required. |
| 141 | + |
| 142 | +Use it to perform DNS resolution testing as part of your tests: resolve names via custom or system DNS, measure resolution latency and errors, validate records before HTTP steps, compare resolvers, and even load test DNS servers in end‑to‑end scenarios. |
| 143 | + |
| 144 | +For example: |
| 145 | + |
| 146 | +```javascript |
| 147 | +import dns from 'k6/x/dns'; |
| 148 | + |
| 149 | +export default function () { |
| 150 | + const answer = dns.resolve('grafana.com', { recordType: 'A' }); |
| 151 | + console.log(answer.records.map(({ address }) => address).join(', ')); |
| 152 | +} |
| 153 | +``` |
| 154 | + |
| 155 | +The extension currently supports A and AAAA record lookups. If you would like to see additional record types supported, please consider [contributing to the extension](https://github.com/grafana/xk6-dns). |
| 156 | + |
| 157 | + |
| 158 | +### Automatic extension resolution improvements [#5320](https://github.com/grafana/k6/pull/5320), [#5239](https://github.com/grafana/k6/pull/5239), [#5342](https://github.com/grafana/k6/pull/5342), [#5332](https://github.com/grafana/k6/pull/5332), [#5240](https://github.com/grafana/k6/pull/5240) |
| 159 | + |
| 160 | +Automatic extension resolution has been completely reimplemented to use k6's internal module loader instead of the external `k6deps`/esbuild pipeline. This change brings significant improvements in reliability and maintainability. |
| 161 | + |
| 162 | +As part of the rewrite, a few issues and unintended _features_ were found, namely: |
| 163 | +1. Trying to follow `require` calls, which, due to their dynamic nature, don't work particularly stably. That is, depending on where and how the `require` call was used, k6 might decide whether it is needed or not. And it definitely doesn't work when using actual string variables. Support for CommonJS is primarily for backward compatibility, so after an internal discussion, we opted not to support it at all. We could bring this back until v2, if there is enough interest. However, in the long term, it is intended that this not be part of k6. |
| 164 | +2. "use k6 with ..." directives were parsed from the whole file instead of just the beginning, which leads to numerous problems, and was not the intended case. As such, they are now only parsed at the beginning of files (not just the main one) with potential empty lines and comments preceding them. |
| 165 | + |
| 166 | +**Example:** |
| 167 | + |
| 168 | +```javascript |
| 169 | +// main.js |
| 170 | +"use k6 with k6/x/faker" |
| 171 | +import { faker } from 'k6/x/faker'; |
| 172 | +import { helper } from './utils.js'; |
| 173 | + |
| 174 | +export default function() { |
| 175 | + console.log(faker.name()); |
| 176 | + helper(); |
| 177 | +} |
| 178 | +``` |
| 179 | +Or, an example using the directive with CommonJS |
| 180 | +```javascript |
| 181 | +// utils.js |
| 182 | +"use k6 with k6/x/redis" |
| 183 | +const redis = require('k6/x/redis'); |
| 184 | + |
| 185 | +exports.helper = function() { |
| 186 | + // Use redis extension |
| 187 | +} |
| 188 | +``` |
| 189 | + |
| 190 | +In this example, k6 will detect both `k6/x/faker` and `k6/x/redis` extensions from the `use k6` directives in both files and provision a binary that includes both extensions if needed. |
| 191 | + |
| 192 | +Other fixes this brings are: |
| 193 | +1. Fixes for path related issues (irregardless of usage of the feature) on windows, especially between drives. It is possible there were problems on other OSes that were just not reported. [#5176](https://github.com/grafana/k6/issues/5176) |
| 194 | +2. Syntax errors were not reported as such, as the underlying `esbuild` parsing will fail, but won't be handled well. [#5127](https://github.com/grafana/k6/issues/5127), [#5104](https://github.com/grafana/k6/issues/5104) |
| 195 | + |
| 196 | +3. Propagating exit codes from a sub-process running the new k6. This lets you use the result of the exit code. |
0 commit comments