Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use a command line tool to view the JavaScript interpreted source of a web page?

Is there a command line tool that allows you to get the text of the JavaScript interpreted source of a web page similar to how you can see the interpreted code in FireBug on FireFox?

I would like to use CURL or similar tool to request a web page. The catch is I would like to view how the code has been modified by JavaScript. For instance if the dom has been changed or an element has been modified, I would like to see the modified version. I know FireBug does this for FireFox, but I am looking for a way to script the process.

like image 248
whoacowboy Avatar asked Dec 29 '12 00:12

whoacowboy


People also ask

How can I see the JavaScript of a website?

For most browsers, to view inline JavaScript in the HTML source code, do one of the following. Press the Ctrl + U keyboard shortcut. Right-click an empty area on the web page and select the View page source or similar option in the pop-up menu.

How use JavaScript command line?

To run the REPL, just type node at the command line. You'll see a new prompt appear—this time, a > instead of a $ . As long as the prompt is > , you can type Javascript expressions and see what they evaluate to (sort of like a calculator). To exit the REPL, type .

How is JavaScript interpreted by the browser?

In contrast, JavaScript has no compilation step. Instead, an interpreter in the browser reads over the JavaScript code, interprets each line, and runs it. More modern browsers use a technology known as Just-In-Time (JIT) compilation, which compiles JavaScript to executable bytecode just as it is about to run.


1 Answers

Have you looked in to tools like PhantomJS for running the tests? Many of them support running a "headless" browser, which lets you render pages and run JS against the rendered page without having to actually run a browser. It doesn't use curl, but I don't see why that should be a requirement.

For instance:

$ phantomjs save_page.js http://example.com 

with save_page.js:

var system = require('system');
var page = require('webpage').create();

page.open(system.args[1], function()
{
    console.log(page.content);
    phantom.exit();
});
like image 200
pjmorse Avatar answered Oct 09 '22 20:10

pjmorse