-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate-core-protocol.js
84 lines (67 loc) · 1.96 KB
/
generate-core-protocol.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
'use strict'
var _ = require('lodash')
var fs = require('fs')
var request = require('request-promise')
var fetchChromeProtocol = () => {
return new Promise((resolve, reject) => {
var protocol = {
version: { 'major': '1', 'minor': '2' },
domains: []
}
var urls = [
'https://chromium.googlesource.com/chromium/src/+/master/third_party/WebKit/Source/core/inspector/browser_protocol.json?format=TEXT',
'https://chromium.googlesource.com/v8/v8/+/master/src/inspector/js_protocol.json?format=TEXT'
]
var fetchedProtocols = urls.map(url => {
return request(url).then(body => {
return JSON.parse(Buffer.from(body, 'base64').toString('utf8'))
})
})
Promise.all(fetchedProtocols).then(protocols => {
var mergedDomains = []
protocols.forEach(protocol => {
mergedDomains.push(...protocol.domains)
})
protocol.domains = mergedDomains
resolve(protocol)
})
})
}
fetchChromeProtocol().then(chromeProtocol => {
var domainList = []
var seenList = new Map()
// Filter domains
chromeProtocol.domains.forEach(domain => {
if (isRelevant(domain)) {
domainList.push(domain)
}
})
// Filter commands, events and types
domainList.forEach(domain => {
domain.commands = domain.commands.filter(c => isRelevant(c) ? c : false)
if (domain.events) {
domain.events = domain.events.filter(c => isRelevant(c) ? c : false)
}
if (domain.types) {
domain.types = domain.types.filter(c => isRelevant(c) ? c : false)
}
})
var protocol = chromeProtocol
protocol.domains = domainList
fs.writeFile('protocol.json', JSON.stringify(protocol, null, 2), function (err) {
if (err) {
console.log(err)
} else {
console.log('Core Protocol JSON file generated')
}
})
}).catch(err => {
console.log('err', err)
})
function isRelevant (o) {
if (o.experimental || o.deprecated) {
return false
} else {
return true
}
}