Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fetch inherited CSS properties from Chromium sources
// Run this script (in console) on https://cs.chromium.org/
/**
* Default params when search is initiated from UI (order seems to matter):
*
* Name=value Comments
* -----------------------------------------------------------------------------
* search_request=b -> Required
* query=<query> -> String to search for (with options)
* exact:<Boolean> -> Default: false?
* file:<String> -> Default: /?
* package:<Sting|Regexp> -> Default: chromium
* max_num_results=11 -> Default: 50 (why default from UI isn't 10?)
* results_offset=0 -> Default: 0
* sort_results=false -> Default: false?
* return_local_augmented_results=true -> Default: false? Same results when true/false
* return_directories=true -> Default: true? (directory is file name?)
* return_snippets=true -> Default: false
* return_all_snippets=false -> Default: false?
* return_decorated_snippets=true -> Default: false?
* return_line_matches=false -> Default: false
* consolidated_query=true -> Default: false?
* debug_level=0 -> Default: ?
* exhaustive=true -> Default: ? Same results when true/false
* file_sizes=true -> Default: false
* full_history_search=false -> Default: ?
* lines_context=1 -> Default: false
* sid=<Number> -> Default: ? Same results when true/false
* msid=<Number> -> Default: ? Same results when true/false
* internal_options=b -> Required
* internal_options=e -> Required
* search_request=e -> Required
*/
const encodeParams = params => Object.entries(params).map(([k, v]) => `${k}=${v}`).join('&')
const extractFilename = ({ top_file: { file: { name } }}) => name
const getPropName = path => path.substring(path.lastIndexOf('/') + 1, path.length - 2).replace(/_/g, '-')
const isProprietaryProp = prop => !prop.startsWith('webkit-')
const unique = list => list.filter((item, idx) => list.indexOf(item) == idx)
const search = async (request, offset = 0) => {
const options = {
max_num_results: 10,
results_offset: offset,
search_request: 'e',
}
const response = await fetch(`${request}&${encodeParams(options)}&internal_options=b&internal_options=e`)
const { search_response } = await response.json()
const { search_result } = search_response[0]
const inheritedValues = search_result
.map(extractFilename)
.map(getPropName)
.filter(isProprietaryProp)
let otherInheritedValues = []
if (search_result.length === 10) {
otherInheritedValues = await search(request, offset + 10)
}
return inheritedValues.concat(otherInheritedValues)
}
const url = '/codesearch/json/search_request:1'
const what = 'bool IsInherited() const override { return true'
const where = 'file:src/out/Debug/gen/third_party/blink/renderer/core/css/properties/'
const query = `${what} ${where} exact:yes package:chromium`
const request = `${url}?search_request=b&query=${query}`
search(request).then(unique).then(props => console.dir(props.sort())).catch(console.error)
@cdoublev

This comment has been minimized.

Copy link
Owner Author

@cdoublev cdoublev commented Aug 8, 2020

This no longers works since the search algorythm used on source.chromium.org/chromium (redirection from cs.chromium.org) is now using the Google Contents API, which is private, ie. it can't be added into a project in the Google Cloud Platform.

I keep this Gist for archiving reasons (external links).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment