-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-vsnative.html
More file actions
164 lines (158 loc) · 8.03 KB
/
Copy pathdev-vsnative.html
File metadata and controls
164 lines (158 loc) · 8.03 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>patched vs pristine native</title></head>
<body><pre id="out">running…</pre>
<script>
sessionStorage.setItem('v.ui.s', JSON.stringify({
mode:'normal', screenWidth:2560, screenHeight:1440, colorDepth:32, devicePixelRatio:1,
platform:'Win32', hwConcurrency:12, deviceMemory:32, vendor:'Google Inc.',
language:'et-EE', locale:'et-EE', countryCode:'EE', languages:['et-EE','et','en','en-US'],
timezone:'Europe/Tallinn', noiseSeed:305419896, maxTouchPoints:0, pdfViewerEnabled:true,
userAgent:navigator.userAgent.replace(/Chrome\/[\d.]+/,'Chrome/151.0.0.0'),
appVersion:'5.0 (Windows NT 10.0; Win64; x64)',
webglVendor:'Google Inc. (NVIDIA)', webglRenderer:'ANGLE (NVIDIA, RTX 3060)', webglParams:{},
clientHints:{platform:'Windows',mobile:false,platformVersion:'10.0.0',architecture:'x86',bitness:'64',wow64:false,model:'',formFactors:['Desktop']},
allowedFonts:['Arial','Segoe UI','Tahoma'], mediaDevices:[], plugins:[], mimeTypes:[],
speechVoices:[{name:'Microsoft Kaia - Estonian',lang:'et-EE',localService:true,default:true}],
features:{canvas:true,audio:true,webgl:true,webrtc:true,navigator:true,screen:true,timezone:true,
geolocation:true,battery:true,fonts:true,clientRects:true,plugins:true,network:true,hideAdBlocker:true}
}));
sessionStorage.setItem('v.ui.m','normal');
const L=[]; const t=(n,p,d)=>L.push((p?'PASS ':'FAIL ')+n+(d?' :: '+d:''));
const ORDER=['profile-injector.js','mw/mw-bag.js','mw/mw-core.js','mw/mw-timezone-screen.js',
'mw/mw-navigator.js','mw/mw-canvas-audio.js','mw/mw-misc.js','mw/mw-workers.js','mw/mw-geo.js','mw/mw-adblock.js'];
const load=(s)=>new Promise(r=>{const e=document.createElement('script');e.src=s+'?x='+Date.now();
e.onload=()=>r(1);e.onerror=()=>r(0);document.head.appendChild(e);});
// pristine reference: an about:blank iframe created BEFORE the modules load,
// whose realm we snapshot immediately — nothing of ours has run in it.
const ifr=document.createElement('iframe'); ifr.style.display='none';
document.body.appendChild(ifr);
const W0=ifr.contentWindow;
function sigIn(win, path, prop, kind){
try{
let holder=win, parts=path?path.split('.'):[];
for(const p of parts){ holder=holder[p]; if(!holder) return null; }
if(kind==='getter'){
let o=holder,d=null;
while(o&&!d){ d=Object.getOwnPropertyDescriptor(o,prop); if(!d) o=Object.getPrototypeOf(o); }
if(!d||!d.get) return null;
return {name:d.get.name, length:d.get.length, str:String(d.get)};
}
const f=holder[prop];
if(typeof f!=='function') return null;
return {name:f.name, length:f.length, str:String(f)};
}catch(e){ return null; }
}
// Everything we patch that also exists natively — compared shape-for-shape.
const CASES=[
// accessors on prototypes
['Navigator.prototype','deviceMemory','getter'],
['Navigator.prototype','hardwareConcurrency','getter'],
['Navigator.prototype','languages','getter'],
['Navigator.prototype','language','getter'],
['Navigator.prototype','userAgentData','getter'],
['Screen.prototype','width','getter'],
['Screen.prototype','height','getter'],
['Screen.prototype','availWidth','getter'],
['Screen.prototype','colorDepth','getter'],
['TextMetrics.prototype','width','getter'],
['TextMetrics.prototype','actualBoundingBoxAscent','getter'],
['NetworkInformation.prototype','downlink','getter'],
['NetworkInformation.prototype','effectiveType','getter'],
['NetworkInformation.prototype','rtt','getter'],
['NetworkInformation.prototype','onchange','getter'],
['Error.prototype','stack','getter'],
['MimeType.prototype','enabledPlugin','getter'],
['FontFaceSet.prototype','size','getter'],
['OfflineAudioContext.prototype','oncomplete','getter'],
['Intl.Locale.prototype','timeZone','getter'],
['','innerWidth','getter'], ['','innerHeight','getter'],
['','outerWidth','getter'], ['','outerHeight','getter'],
['','devicePixelRatio','getter'],
['VisualViewport.prototype','width','getter'],
['VisualViewport.prototype','height','getter'],
['Element.prototype','clientWidth','getter'],
['Element.prototype','clientHeight','getter'],
// methods
['Date.prototype','getTimezoneOffset','method'],
['Date.prototype','toString','method'],
['Date.prototype','toLocaleString','method'],
['Date.prototype','toLocaleDateString','method'],
['Date.prototype','toLocaleTimeString','method'],
['Date.prototype','getHours','method'],
['Date.prototype','setHours','method'],
['Number.prototype','toLocaleString','method'],
['Intl.DateTimeFormat.prototype','resolvedOptions','method'],
['Intl.DateTimeFormat.prototype','formatToParts','method'],
['Intl.NumberFormat.prototype','resolvedOptions','method'],
['CanvasRenderingContext2D.prototype','getImageData','method'],
['CanvasRenderingContext2D.prototype','measureText','method'],
['CanvasRenderingContext2D.prototype','fillText','method'],
['CanvasRenderingContext2D.prototype','strokeText','method'],
['HTMLCanvasElement.prototype','toDataURL','method'],
['HTMLCanvasElement.prototype','toBlob','method'],
['HTMLCanvasElement.prototype','getContext','method'],
['OffscreenCanvas.prototype','getContext','method'],
['OffscreenCanvas.prototype','convertToBlob','method'],
['OffscreenCanvasRenderingContext2D.prototype','getImageData','method'],
['OffscreenCanvasRenderingContext2D.prototype','measureText','method'],
['Element.prototype','getBoundingClientRect','method'],
['Range.prototype','getBoundingClientRect','method'],
['WebGLRenderingContext.prototype','getParameter','method'],
['WebGL2RenderingContext.prototype','getParameter','method'],
['AnalyserNode.prototype','getFloatFrequencyData','method'],
['AnalyserNode.prototype','getByteFrequencyData','method'],
['SpeechSynthesis.prototype','getVoices','method'],
['Performance.prototype','now','method'],
['','matchMedia','method'],
['Permissions.prototype','query','method'],
['MediaDevices.prototype','enumerateDevices','method'],
['Geolocation.prototype','getCurrentPosition','method'],
['Geolocation.prototype','watchPosition','method'],
['Geolocation.prototype','clearWatch','method'],
['Navigator.prototype','getBattery','method'],
['ServiceWorkerContainer.prototype','register','method'],
['NavigatorUAData.prototype','getHighEntropyValues','method'],
['NavigatorUAData.prototype','brands','getter'],
['RTCPeerConnection.prototype','addEventListener','method'],
['FontFaceSet.prototype','check','method'],
['FontFaceSet.prototype','load','method'],
// constructors
['','Date','method'],
['Intl','DateTimeFormat','method'],
['Intl','NumberFormat','method'],
['Intl','Collator','method'],
['Intl','PluralRules','method'],
['Intl','RelativeTimeFormat','method'],
['Intl','Locale','method']
];
(async()=>{
// snapshot pristine natives from the untouched iframe realm first
const ref={};
for(const [path,prop,kind] of CASES){
ref[path+'.'+prop] = sigIn(W0, path, prop, kind);
}
for(const f of ORDER) await load(f);
let patched=0, mismatched=0, skipped=0;
for(const [path,prop,kind] of CASES){
const key=path+'.'+prop;
const n=ref[key], o=sigIn(window, path, prop, kind);
if(!n||!o){ skipped++; continue; }
const same = n.name===o.name && n.length===o.length && n.str===o.str;
const isOurs = o.str!==n.str || o.name!==n.name || o.length!==n.length;
if(!same){
mismatched++;
L.push('FAIL '+key);
if(n.name!==o.name) L.push(' name: native "'+n.name+'" ours "'+o.name+'"');
if(n.length!==o.length)L.push(' length: native '+n.length+' ours '+o.length);
if(n.str!==o.str) L.push(' str: native '+n.str+'\n ours '+o.str);
} else patched++;
}
L.unshift('compared '+(patched+mismatched)+' APIs against a pristine iframe realm ('+skipped+' unavailable)');
L.unshift('');
L.unshift(mismatched===0
? 'PASS every patched API is shape-identical to its pristine native (name|length|toString)'
: 'FAIL '+mismatched+' APIs differ from pristine native:');
document.getElementById('out').textContent=L.join('\n');
})();
</script>
</body></html>