-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathflash.js
103 lines (81 loc) · 2.11 KB
/
flash.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"use strict";
function fakeObject(object, override) {
var exclude = Object.keys(override);
var prototype = Object.create(Object.getPrototypeOf(object));
var constructor = function() {};
var instance;
var key;
constructor.prototype = prototype;
copy = new constructor();
for (key in navigator) {
if ((object.hasOwnProperty(key) === true) && (exclude.indexOf(key) === -1)) {
Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(object, key));
}
}
exclude.forEach(function(key) {
var descriptor = Object.getOwnPropertyDescriptor(object, key);
if (descriptor) {
delete descriptor.get;
delete descriptor.set;
} else {
descriptor = {
'writable': true,
'enumerable': true,
'configurable': true
};
}
descriptor.value = override[key];
Object.defineProperty(copy, key, descriptor);
});
return copy;
}
function flash(page) {
return page.evaluate(function(fakeObject) {
try {
var mimeTypes;
var plugins;
var mime;
var plugin;
// Create fake MIME and plug-in objects.
mime = {
'description': 'Shockwave Flash',
'suffixes': 'swf',
'type': 'application/x-shockwave-flash'
};
plugin = {
'description': 'Shockwave Flash 11.9 r900',
'filename': 'pepflashplayer.dll',
'0': mime,
'length': 1
};
// Create cirular reference.
mime['enabledPlugin'] = plugin;
// Create fake lists of MIME types and plug-ins.
mimeTypes = fakeObject(navigator.mimeTypes, {
'application/x-shockwave-flash': mime,
'length': 1,
'0': mime
});
plugins = fakeObject(navigator.plugins, {
'Shockwave Flash': plugin,
'length': 1,
'0': plugin
});
// Fake the navigator object so we are able to override them.
navigator = fakeObject(navigator, {
'plugins': plugins,
'mimeTypes': mimeTypes
});
// Add a fake "GetVersion" prototype.
HTMLObjectElement.prototype.GetVariable = HTMLEmbedElement.prototype.GetVariable = function(name) {
if (name === '$version') {
return 'LNX 14,0,0,125';
}
};
} catch (err) {
return false;
}
return true;
}, fakeObject);
}
module.exports = flash;