Skip to content

CLI tool to evaluate a JS snippet in a webpage context with headless chrome

Notifications You must be signed in to change notification settings

vith/headless-eval

Repository files navigation

headless-eval pipeline status dependency status

CLI tool to evaluate a JS snippet in a webpage context with headless chrome

Install

$ npm i -g headless-eval

Usage

$ headless-eval -h
Usage: headless-eval [options] <url> <js_snippet>

CLI tool to evaluate a JS snippet in a webpage context with headless chrome

Options:
  -V, --version  output the version number
  -j, --json     output result as JSON
  -h, --help     output usage information

Examples

$ headless-eval https://news.ycombinator.com '[...document.querySelectorAll("a.titlelink")].slice(0, 3).map(a => `${a.textContent} - ${a.href}`)'
Apple News No Longer Supports RSS - https://mjtsai.com/blog/2019/12/26/apple-news-no-longer-supports-rss/
Darpa head resigns, moving on to industry - https://www.defensenews.com/breaking-news/2019/12/17/darpa-head-resigns-moving-on-to-industry/
Scientists Likely Found Way to Grow New Teeth for Patients - https://www.sciencetimes.com/articles/24252/20191111/scientists-likely-found-way-to-grow-new-teeth-for-patients.htm
$ headless-eval -j https://news.ycombinator.com '[...document.querySelectorAll("a.titlelink")].slice(0, 3).map(({ textContent: title, href }) => ({ title, href }))'
[
        {
                "title": "Apple News No Longer Supports RSS",
                "href": "https://mjtsai.com/blog/2019/12/26/apple-news-no-longer-supports-rss/"
        },
        {
                "title": "Darpa head resigns, moving on to industry",
                "href": "https://www.defensenews.com/breaking-news/2019/12/17/darpa-head-resigns-moving-on-to-industry/"
        },
        {
                "title": "Scientists Likely Found Way to Grow New Teeth for Patients",
                "href": "https://www.sciencetimes.com/articles/24252/20191111/scientists-likely-found-way-to-grow-new-teeth-for-patients.htm"
        }
]