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
af7f4435
...
af7f4435a83c311b7f977d02f3097c30d2da788d
authored
2011-11-09 12:34:44 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
better Casper.capture()
1 parent
6407ef35
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
9 deletions
casper.js
casper.js
View file @
af7f443
...
...
@@ -106,27 +106,33 @@
/**
* Proxy method for WebPage#render. Adds a clipRect parameter for
* automatically set page clipRect setting values and sets it back once
* done.
* done. If the cliprect parameter is omitted, the full page viewport
* area will be rendered.
*
* @param String targetFile A target filename
* @param mixed clipRect An optional clipRect object
* @param mixed clipRect An optional clipRect object
(optional)
* @return Casper
*/
capture
:
function
(
targetFile
,
clipRect
)
{
if
(
typeof
clipRect
!==
"object"
)
{
throw
new
Error
(
"ClipRect must be an object instance."
);
}
var
previousClipRect
=
this
.
page
.
clipRect
;
var
previousClipRect
;
if
(
clipRect
)
{
if
(
typeof
clipRect
!==
"object"
)
{
throw
new
Error
(
"clipRect must be an Object instance."
);
}
previousClipRect
=
this
.
page
.
clipRect
;
this
.
page
.
clipRect
=
clipRect
;
this
.
log
(
'Capturing page to '
+
targetFile
+
' with clipRect'
+
JSON
.
stringify
(
clipRect
),
"debug"
);
}
else
{
this
.
log
(
'Capturing page to '
+
targetFile
,
"debug"
);
}
if
(
!
this
.
page
.
render
(
targetFile
))
{
this
.
log
(
'Failed to capture screenshot as '
+
targetFile
,
"error"
);
try
{
this
.
page
.
render
(
targetFile
);
}
catch
(
e
)
{
this
.
log
(
'Failed to capture screenshot as '
+
targetFile
+
': '
+
e
,
"error"
);
}
if
(
previousClipRect
)
{
this
.
page
.
clipRect
=
previousClipRect
;
}
this
.
page
.
clipRect
=
previousClipRect
;
return
this
;
},
...
...
Please
register
or
sign in
to post a comment