diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 95dc5176a8b044..d99d16e067a0c0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -3143,7 +3143,6 @@ /types/hash-stream/ @BendingBender /types/hash-sum/ @DanielRosenwasser /types/hasher/ @flyfishMT -/types/hashmap/ @rafalwrzeszcz @outring @dodomorandi /types/hashring/ @medns /types/hashset/ @gerich-home /types/hashtable/ @gerich-home @@ -3258,7 +3257,6 @@ /types/http-aws-es/ @marcogrcr /types/http-build-query/ @alexu740 /types/http-cache-semantics/ @BendingBender -/types/http-codes/ @mhegazy /types/http-context/ @mtraynham /types/http-errors/ @tkrotoff @BendingBender @bjohansebas /types/http-headers/ @BendingBender diff --git a/types/k6/browser/index.d.ts b/types/k6/browser/index.d.ts index b82c2a87ce3f01..92fea9d36913ad 100644 --- a/types/k6/browser/index.d.ts +++ b/types/k6/browser/index.d.ts @@ -728,6 +728,66 @@ export interface NewBrowserContextOptions { */ export const browser: Browser; +/** + * The `chromium` named export allows attaching to an already running + * Chromium-based browser over the Chrome DevTools Protocol (CDP), instead of + * relying on the browser instance that k6 launches and manages for you. + */ +export const chromium: BrowserType; + +/** + * `BrowserType` is the entry point to connect to an existing Chromium-based + * browser. + */ +export interface BrowserType { + /** + * Attaches to an already running Chromium-based browser over the Chrome + * DevTools Protocol (CDP), and returns the corresponding `Browser` + * instance. + * + * The returned `Browser` is closed automatically at the end of the + * iteration. Use {@link ConnectedBrowser.close | close} to release the + * connection earlier. + * + * **Usage** + * + * ```js + * const browser = await chromium.connectOverCDP('ws://localhost:9222/devtools/browser/'); + * const page = await browser.newPage(); + * + * try { + * await page.goto('https://quickpizza.grafana.com/'); + * } finally { + * await page.close(); + * await browser.close(); + * } + * ``` + * + * @param wsEndpoint The WebSocket endpoint of the browser to attach to, + * e.g. 'ws://localhost:9222/devtools/browser/'. + */ + connectOverCDP(wsEndpoint: string): Promise; +} + +/** + * `ConnectedBrowser` represents a web browser instance that k6 attached to over + * the Chrome DevTools Protocol (CDP), rather than launched itself. + * + * On top of the `Browser` API, it exposes a `close` method, since the + * connection is user managed and can be released on demand. + */ +export interface ConnectedBrowser extends Browser { + /** + * Closes the connection to the browser, and all of its `BrowserContext`s + * and `Page`s. + * + * Calling this method is optional: the connection is closed automatically + * at the end of the iteration. Closing an already closed `Browser` is a + * no-op. + */ + close(): Promise; +} + /** * `Browser` represents the main web browser instance. */ diff --git a/types/k6/options/index.d.ts b/types/k6/options/index.d.ts index 9140884a18d375..14fb688b9824d9 100644 --- a/types/k6/options/index.d.ts +++ b/types/k6/options/index.d.ts @@ -50,6 +50,9 @@ export interface Options { /** Cloud options */ cloud?: CloudOptions; + /** handleSummary() function timeout. */ + handleSummaryTimeout?: string; + /** Static hostname mapping. */ hosts?: { [name: string]: string }; diff --git a/types/k6/package.json b/types/k6/package.json index 62bd62097ffb25..1b05e70837a0c5 100644 --- a/types/k6/package.json +++ b/types/k6/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@types/k6", - "version": "2.0.9999", + "version": "2.2.9999", "type": "module", "projects": [ "https://grafana.com/docs/k6/latest/" @@ -61,6 +61,10 @@ { "name": "Iván Szkiba", "githubUsername": "szkiba" + }, + { + "name": "Jan Hildebrandt", + "githubUsername": "janHildebrandt98" } ] } diff --git a/types/k6/test/browser.ts b/types/k6/test/browser.ts index 820d1b108bde80..fcf2055b40f512 100644 --- a/types/k6/test/browser.ts +++ b/types/k6/test/browser.ts @@ -1,4 +1,4 @@ -import { browser, devices } from "k6/browser"; +import { browser, chromium, devices } from "k6/browser"; const url = "http://example.com"; const selector = "a[href=\"http://example.com\"]"; @@ -121,6 +121,30 @@ async function test() { // $ExpectType string browser.version(); + // + // Connect to an existing browser over CDP + // + // @ts-expect-error + chromium.connectOverCDP(); + // $ExpectType Promise + chromium.connectOverCDP("ws://localhost:9222/devtools/browser/1234"); + + const connectedBrowser = await chromium.connectOverCDP("ws://localhost:9222/devtools/browser/1234"); + + // $ExpectType Promise + connectedBrowser.close(); + // $ExpectType Promise + connectedBrowser.newPage(); + // $ExpectType Promise + connectedBrowser.newContext({ viewport: { width: 1280, height: 720 } }); + // $ExpectType boolean + connectedBrowser.isConnected(); + // $ExpectType string + connectedBrowser.version(); + + // @ts-expect-error + browser.close(); + // // Create a browserContext //