added an event as a Casper option
Showing
1 changed file
with
20 additions
and
14 deletions
... | @@ -26,12 +26,15 @@ | ... | @@ -26,12 +26,15 @@ |
26 | /** | 26 | /** |
27 | * Main Casper class. Available options are: | 27 | * Main Casper class. Available options are: |
28 | * | 28 | * |
29 | * Type Name Default Description | 29 | * Name | Type | Default | Description |
30 | * - Array clientScripts ([]): A collection of script filepaths to include to every page loaded | 30 | * ——————————————————+——————————+—————————+———————————————————————————————————————————————————————————————————— |
31 | * - String logLevel ("error") Logging level (see logLevels for available values) | 31 | * clientScripts | Array | [] | A collection of script filepaths to include to every page loaded |
32 | * - Object pageSettings ({}): PhantomJS's WebPage settings object | 32 | * logLevel | String | "error" | Logging level (see logLevels for available values) |
33 | * - WebPage page (null): An existing WebPage instance | 33 | * onDie | function | null | A function to be called when Casper#die() is called |
34 | * - Boolean verbose (false): Realtime output of log messages | 34 | * onPageInitialized | function | null | A function to be called after WebPage instance has been initialized |
35 | * page | WebPage | null | An existing WebPage instance | ||
36 | * pageSettings | Object | {} | PhantomJS's WebPage settings object | ||
37 | * verbose | Boolean | false | Realtime output of log messages | ||
35 | * | 38 | * |
36 | * @param Object options Casper options | 39 | * @param Object options Casper options |
37 | * @return Casper | 40 | * @return Casper |
... | @@ -45,14 +48,13 @@ | ... | @@ -45,14 +48,13 @@ |
45 | } | 48 | } |
46 | // default options | 49 | // default options |
47 | this.defaults = { | 50 | this.defaults = { |
48 | clientScripts: [], | 51 | clientScripts: [], |
49 | logLevel: "error", | 52 | logLevel: "error", |
50 | onDie: null, | 53 | onDie: null, |
51 | page: null, | 54 | onPageInitialized: null, |
52 | pageSettings: { | 55 | page: null, |
53 | userAgent: DEFAULT_USER_AGENT, | 56 | pageSettings: { userAgent: DEFAULT_USER_AGENT }, |
54 | }, | 57 | verbose: false |
55 | verbose: false | ||
56 | }; | 58 | }; |
57 | // local properties | 59 | // local properties |
58 | this.checker = null; | 60 | this.checker = null; |
... | @@ -398,6 +400,10 @@ | ... | @@ -398,6 +400,10 @@ |
398 | } | 400 | } |
399 | this.page.settings = mergeObjects(this.page.settings, this.options.pageSettings); | 401 | this.page.settings = mergeObjects(this.page.settings, this.options.pageSettings); |
400 | this.started = true; | 402 | this.started = true; |
403 | if (typeof(this.options.onPageInitialized) === "function") { | ||
404 | this.log("Post-configuring WebPage instance", "debug"); | ||
405 | this.options.onPageInitialized(this.page); | ||
406 | } | ||
401 | if (typeof(location) === "string" && location.length > 0) { | 407 | if (typeof(location) === "string" && location.length > 0) { |
402 | if (typeof(then) === "function") { | 408 | if (typeof(then) === "function") { |
403 | return this.open(location).then(then); | 409 | return this.open(location).then(then); | ... | ... |
-
Please register or sign in to post a comment