BlueGit

blue-star danique-bot

Files

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

detectsniff.js

Import template
timfa Tim · pushed by timfa · 4 years ago
c788ad20 History
detectsniff.js 1.7 KiB Download Raw
1// Detect if a web page sniffs the user agent or not.
2
3"use strict";
4var page = require('webpage').create(),
5 system = require('system'),
6 sniffed,
7 address;
8
9page.onInitialized = function () {
10 page.evaluate(function () {
11
12 (function () {
13 var userAgent = window.navigator.userAgent,
14 platform = window.navigator.platform;
15
16 window.navigator = {
17 appCodeName: 'Mozilla',
18 appName: 'Netscape',
19 cookieEnabled: false,
20 sniffed: false
21 };
22
23 window.navigator.__defineGetter__('userAgent', function () {
24 window.navigator.sniffed = true;
25 return userAgent;
26 });
27
28 window.navigator.__defineGetter__('platform', function () {
29 window.navigator.sniffed = true;
30 return platform;
31 });
32 })();
33 });
34};
35
36if (system.args.length === 1) {
37 console.log('Usage: detectsniff.js <some URL>');
38 phantom.exit(1);
39} else {
40 address = system.args[1];
41 console.log('Checking ' + address + '...');
42 page.open(address, function (status) {
43 if (status !== 'success') {
44 console.log('FAIL to load the address');
45 phantom.exit();
46 } else {
47 window.setTimeout(function () {
48 sniffed = page.evaluate(function () {
49 return navigator.sniffed;
50 });
51 if (sniffed) {
52 console.log('The page tried to sniff the user agent.');
53 } else {
54 console.log('The page did not try to sniff the user agent.');
55 }
56 phantom.exit();
57 }, 1500);
58 }
59 });
60}