macbre / phantomas

Headless Chromium-based web performance metrics collector and monitoring tool
https://www.npmjs.com/package/phantomas
BSD 2-Clause "Simplified" License
2.25k stars 141 forks source link

window.callPhantom causes PhantomJS crash #62

Closed sjhcockrell closed 10 years ago

sjhcockrell commented 10 years ago

Mac OS X Phantomas 0.6.1 PhantomJS 1.9.1 Node 0.8.18

I've seen crashes when providing the following URLs:

http://www.meetup.com http://www.washingtonpost.com http://www.cnn.com

So far the only commonality I've seen is that they're all using jQuery 1.7.1. The above URLs simply cause PhantomJS to fail.

The New York Times, which also uses jQuery 1.7.1, will display a series of errors, then either fail or complete. Maybe a race condition?

$ ./phantomas.js --url=http://nytimes.com

TypeError: 'undefined' is not an object (evaluating 'val.fn')

  phantomjs://webpage.evaluate():7
TypeError: '[object ElementConstructor]' is not a constructor (evaluating 'new Element("meta",{"name":"WT.z_fbc"})')

  http://js.nyt.com/js2/build/homepage/top.js:1
  http://js.nyt.com/js2/build/homepage/top.js:1
TypeError: 'undefined' is not a function (evaluating 'NYTD.loadEditionToggle()')

  http://www.nytimes.com/:77
TypeError: 'undefined' is not a function (evaluating '$("#spanABCRegion")')

  http://www.nytimes.com/:326
  http://www.nytimes.com/:337
ReferenceError: Can't find variable: NYT_HP_AVOID_MAYOR_PROMO

  http://www.nytimes.com/:552
TypeError: 'undefined' is not a function (evaluating 'e(document)')

  http://js.nyt.com/projects/assets/geoip_resolver/geotargeted_promo-e951aadc737a7470e13f9da6289fd63a.js:3
  http://js.nyt.com/projects/assets/geoip_resolver/geotargeted_promo-e951aadc737a7470e13f9da6289fd63a.js:3
TypeError: 'undefined' is not an object (evaluating 'e.extend')

  http://js.nyt.com/js2/build/video/players/extended/1.0/app.js:1
  http://www.nytimes.com/:841

// PhantomJS fails.
sjhcockrell commented 10 years ago

Probably redundant with issue #56. Will close that pull request because it is a silly pull request.

Will add more detailed --verbose crash logs.

https://gist.github.com/sjhcockrell/6471107 https://gist.github.com/sjhcockrell/6471131

sjhcockrell commented 10 years ago

CNN Crash Log https://gist.github.com/sjhcockrell/4de01c724a20df7a4949

sjhcockrell commented 10 years ago

Washington Post Crash Log https://gist.github.com/sjhcockrell/fbeb779ae36e15ac425e

sjhcockrell commented 10 years ago

Potentially related or not, a common message I've seen in verbose logs from time to time is:

ReferenceError: Can't find variable: Kk

  :1

A bit odd, since I don't seem to turn up anything inside Phantomas when grepping that has that var name.

sjhcockrell commented 10 years ago

Problem seems to happen with spying on sizzle calls when using jQuery 1.7.1.

modules/jQuery.js : 37-41

macbre commented 10 years ago

Interesting thing is that PhantomJS doesn't die on the first call to Sizzle / first DOM query. Does the same happen when you pass --modules=jQuery as command line option (i.e. only jQuery module is used to gather metrics)?

sjhcockrell commented 10 years ago

Seems like I'm getting identical behavior:

$ ./phantomas.js --url={whatever url} --modules=jQuery --verbose

washingtonpost (still fails) https://gist.github.com/sjhcockrell/c7e938d94513cf6999ca

cnn (pass) - using jQuery 1.7.2 now https://gist.github.com/sjhcockrell/f024292567c611bb24d3

meetup (still fails) https://gist.github.com/sjhcockrell/0fcea0e5453bf24d255c

macbre commented 10 years ago

Thanks to #66 we can now disable given module(s), so now let's try the following:

$ ./phantomas.js --url={whatever url} --skip-modules=jQuery --verbose

Thanks @sjhcockrell for debugging this issue!

macbre commented 10 years ago

