Skip to content
This repository was archived by the owner on Nov 24, 2018. It is now read-only.

feat: add support to ignore certificate errors #464

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Chromeless provides TypeScript typings.
- `viewport: any` Viewport dimensions — Default: `{width: 1440, height: 900, scale: 1}`
- `launchChrome: boolean` Auto-launch chrome (local) — Default: `true`
- `cdp: CDPOptions` Chome Debugging Protocol Options — Default: `{host: 'localhost', port: 9222, secure: false, closeTab: true}`
- `ignoreCertErrors: boolean` ignore certificate errors — Default: `false`

### Chromeless methods
- [`end()`](#api-end)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"aws-sdk": "^2.177.0",
"bluebird": "^3.5.1",
"chrome-launcher": "^0.10.0",
"chrome-remote-interface": "^0.25.5",
"chrome-remote-interface": "^0.25.7",
"cuid": "^2.1.0",
"form-data": "^2.3.1",
"got": "^8.0.0",
Expand Down
6 changes: 4 additions & 2 deletions src/chrome/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Chrome, Command, ChromelessOptions, Client } from '../types'
import * as CDP from 'chrome-remote-interface'
import { LaunchedChrome, launch } from 'chrome-launcher'
import LocalRuntime from './local-runtime'
import { evaluate, setViewport } from '../util'
import { evaluate, setViewport, ignoreCertErrors } from '../util'
import { DeviceMetrics } from '../types'

interface RuntimeClient {
Expand All @@ -25,7 +25,9 @@ export default class LocalChrome implements Chrome {
const client = this.options.launchChrome
? await this.startChrome()
: await this.connectToChrome()

if (this.options.ignoreCertErrors) {
ignoreCertErrors(client)
}
const { viewport = {} as DeviceMetrics } = this.options
await setViewport(client, viewport as DeviceMetrics)

Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface Client {
Runtime: any
Emulation: any
Storage: any
Security: any
close: () => void
target: {
id: string
Expand Down Expand Up @@ -51,12 +52,14 @@ export interface ChromelessOptions {
scale?: number // 1
}
launchChrome?: boolean // auto-launch chrome (local) `true`
ignoreCertErrors?: boolean
cdp?: CDPOptions
remote?: RemoteOptions | boolean
}

export interface Chrome {
process<T extends any>(command: Command): Promise<T>

close(): Promise<void>
}

Expand Down
6 changes: 6 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ export async function focus(client: Client, selector: string): Promise<void> {
await DOM.focus(node)
}

export async function ignoreCertErrors(client: Client): Promise<void> {
const { Security } = client
await Security.enable()
await Security.setIgnoreCertificateErrors({ ignore: true })
}

export async function evaluate<T>(
client: Client,
fn: string,
Expand Down