In this particular query, I have defined the const contents
to be the content of my HTML file for the sake of convenience.
var webPage = require('webpage');
var page = webPage.create();
const contents = `
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript">
console.log("TEXT WITHIN HTML");
</script>
</head>
<body></body>
</html>
`;
page.open(contents, function(status) {
console.log('Status: ' + status);
page.evaluate("function() { console.log('page.evaluated stuff')}");
});
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
Upon executing $ phantomjs test.js
:
$ phantomjs test.js
Status: success
CONSOLE: page.evaluated stuff (from line # in "")
The code successfully captures the console.log
that is part of the page.evaluate
method, but it does not capture the one within the <script>
tag in the HTML file.
What is the reason behind this behavior? I am not very well-versed in PhantomJS.