# newWindow

Open a new window or tab and wait until its page has loaded, the equivalent of `window.open()`. This command does not work in mobile environments.

In a WebDriver BiDi session (the default since v10) it returns the new [browsing context](/docs/api/browsingContext.md) and does not switch to it: run commands on the returned context, while `browser.url()` keeps navigating the first one. In a WebDriver Classic session the command switches to the new window and returns `{ handle, type }`.

## Usage[​](#usage "Direct link to Usage")

```
await browser.newWindow(url, { type, referenceContext })
```

## Parameters[​](#parameters "Direct link to Parameters")

| Name                                       | Type                      | Details                                                                                                                            |
| ------------------------------------------ | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `url`                                      | `string`                  | website URL to open                                                                                                                |
| `options`<br />*optional*                  | `NewWindowOptions`        | newWindow command options                                                                                                          |
| `options.type`<br />*optional*             | `string`                  | type of new window: 'tab' or 'window'                                                                                              |
| `options.referenceContext`<br />*optional* | `string, BrowsingContext` | top-level browsing context to open the new tab or window from (BiDi only). In parallel mode, the default is the window of the test |

## Example[​](#example "Direct link to Example")

newWindow\.js

```
it('should open a new tab', async () => {

    const page = await browser.url('https://webdriver.io')

    const tab = await browser.newWindow('https://webdriver.io/docs/api', { type: 'tab' })



    console.log(await tab.getTitle()) // the title of the API page

    console.log(await page.getTitle()) // the first tab still answers commands

    await tab.closeWindow()

});
```

## Returns[​](#returns "Direct link to Returns")

* **\<BrowsingContext|Object>** **`return`:** In a BiDi session, the new browsing context. In a Classic session, `{handle, type}`.

## Throws[​](#throws "Direct link to Throws")

* **Error**: If `url` is invalid, if the command is used on mobile, or `type` is not 'tab' or 'window'.
