forked from philipwalton/html-inspector
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlarge-viewstate.js
37 lines (28 loc) · 1.04 KB
/
large-viewstate.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
module.exports = {
name: "large-viewstate",
config: {
//Warn if more than 50 KB in total size
sizeInKB: 50
},
func: function(listener, reporter, config) {
var viewStateCount = 0
, viewStateSize = 0
// register a handler for the `attribute` event
listener.on('attribute', function(name, value, element) {
//Total no. of characters in value attribute of all <input type="hidden" name="__VIEWSTATE"> tags should not be more than 50 (config value)
if (name=="name" && value.indexOf("__VIEWSTATE")===0 && value!== "__VIEWSTATEFIELDCOUNT") {
viewStateCount++
viewStateSize += element.getAttribute("value").length
}
})
listener.on("afterInspect", function() {
if (viewStateSize > config.sizeInKB * 1024) {
reporter.warn(
"large-viewstate",
viewStateSize/1024 + " KB is being used in " + viewStateCount + " chunk(s) of View State.",
"Disable View States where not needed for better performace."
)
}
})
}
}