BlueGit

blue-star danique-bot

Files

danique-bot / node_modules / phantomjs-prebuilt / lib / phantom / examples / unrandomize.js

unrandomize.js

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