diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser.md index dafd25ef6c..177163ddae 100644 --- a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser.md +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser.md @@ -5,45 +5,32 @@ excerpt: "xk6-browser: Browser Class" +A Browser is created via [browserType.launch([options])](/javascript-api/xk6-browser/browsertype/#browsertype-launch-options). + +| Method | Description | +| ------------------------------------------------------------------------------------------------------ | ------------------------------------------ | +| [browser.close()](/javascript-api/xk6-browser/browser/browser-close) | | +| [browser.contexts()](/javascript-api/xk6-browser/browser/browser-contexts) | | +| [browser.isConnected](/javascript-api/xk6-browser/browser/browser-isconnected) | | +| 🚧 [browser.newBrowserCDPSession()](/javascript-api/xk6-browser/browser/browser-newbrowsercdpsession) | | +| [browser.newContext([options])](/javascript-api/xk6-browser/browser/browser-newcontext/) | Creates and returns a new browser context. | +| [browser.newPage([options])](/javascript-api/xk6-browser/browser/browser-newpage) | | +| 🚧 [browser.on('disconnected')](/javascript-api/xk6-browser/browser/browser-on) | | +| ❌ [browser.startTracing()](/javascript-api/xk6-browser/browser/browser-starttracing) | | +| ❌ [browser.stopTracing()](/javascript-api/xk6-browser/browser/browser-stoptracing) | | +| [browser.version()](/javascript-api/xk6-browser/browser/browser-version) | | + +An example of using a Browser to create a [Page](/javascript-api/xk6-browser/page): + ```javascript import launcher from 'k6/x/browser'; + export default function () { const browser = launcher.launch('chromium'); const context = browser.newContext(); const page = context.newPage(); + const res = page.goto('https://test.k6.io/'); page.close(); browser.close(); } ``` - -- [browser.close()](#browser-close) -- [browser.contexts()](#browser-contexts) -- [browser.isConnected()](#browser-isconnected) -- 🚧 [browser.newBrowserCDPSession()](#browser-newbrowsercdpsession) -- [browser.newContext([options])](#browser-newcontext-options) -- [browser.newPage([options])](#browser-newpage-options) -- 🚧 [browser.on()](#browser-on) -- ❌ [browser.startTracing()](#browser-starttracing) -- ❌ [browser.stopTracing()](#browser-stoptracing) -- [browser.version()](#browser-version) - - -## browser.close() - -## browser.contexts() - -## browser.isConnected() - -## browser.newBrowserCDPSession() - -## browser.newContext([options]) - -## browser.newPage([options]) - -## browser.on() - -## browser.startTracing() - -## browser.stopTracing() - -## browser.version() diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/01-browser-close.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/01-browser-close.md new file mode 100644 index 0000000000..85fbeacca2 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/01-browser-close.md @@ -0,0 +1,10 @@ +--- +title: 'Browser.close()' +excerpt: 'xk6-browser: Browser.close method' +--- + + + +Closes the browser and all of its pages (if any were opened). + +The Browser object itself is considered to be disposed and cannot be used anymore. diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/02-browser-contexts.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/02-browser-contexts.md new file mode 100644 index 0000000000..cdee4d7c8f --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/02-browser-contexts.md @@ -0,0 +1,24 @@ +--- +title: 'Browser.contexts()' +excerpt: 'xk6-browser: Browser.contexts method' +--- + + + +Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts. + +### Returns + +| Type | Description | +| ----- | ------------------------------------------------------------------------------ | +| Array | Array of [BrowserContext](/javascript-api/xk6-browser/browsercontext/) objects | + + + +```javascript +const browser = launcher.launch('chromium'); +console.log(browser.contexts().length); // prints `0` + +const context = browser.newContext(); +console.log(browser.contexts().length); // prints `1` +``` diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/03-browser-isconnected.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/03-browser-isconnected.md new file mode 100644 index 0000000000..fb477695d8 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/03-browser-isconnected.md @@ -0,0 +1,14 @@ +--- +title: 'Browser.isConnected()' +excerpt: 'xk6-browser: Browser.isConnected method' +--- + + + +Indicates whether the WebSocket connection to the browser application is active or not. + +### Returns + +| Type | Description | +| ------- | ---------------------------------------------------------------------------------------------- | +| boolean | Returns `true` if Browser is connected to the browser application. Otherwise, returns `false`. | diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/04-browser-newbrowsercdpsession.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/04-browser-newbrowsercdpsession.md new file mode 100644 index 0000000000..1264c55b02 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/04-browser-newbrowsercdpsession.md @@ -0,0 +1,8 @@ +--- +title: 'Browser.newBrowserCDPSession()' +excerpt: 'xk6-browser: Browser.newBrowserCDPSession method' +--- + + + +TODO \ No newline at end of file diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/05-browser-newcontext-options.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/05-browser-newcontext-options.md new file mode 100644 index 0000000000..d5c4121253 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/05-browser-newcontext-options.md @@ -0,0 +1,88 @@ +--- +title: 'Browser.newContext([options])' +excerpt: 'xk6-browser: Browser.newContext method' +--- + + + +Creates a new browser context. + +| Parameter | Type | Description | +| --------- | ------ | ----------------------------------------- | +| options | object | See [options](#options) for more details. | + +### Returns + +| Type | Description | +| ------ | -------------------------------------------------------------------- | +| object | [BrowserContext](/javascript-api/xk6-browser/browsercontext/) object | + +### options + +You can customize the creation of a new browser context using the following options. + + + +| Option | Type | Description | +| ------------------------------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| acceptDownloads | boolean | Whether to automatically download files. Defaults to `true`. | +| baseURL | string | The base URL to use for all relative URLs. For example: `/open-source/` will be converted to `https://k6.io/open-source/` if `baseURL` is set to `https://k6.io`. | +| bypassCSP | boolean | Whether to bypass a page's Content-Security-Policy. | +| colorScheme | string | Whether to display a page in dark or light mode by emulating the 'prefers-colors-scheme' media feature. It can be one of `'light'`, `'dark'`, `'no-preference'`. See [page.emulateMedia](/javascript-api/xk6-browser/page#page-emulatemedia-options) for the options and the [example](https://github.com/grafana/xk6-browser/blob/main/examples/colorscheme.js). Defaults to `'light'`. | +| deviceScaleFactor | number | Sets the resolution ratio in physical pixels to the resolution in CSS pixels. See the [link](https://github.com/grafana/xk6-browser/blob/main/examples/device_emulation.js) as an example. Defaults to `1`. | +| extraHTTPHeaders | object | Contains additional HTTP headers to be sent with every request, where the keys are HTTP headers and values are HTTP header values. | +| forcedColors | string | Enforces a limited color palette on the page by emulating `forced-colors` media feature. It can be one of `'active'` or `'none'`. Defaults to `'none'`. | +| geolocation | object | Sets the user's geographical location. See [geolocation](#geolocation-options) for the options. | +| hasTouch | boolean | Whether to simulate a device with touch events. Defaults to `false`. | +| httpCredentials | object | Sets the credentials for HTTP authentication. See: [httpCredentials](#httpcredentials-options). | +| ignoreHTTPSErrors | boolean | Whether to ignore HTTPS errors that may be caused by invalid certificates. Defaults to `false`. | +| isMobile | boolean | Whether to simulate a mobile device. Defaults to `false`. | +| javaScriptEnabled | boolean | Whether to activate JavaScript support for the context. Defaults to `true`. | +| locale | string | Specifies the user's locale, such as `en-US`, `tr-TR`, etc. | +| logger | object | Specifies the logger to use in xk6-browser. | +| offline | boolean | Whether to emulate an offline network. Defaults to `false`. | +| permissions | Array | Permissions to grant for the context's pages. See [browserContext.grantPermissions()](/javascript-api/xk6-browser/browsercontext#browsercontext-grantpermissions-permissions-options) for the options. | +| proxy | object | Sets the network proxy settings for the context. | +| recordHar | object | Activates HAR recording for the context's pages. | +| [❌](https://github.com/grafana/xk6-browser/issues/103) recordVideo | object | Activates video recording for the context's pages. | +| reducedMotion | string | Minimizes the amount of motion by emulating the 'prefers-reduced-motion' media feature. It can be one of `'reduce'` and `'no-preference'`. See [page.emulateMedia()](/javascript-api/xk6-browser/page#page-emulatemedia-options) for the options. Defaults to `'no-preference'`. | +| screen | object | Sets a window screen size for all pages in the context. It can only be used when the viewport is set. See: [screen](#screen-options) for the options. | +| strictSelectors | bool | Whether to activate the strict selectors mode. | +| timezoneID | string | Changes the context's timezone. See [ICU's metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1) for a list of supported timezone IDs. | +| userAgent | string | Specifies the user agent to use in the context. | +| viewport | object | Sets a viewport size for all pages in the context. `null` disables the default viewport. See: [viewport](#viewport-options) for the options. Defaults to `1280x720`. | + + + +### geolocation options + +| Option | Type | Description | +| --------- | ------ | ------------------------------------------------------ | +| latitude | number | Latitude should be between `-90` and `90`. | +| longitude | number | Longitude should be between `-180` and `180`. | +| accuracy | number | Accuracy should be a positive number. Defaults to `0`. | + +### httpCredentials options + +| Option | Type | Description | +| -------- | ------ | ------------------------------------------------------------------ | +| username | string | Username to pass to the web browser for Basic HTTP Authentication. | +| password | string | Password to pass to the web browser for Basic HTTP Authentication. | + +### screen options + +| Option | Type | Description | +| ------ | ------ | ---------------------- | +| width | number | Page width in pixels. | +| height | number | Page height in pixels. | + + + +### viewport options + + + +| Option | Type | Description | +| ------ | ------ | ---------------------- | +| width | number | Page width in pixels. | +| height | number | Page height in pixels. | diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/06-browser-newpage.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/06-browser-newpage.md new file mode 100644 index 0000000000..947fa03049 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/06-browser-newpage.md @@ -0,0 +1,26 @@ +--- +title: 'Browser.newPage([options])' +excerpt: 'xk6-browser: Browser.newPage method' +--- + + + +| Parameter | Type | Description | +| --------- | ------ | ------------------------------------------------- | +| options | object | See [options](#options) for more details. | + +### Returns + +| Type | Description | +| ------ | ------------------------------------------------ | +| object | [Page](/javascript-api/xk6-browser/page/) object | + +You can customize the creation of a new page using the following options. + +### options + +| Option | Type | Description | +| --------------- | ------- | ------------------------------------------------------------------------------------------------------------- | +| acceptDownloads | boolean | Whether to automatically download all the attachments. Defaults to true where all the downloads are accepted. | + +TODO diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/07-browser-on.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/07-browser-on.md new file mode 100644 index 0000000000..ec7d00fe21 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/07-browser-on.md @@ -0,0 +1,21 @@ +--- +title: 'Browser.on()' +excerpt: 'xk6-browser: Browser.on method' +--- + + + +Emitted when Browser gets disconnected from the browser application. This might happen because of one of the following: + +* Browser application is closed or crashed. +* The [browser.close()](#browser-close) method was called. + +| Parameter | Type | Description | +| --------- | ------ | -------------------------------------------------- | +| event | string | The only accepted event value is `'disconnected'`. | + +### Returns + +| Type | Description | +| ------- | ------------------------------------------------------------------------------- | +| promise | On returns a Promise that is resolved when the browser process is disconnected. | diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/08-browser-starttracing.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/08-browser-starttracing.md new file mode 100644 index 0000000000..04ea7c2ad7 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/08-browser-starttracing.md @@ -0,0 +1,8 @@ +--- +title: 'Browser.startTracing()' +excerpt: 'xk6-browser: Browser.startTracing method' +--- + + + +TODO \ No newline at end of file diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/09-browser-stoptracing.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/09-browser-stoptracing.md new file mode 100644 index 0000000000..60768de432 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/09-browser-stoptracing.md @@ -0,0 +1,8 @@ +--- +title: 'Browser.stopTracing()' +excerpt: 'xk6-browser: Browser.stopTracing method' +--- + + + +TODO diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/10-browser-version.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/10-browser-version.md new file mode 100644 index 0000000000..126237cd30 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser/10-browser-version.md @@ -0,0 +1,14 @@ +--- +title: 'Browser.version()' +excerpt: 'xk6-browser: Browser.version method' +--- + + + +TODO + +### Returns + +| Type | Description | +| ------ | ------------------------------------------ | +| string | Returns the browser application's version. |