Diff between jQuery v1.7.1 and 1.7.2 is quite big - https://github.com/jquery/jquery/compare/1.7.1...1.7.2

sjhcockrell commented 10 years ago

Getting mixed results with the --skip-modules=jQuery flag running.

As an example:

washingtonpost.com (Success) https://gist.github.com/sjhcockrell/96b787ede819c7cf950b

washingtonpost.com (Failure) https://gist.github.com/sjhcockrell/a5c4519b5e69c13c2697

meetup.com (Success) https://gist.github.com/sjhcockrell/d800d3e0714feef07658

meetup.com (Failure) https://gist.github.com/sjhcockrell/b120dab95111ca730706

New hypotheses could be:

a) timeout/race condition issues b) non jQuery-related issues (jQuery version being a red herring)

sjhcockrell commented 10 years ago

Observation 1:

Another observation is that there was a similar pattern when loading washingtonpost.com, meetup.com, and (not included in gists) nytimes.com:

Run 1: Fail Run 2: Success Run 3: Fail Run 4: Fail

Probably unrelated, but slightly strange.

Observation 2:

washingtonpost.com and nytimes.com both commonly cause phantomjs to abort around <script> insertions to either <body> or <head>.

Observation 3:

meetup.com seems to commonly abort around event binding:

23:25:19.199 DOM event: "error" bound to "img"
23:25:19.199 DOM event: "load" bound to "img"

Seems like these could maybe be two separate kinds of errors?

sjhcockrell commented 10 years ago

ebay.com seems to exhibit the same F S F F execution pattern as above. It uses jQuery 1.7.

When failing, it typically fails on DOM insertion.

$ ./phantomas.js --url=http://www.ebay.com --skip-modules=jQuery --verbose --timeout=30

sjhcockrell commented 10 years ago

PhantomJS cut a new release (1.9.2) a little while ago.

Upgrading, at least on an OS X environment, did not seem to fix the issue.

sjhcockrell commented 10 years ago

This set of flags seems to avoid PhantomJS crashes on washingtonpost.com and meetup.com:

# Success on Meetup and Washington Post
./phantomas.js --url={ whatever } --skip-modules=jQuery,domQueries,eventListeners,javaScriptBottlenecks --verbose --timeout=100

Omitting javaScriptBottlenecks on washingtonpost.com calls seems to consistently generate crashes.

# Fail on Washington Post, Success on Meetup
./phantomas.js --url={ whatever } --skip-modules=jQuery,domQueries,eventListeners --verbose --timeout=100
macbre commented 10 years ago

jQuery,domQueries,eventListeners,javaScriptBottlenecks - these are the only modules using phantomas.spy

Running phantomas 20 times against --url=http://meetup.com was successful with spy feature disabled. Back to drawing board ;)

macbre commented 10 years ago
macbre commented 10 years ago
20:51:47.767 DOM insert: node "#text" added to "#document-fragment"
20:51:47.767 DOM insert: node "#document-fragment > #text" added to "body > div.middle > div#main > div#content > div#stage > div#dailyDeal > div.deals > div.ddcrd > div.blast > div.time"
TypeError: 'undefined' is not a function (evaluating 'fn.apply(scope, arguments)')

  /home/macbre/github/phantomas/core/phantomas.js:169
20:51:48.720 DOM query: by id "#MFBB_DD_760_m_400673"

when running for ebay.com...

macbre commented 10 years ago

I've submitted stack trace to PhantomJS issue tracker.

macbre commented 10 years ago

I have a new suspect, officer :)

window.callPhantom is used to send metrics from browser scope to phantomas. API docs says that its stability is expiremental.

$ ./run-multiple.js --url=http://www.ebay.com  --verbose  --timeout 30 --runs 25

with window.callPhantom commented out went smooth as never. JSON encoded string will need to be sent via console.log and parsed on PhantomJS side.

sjhcockrell commented 10 years ago

Wow, great digging to find that one!

macbre commented 10 years ago

71 merged into master. Keeping this issue, so that we can easily re-open (just in case).

sjhcockrell commented 10 years ago

I'll do a bit of stress testing when I get home tonight. Thanks for fixing!

sjhcockrell commented 10 years ago

This is looking pretty healthy--haven't noticed any issues where I was seeing them before.

macbre commented 10 years ago

Jolly good! Thanks for checking and debugging this issue :+1: