detectsniff.coffee 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. page = require('webpage').create()
  2. system = require 'system'
  3. page.onInitialized = ->
  4. page.evaluate ->
  5. userAgent = window.navigator.userAgent
  6. platform = window.navigator.platform
  7. window.navigator =
  8. appCodeName: 'Mozilla'
  9. appName: 'Netscape'
  10. cookieEnabled: false
  11. sniffed: false
  12. window.navigator.__defineGetter__ 'userAgent', ->
  13. window.navigator.sniffed = true
  14. userAgent
  15. window.navigator.__defineGetter__ 'platform', ->
  16. window.navigator.sniffed = true
  17. platform
  18. if system.args.length is 1
  19. console.log 'Usage: detectsniff.coffee <some URL>'
  20. phantom.exit 1
  21. else
  22. address = system.args[1]
  23. console.log 'Checking ' + address + '...'
  24. page.open address, (status) ->
  25. if status isnt 'success'
  26. console.log 'FAIL to load the address'
  27. phantom.exit()
  28. else
  29. window.setTimeout ->
  30. sniffed = page.evaluate(->
  31. navigator.sniffed
  32. )
  33. if sniffed
  34. console.log 'The page tried to sniff the user agent.'
  35. else
  36. console.log 'The page did not try to sniff the user agent.'
  37. phantom.exit()
  38. , 1500