source: other-projects/FileTransfer-WebSocketPair/Themes/themebuilder/bin/phantomjs-1.9.2-windows/examples/detectsniff.js@ 31525

Last change on this file since 31525 was 31525, checked in by ak19, 7 years ago

Nathan provided more stuff: Themes folder contains Sencha's Themebuilder which generates GXT Themes. It includes the .theme and generated .jar files for the project theme.

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