Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
92f5aebf
...
92f5aebf92d357ed10aa4aa08b497abd595fe700
authored
2011-12-25 22:16:17 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
backport fixes of master
1 parent
ae57bcf3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
12 deletions
modules/casper.js
samples/screenshot.js
modules/casper.js
View file @
92f5aeb
...
...
@@ -149,6 +149,7 @@ Casper.prototype = {
*/
capture
:
function
(
targetFile
,
clipRect
)
{
var
previousClipRect
;
targetFile
=
require
(
'fs'
).
absolute
(
targetFile
);
if
(
clipRect
)
{
if
(
!
utils
.
isType
(
clipRect
,
"object"
))
{
throw
new
Error
(
"clipRect must be an Object instance."
);
...
...
@@ -159,10 +160,8 @@ Casper.prototype = {
}
else
{
this
.
log
(
'Capturing page to '
+
targetFile
,
"debug"
);
}
try
{
this
.
page
.
render
(
targetFile
);
}
catch
(
e
)
{
this
.
log
(
'Failed to capture screenshot as '
+
targetFile
+
': '
+
e
,
"error"
);
if
(
!
this
.
page
.
render
(
targetFile
))
{
this
.
log
(
'Failed to save screenshot to '
+
targetFile
+
'; please check permissions'
,
"error"
);
}
if
(
previousClipRect
)
{
this
.
page
.
clipRect
=
previousClipRect
;
...
...
@@ -888,6 +887,9 @@ Casper.prototype = {
* @return Casper
*/
viewport
:
function
(
width
,
height
)
{
if
(
!
this
.
started
)
{
throw
new
Error
(
"Casper must be started in order to set viewport at runtime"
);
}
if
(
!
utils
.
isType
(
width
,
"number"
)
||
!
utils
.
isType
(
height
,
"number"
)
||
width
<=
0
||
height
<=
0
)
{
throw
new
Error
(
"Invalid viewport width/height set: "
+
width
+
'x'
+
height
);
}
...
...
samples/screenshot.js
View file @
92f5aeb
if
(
!
phantom
.
casperLoaded
)
{
console
.
log
(
'This script is intended to work with CasperJS, using its executable.'
);
phantom
.
exit
(
1
);
}
var
casper
=
new
phantom
.
Casper
({
var
casper
=
require
(
'casper'
).
create
({
logLevel
:
"debug"
,
verbose
:
true
verbose
:
true
,
viewportSize
:
{
width
:
1024
,
height
:
768
}
});
casper
.
start
(
'https://twitter.com/#!/twilio'
,
function
(
self
)
{
...
...
@@ -16,4 +15,4 @@ casper.start('https://twitter.com/#!/twilio', function(self) {
casper
.
run
(
function
(
self
)
{
self
.
exit
();
});
\ No newline at end of file
});
...
...
Please
register
or
sign in
to post a comment