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
10495da5
...
10495da54a17f73579dd1c7f5ffb4202ab71d54a
authored
2014-05-20 00:07:43 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixes #178 - plain text version for non-html contents.
1 parent
7d9f0e18
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
29 deletions
modules/casper.js
tests/suites/casper/content.js
modules/casper.js
View file @
10495da
...
...
@@ -943,36 +943,10 @@ Casper.prototype.getPageContent = function getPageContent() {
"use strict"
;
this
.
checkStarted
();
var
contentType
=
utils
.
getPropertyPath
(
this
,
'currentResponse.contentType'
);
if
(
!
utils
.
isString
(
contentType
))
{
if
(
!
utils
.
isString
(
contentType
)
||
contentType
.
indexOf
(
"text/html"
)
!==
-
1
)
{
return
this
.
page
.
frameContent
;
}
// for some reason (qt)webkit/Gecko will always enclose non text/html body contents within an html
// structure like this:
// webkit: <html><head></head><body><pre style="(...)">content</pre></body></html>
// gecko: <html><head><link rel="alternate stylesheet" type="text/css" href="resource://gre-resources/plaintext.css" title="..."></head><body><pre>document.write('foo');\n</pre></body></html>
var
sanitizedHtml
=
this
.
evaluate
(
function
checkHtml
()
{
var
head
=
__utils__
.
findOne
(
'head'
),
body
=
__utils__
.
findOne
(
'body'
);
if
(
!
head
||
!
body
)
{
return
null
;
}
// for content in Webkit
if
(
head
.
childNodes
.
length
===
0
&&
body
.
childNodes
.
length
===
1
&&
__utils__
.
findOne
(
'body pre[style]'
))
{
return
__utils__
.
findOne
(
'body pre'
).
textContent
.
trim
();
}
// for content in Gecko
if
(
head
.
childNodes
.
length
===
1
&&
body
.
childNodes
.
length
===
1
&&
head
.
childNodes
[
0
].
localName
===
'link'
&&
head
.
childNodes
[
0
].
getAttribute
(
'href'
)
===
'resource://gre-resources/plaintext.css'
&&
body
.
childNodes
[
0
].
localName
===
'pre'
)
{
return
body
.
childNodes
[
0
].
textContent
.
trim
();
}
return
null
;
});
return
sanitizedHtml
?
sanitizedHtml
:
this
.
page
.
frameContent
;
return
this
.
page
.
framePlainText
;
};
/**
...
...
tests/suites/casper/content.js
View file @
10495da
...
...
@@ -13,7 +13,7 @@ casper.test.begin("Casper.getPageContent() text/html content", 1, function(test)
casper
.
test
.
begin
(
"Casper.getPageContent() non text/html content"
,
1
,
function
(
test
)
{
casper
.
start
(
"tests/site/dummy.js"
,
function
()
{
test
.
assertEquals
(
this
.
getPageContent
(),
"document.write('foo');"
,
test
.
assertEquals
(
this
.
getPageContent
(),
"document.write('foo');
\n
"
,
"Casper.getPageContent() retrieves non text/html content"
);
}).
run
(
function
()
{
test
.
done
();
...
...
Please
register
or
sign in
to post a comment