unrandomize.js 655 B

12345678910111213141516171819202122232425
  1. // Modify global object at the page initialization.
  2. // In this example, effectively Math.random() always returns 0.42.
  3. "use strict";
  4. var page = require('webpage').create();
  5. page.onInitialized = function () {
  6. page.evaluate(function () {
  7. Math.random = function() {
  8. return 42 / 100;
  9. };
  10. });
  11. };
  12. page.open('http://ariya.github.com/js/random/', function (status) {
  13. var result;
  14. if (status !== 'success') {
  15. console.log('Network error.');
  16. } else {
  17. console.log(page.evaluate(function () {
  18. return document.getElementById('numbers').textContent;
  19. }));
  20. }
  21. phantom.exit();
  22. });