Merge pull request #204 from chiefcll/fix-url-change-via-javascript
Fix for when the url is changed via javascript
Showing
1 changed file
with
7 additions
and
1 deletions
... | @@ -117,6 +117,7 @@ var Casper = function Casper(options) { | ... | @@ -117,6 +117,7 @@ var Casper = function Casper(options) { |
117 | this.defaultWaitTimeout = 5000; | 117 | this.defaultWaitTimeout = 5000; |
118 | this.history = []; | 118 | this.history = []; |
119 | this.loadInProgress = false; | 119 | this.loadInProgress = false; |
120 | this.navigationRequested = false; | ||
120 | this.logFormats = {}; | 121 | this.logFormats = {}; |
121 | this.logLevels = ["debug", "info", "warning", "error"]; | 122 | this.logLevels = ["debug", "info", "warning", "error"]; |
122 | this.logStyles = { | 123 | this.logStyles = { |
... | @@ -316,7 +317,7 @@ Casper.prototype.captureSelector = function captureSelector(targetFile, selector | ... | @@ -316,7 +317,7 @@ Casper.prototype.captureSelector = function captureSelector(targetFile, selector |
316 | */ | 317 | */ |
317 | Casper.prototype.checkStep = function checkStep(self, onComplete) { | 318 | Casper.prototype.checkStep = function checkStep(self, onComplete) { |
318 | "use strict"; | 319 | "use strict"; |
319 | if (self.pendingWait || self.loadInProgress) { | 320 | if (self.pendingWait || self.loadInProgress || self.navigationRequested) { |
320 | return; | 321 | return; |
321 | } | 322 | } |
322 | var step = self.steps[self.step++]; | 323 | var step = self.steps[self.step++]; |
... | @@ -1639,6 +1640,7 @@ function createPage(casper) { | ... | @@ -1639,6 +1640,7 @@ function createPage(casper) { |
1639 | } | 1640 | } |
1640 | message += ': ' + casper.requestUrl; | 1641 | message += ': ' + casper.requestUrl; |
1641 | casper.log(message, "warning"); | 1642 | casper.log(message, "warning"); |
1643 | casper.navigationRequested = false; | ||
1642 | if (utils.isFunction(casper.options.onLoadError)) { | 1644 | if (utils.isFunction(casper.options.onLoadError)) { |
1643 | casper.options.onLoadError.call(casper, casper, casper.requestUrl, status); | 1645 | casper.options.onLoadError.call(casper, casper, casper.requestUrl, status); |
1644 | } | 1646 | } |
... | @@ -1668,6 +1670,9 @@ function createPage(casper) { | ... | @@ -1668,6 +1670,9 @@ function createPage(casper) { |
1668 | page.onNavigationRequested = function onNavigationRequested(url, navigationType, navigationLocked, isMainFrame) { | 1670 | page.onNavigationRequested = function onNavigationRequested(url, navigationType, navigationLocked, isMainFrame) { |
1669 | casper.log(f('Navigation requested: url=%s, type=%s, lock=%s, isMainFrame=%s', | 1671 | casper.log(f('Navigation requested: url=%s, type=%s, lock=%s, isMainFrame=%s', |
1670 | url, navigationType, navigationLocked, isMainFrame), "debug"); | 1672 | url, navigationType, navigationLocked, isMainFrame), "debug"); |
1673 | if(isMainFrame) { | ||
1674 | casper.navigationRequested = true; | ||
1675 | } | ||
1671 | casper.emit('navigation.requested', url, navigationType, navigationLocked, isMainFrame); | 1676 | casper.emit('navigation.requested', url, navigationType, navigationLocked, isMainFrame); |
1672 | }; | 1677 | }; |
1673 | page.onPrompt = function onPrompt(message, value) { | 1678 | page.onPrompt = function onPrompt(message, value) { |
... | @@ -1702,6 +1707,7 @@ function createPage(casper) { | ... | @@ -1702,6 +1707,7 @@ function createPage(casper) { |
1702 | }; | 1707 | }; |
1703 | page.onUrlChanged = function onUrlChanged(url) { | 1708 | page.onUrlChanged = function onUrlChanged(url) { |
1704 | casper.log(f('url changed to "%s"', url), "debug"); | 1709 | casper.log(f('url changed to "%s"', url), "debug"); |
1710 | casper.navigationRequested = false; | ||
1705 | casper.emit('url.changed', url); | 1711 | casper.emit('url.changed', url); |
1706 | }; | 1712 | }; |
1707 | casper.emit('page.created', page); | 1713 | casper.emit('page.created', page); | ... | ... |
-
Please register or sign in to post a comment