Refs #482: casper.viewport should wait after repaint
Since setting the viewport forces a redraw of the rendering, in an asynchronous manner, it should wait a bit of time. At least SlimerJS needs this delay to redraw its window.
Showing
1 changed file
with
12 additions
and
2 deletions
... | @@ -1892,12 +1892,22 @@ Casper.prototype.viewport = function viewport(width, height, then) { | ... | @@ -1892,12 +1892,22 @@ Casper.prototype.viewport = function viewport(width, height, then) { |
1892 | if (!utils.isNumber(width) || !utils.isNumber(height) || width <= 0 || height <= 0) { | 1892 | if (!utils.isNumber(width) || !utils.isNumber(height) || width <= 0 || height <= 0) { |
1893 | throw new CasperError(f("Invalid viewport: %dx%d", width, height)); | 1893 | throw new CasperError(f("Invalid viewport: %dx%d", width, height)); |
1894 | } | 1894 | } |
1895 | |||
1895 | this.page.viewportSize = { | 1896 | this.page.viewportSize = { |
1896 | width: width, | 1897 | width: width, |
1897 | height: height | 1898 | height: height |
1898 | }; | 1899 | }; |
1899 | this.emit('viewport.changed', [width, height]); | 1900 | |
1900 | return utils.isFunction(then) ? this.then(then) : this; | 1901 | return this.then(function _step() { |
1902 | this.waitStart(); | ||
1903 | setTimeout(function _check(self) { | ||
1904 | self.waitDone(); | ||
1905 | self.emit('viewport.changed', [width, height]); | ||
1906 | if (utils.isFunction(then)){ | ||
1907 | self.then(then); | ||
1908 | } | ||
1909 | }, 300, this); | ||
1910 | }); | ||
1901 | }; | 1911 | }; |
1902 | 1912 | ||
1903 | /** | 1913 | /** | ... | ... |
-
Please register or sign in to post a comment