This repository was archived by the owner on Nov 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 576
chrome-launcher + spelling fixes + docs #120
Merged
joelgriffith
merged 4 commits into
schickling:master
from
joelgriffith:feature/chrome-launcher
Aug 1, 2017
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
07d8bc6
chrome-launcher + spelling fixes + docs
joelgriffith 51015a6
PR feedback and run.ts fixes
joelgriffith ae44e01
Merge remote-tracking branch 'upstream/master' into feature/chrome-la…
joelgriffith 3e2087b
Merge remote-tracking branch 'upstream/master' into feature/chrome-la…
joelgriffith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
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 } from '../util' | ||
|
||
|
@@ -11,16 +12,31 @@ interface RuntimeClient { | |
export default class LocalChrome implements Chrome { | ||
private options: ChromelessOptions | ||
private runtimeClientPromise: Promise<RuntimeClient> | ||
private chromeInstance?: LaunchedChrome | ||
|
||
constructor(options: ChromelessOptions = {}) { | ||
this.options = options | ||
|
||
this.runtimeClientPromise = this.initRuntimeClient() | ||
} | ||
|
||
private async initRuntimeClient(): Promise<RuntimeClient> { | ||
private async startChrome(): Promise<Client> { | ||
this.chromeInstance = await launch({ | ||
logLevel: this.options.debug ? 'info' : 'silent', | ||
port: this.options.cdp.port | ||
}) | ||
return await CDP({ port: this.chromeInstance.port }) | ||
} | ||
|
||
private async connectToChrome(): Promise<Client> { | ||
const target = await CDP.New() | ||
const client = await CDP({ target }) | ||
return await CDP({ target }) | ||
} | ||
|
||
private async initRuntimeClient(): Promise<RuntimeClient> { | ||
const client = this.options.launchChrome ? | ||
await this.startChrome() : | ||
await this.connectToChrome() | ||
|
||
await this.setViewport(client) | ||
|
||
|
@@ -39,7 +55,7 @@ export default class LocalChrome implements Chrome { | |
fitWindow: false, // as we cannot resize the window, `fitWindow: false` is needed in order for the viewport to be resizable | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a bug waiting for us 😄 |
||
const versionResult = await CDP.Version() | ||
const versionResult = await CDP.Version({ port: this.chromeInstance.port }) | ||
const isHeadless = versionResult['User-Agent'].includes('Headless') | ||
|
||
if (viewport.height && viewport.width) { | ||
|
@@ -80,6 +96,10 @@ export default class LocalChrome implements Chrome { | |
CDP.Close({ id: client.target.id }) | ||
} | ||
|
||
if (this.chromeInstance) { | ||
this.chromeInstance.kill() | ||
} | ||
|
||
await client.close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ export async function wait(timeout: number): Promise<void> { | |
export async function nodeExists(client: Client, selector: string): Promise<boolean> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small change here for brevity (also it didn't work?) |
||
const {Runtime} = client | ||
const exists = (selector) => { | ||
return document.querySelector(selector) | ||
return !!document.querySelector(selector) | ||
} | ||
|
||
const expression = `(${exists})(\`${selector}\`)` | ||
|
@@ -62,9 +62,7 @@ export async function nodeExists(client: Client, selector: string): Promise<bool | |
expression, | ||
}) | ||
|
||
// counter intuitive: if it is a real object and not just null, | ||
// the chrome debugger won't return a value but return a objectId | ||
return typeof result.result.value === 'undefined' | ||
return result.result.value | ||
} | ||
|
||
export async function getClientRect(client, selector): Promise<ClientRect> { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,10 +48,22 @@ | |
version "3.5.8" | ||
resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.8.tgz#242a83379f06c90f96acf6d1aeab3af6faebdb98" | ||
|
||
"@types/core-js@^0.9.41": | ||
version "0.9.42" | ||
resolved "https://npm.corp.appnexus.com/@types%2fcore-js/-/core-js-0.9.42.tgz#dd6da92cd7d5ab5ca0b4477524537c3e633b6bce" | ||
|
||
"@types/cuid@^1.3.0": | ||
version "1.3.0" | ||
resolved "https://registry.yarnpkg.com/@types/cuid/-/cuid-1.3.0.tgz#20b0e00ca555df564866bc52d2e251bf90c88db7" | ||
|
||
"@types/mkdirp@^0.3.29": | ||
version "0.3.29" | ||
resolved "https://npm.corp.appnexus.com/@types%2fmkdirp/-/mkdirp-0.3.29.tgz#7f2ad7ec55f914482fc9b1ec4bb1ae6028d46066" | ||
|
||
"@types/[email protected]": | ||
version "6.0.66" | ||
resolved "https://npm.corp.appnexus.com/@types%2fnode/-/node-6.0.66.tgz#5680b74a6135d33d4c00447e7c3dc691a4601625" | ||
|
||
"@types/node@^8.0.15": | ||
version "8.0.16" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.16.tgz#5aa51abd72621a0ce53fb86bccd76825ee1b4ca9" | ||
|
@@ -774,6 +786,17 @@ chokidar@^1.4.2: | |
optionalDependencies: | ||
fsevents "^1.0.0" | ||
|
||
chrome-launcher@^0.3.2: | ||
version "0.3.2" | ||
resolved "https://npm.corp.appnexus.com/chrome-launcher/-/chrome-launcher-0.3.2.tgz#c3a89e40ed2462899bac809417c4d7c451d5de05" | ||
dependencies: | ||
"@types/core-js" "^0.9.41" | ||
"@types/mkdirp" "^0.3.29" | ||
"@types/node" "6.0.66" | ||
lighthouse-logger "^1.0.0" | ||
mkdirp "0.5.1" | ||
rimraf "^2.6.1" | ||
|
||
chrome-remote-interface@^0.24.2: | ||
version "0.24.2" | ||
resolved "https://registry.yarnpkg.com/chrome-remote-interface/-/chrome-remote-interface-0.24.2.tgz#43a05440a1fa60b73769e72f3e7892ac11d66eba" | ||
|
@@ -1005,7 +1028,7 @@ date-time@^2.1.0: | |
dependencies: | ||
time-zone "^1.0.0" | ||
|
||
debug@^2.1.1, debug@^2.2.0: | ||
debug@^2.1.1, debug@^2.2.0, debug@^2.6.8: | ||
version "2.6.8" | ||
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc" | ||
dependencies: | ||
|
@@ -1886,6 +1909,12 @@ leven@^1.0.0: | |
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/leven/-/leven-1.0.2.tgz#9144b6eebca5f1d0680169f1a6770dcea60b75c3" | ||
|
||
lighthouse-logger@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://npm.corp.appnexus.com/lighthouse-logger/-/lighthouse-logger-1.0.0.tgz#c6abdfbbbf0b4a541ab33864802cbad8944bcc8c" | ||
dependencies: | ||
debug "^2.6.8" | ||
|
||
load-json-file@^1.0.0: | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-1.1.0.tgz#956905708d58b4bab4c2261b04f59f31c99374c0" | ||
|
@@ -2069,7 +2098,7 @@ minimist@^1.1.0, minimist@^1.1.3, minimist@^1.2.0: | |
version "1.2.0" | ||
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" | ||
|
||
"mkdirp@>=0.5 0", mkdirp@^0.5.1: | ||
[email protected], "mkdirp@>=0.5 0", mkdirp@^0.5.1: | ||
version "0.5.1" | ||
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" | ||
dependencies: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are mostly spelling fixes