I want to create a simple app that will execute JavaScript commands in Chrome Console on a specific page and will return an output.
Namely, I want to get all accessible links from the current page. I can do it by running the following command in Chrome Console:
urls = $$('a'); for (url in urls) console.log(urls[url].href);
It will return a set of links as output, which I'd like to be able to process in my application.
I can run it manually from Chrome Console, but I want to automate this task because I have a lot of links to work with.
The pseudocode is something like the following:
function runCommandOnSite(command, site) { ... }
function main() {
let site = "facebook.com";
let command = "urls = $$('a'); for (url in urls) console.log(urls[url].href)";
let result_links = runCommandOnSite(site, command);
console.log(result_links);
}
Note: any programming language which could be run from Linux Desktop is acceptable.