Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,24 @@ playwright: {
}
```

### Browser Context Options

Example:

```javascript
playwright: {
ignoreHTTPSErrors: true,
bypassCSP: true,
userAgent: 'Mozilla/5.0 (Explorbot)',
locale: 'en-GB',
colorScheme: 'dark',
basicAuth: { username: 'user', password: 'pass' },
emulate: { ...devices['iPhone 13'] },
}
```

The browser session (cookies, localStorage) is restored automatically when you launch with `--session` — see [`commands.md`](./commands.md#--session).

## Directory Structure

Default directory layout:
Expand Down
13 changes: 12 additions & 1 deletion src/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createTest } from 'codeceptjs/lib/mocha/test';
import { ActionResult } from './action-result.ts';
import Action from './action.js';
import { AIProvider } from './ai/provider.js';
import type { BrowserContextOptions } from 'playwright';
import { visuallyAnnotateContainers } from './ai/researcher/coordinates.ts';
import { RequestStore } from './api/request-store.ts';
import { XhrCapture } from './api/xhr-capture.ts';
Expand Down Expand Up @@ -235,7 +236,17 @@ class Explorer {
}
await this.connectOrLaunchBrowser();
const hasSession = this.options?.session && existsSync(this.options.session);
const contextOptions = hasSession ? { storageState: this.options!.session } : undefined;
const helperOptions = this.playwrightHelper.options || {};
// CodeceptJS skips _createContextPage when sessions/storageState are involved, so we
// build contextOptions ourselves. Most keys share a name with Playwright's
// BrowserContextOptions and are copied as-is; `emulate` must be flattened, `basicAuth`
// renamed to `httpCredentials`, and `storageState` comes from the --session flag.
const contextOptions: BrowserContextOptions = {
...helperOptions,
};
if (helperOptions.emulate) Object.assign(contextOptions, helperOptions.emulate);
if (helperOptions.basicAuth) contextOptions.httpCredentials = helperOptions.basicAuth;
if (hasSession) contextOptions.storageState = this.options!.session;
await this.playwrightHelper._createContextPage(contextOptions);
this.setupXhrCapture();
if (hasSession) {
Expand Down
Loading