Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jserrors generate by injected Code ? #230

Closed
jedi4ever opened this issue Feb 13, 2014 · 8 comments
Closed

Jserrors generate by injected Code ? #230

jedi4ever opened this issue Feb 13, 2014 · 8 comments
Assignees
Labels
Milestone

Comments

@jedi4ever
Copy link

phantomas nodejs v0.10.7 +0ms
phantomas PhantomJS v1.9.7
phantomas phantomas v0.12.1

I was testing on a site and only got partial content and jserrors.
The page rendered ok in phantomjs screenshot but failed in phantomas.

It mentioned Type Errorsand Parse Errors. (See below)
When disabling the origConsoleLog line in the sendMsg function on scope.js , it worked.
Not sure what was happening there. But it worked :)

function sendMsg(type, data) {
  // @see https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#oncallback
  // Stability: EXPERIMENTAL - see issue #62
  /**
  if (typeof window.callPhantom === 'function') {
    window.callPhantom({type: type, data: data});
  }
  **/
 //PDB
 //origConsoleLog.call(console, 'msg:' + stringify({type: type || false, data: data || false}));
}
TRACE:
 -> /Users/patrick/dev/pusher-stats/node_modules/phantomas/core/scope.js: 124 (in function "sendMsg")
 -> /Users/patrick/dev/pusher-stats/node_modules/phantomas/core/scope.js: 136 (in function "incrMetric")
 -> phantomjs://webpage.evaluate(): 32
 -> /Users/patrick/dev/pusher-stats/node_modules/phantomas/core/scope.js: 186
 -> http://mysite.be/: 26
17:53:49.261 Event jserror emitted
17:53:49.262 TypeError: Type error
17:53:49.262 Backtrace: sendMsg(): undefined @ 124 / incrMetric(): undefined @ 136 / unknown fn: undefined @ 32 / unknown fn: undefined @ 18
6 / unknown fn: undefined @ 26 / unknown fn: undefined @ 26
@macbre macbre added the bug label Feb 13, 2014
@macbre macbre self-assigned this Feb 13, 2014
@macbre
Copy link
Owner

macbre commented Feb 13, 2014

Hi @jedi4ever,

Thanks for reporting an error. Can you log the typeof origConsoleLog before the call statement? Does this error happen on other URLs?

@jedi4ever
Copy link
Author

@macbre it's really hard to output something there. As the console.log is used to write the output.
The run, starts with a nice typeof origConsoleLog == 'function' , and it stays a function AFAIK (doing if (typeof origConsoleLog) ) .

Do you have an idea how I can always have the good function or protect it from being changed?

@jedi4ever
Copy link
Author

URL I'm testing is - http://eurosong.een.be/#aflevering/3

@macbre
Copy link
Owner

macbre commented Feb 13, 2014

Chrome console for the page you've mentioned above reveals possible cause:

> console.log
function () {}

@macbre
Copy link
Owner

macbre commented Feb 13, 2014

Works much better when run as:

phantomas --url "http://eurosong.een.be/?debug=1#aflevering/3" --verbose

The JS code that overrides the whole window.console object is that triggers the error.

@jedi4ever
Copy link
Author

Nice spotting ; would it make sense to keep a pointer to the console.log globally at the top of the page? So it can't really get overwritten?

@macbre
Copy link
Owner

macbre commented Feb 14, 2014

It is actually, as origConsoleLog. However, the global console object is overwritten (when there's no debug "flag" in URL), causing origConsoleLog.call(console to fail.

@macbre
Copy link
Owner

macbre commented Feb 14, 2014

The only sensible solution I can think of is to emit more meaningful error message:

Error: phantomas: calling native console.log() failed ("TypeError: Type error")!

Modifying native objects and methods in JavaScript is asking for troubles :)

@macbre macbre added this to the v1.0 milestone Feb 14, 2014
macbre added a commit that referenced this issue Jun 5, 2015
Was throwing "TypeError: Attempting to change value of a readonly property."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants