Google-chrome – How to run Javascript code on any website

google-chromegoogle-chrome-extensionsjavascript

How can I run Javascript code on a website to complete a set function or rule as per the website?

For example, if I'm trying to download a file from some filehost that requires a survey… Now in the source code, the code requires a JSON response to allow file download after the file has been downloaded (just guessing!)…
If I write a code in Javascript, and run it on that site, sending the JSON code (true) to the page's event handler, then can I download the file?

This is only an example, I'm mainly trying to run Javascript codes on websites as per the website's code. I've heard of Greasemonkey, and some other similar extensions and addons, but didn't quite know how to use them or what they're meant for…

Please could someone explain how I could do that?

Best Answer

You don't need an extension for that. Use the console.

To open the Console tab, do one of the following:

  • Use the keyboard shortcut Command-Option-J (Mac) or Control-Shift-J (Windows/Linux).

  • Select View > Developer > JavaScript Console.

Now you can execute any Javascript you want. Variables and functions that are defined in the global scope of the current document can also be used.

For example, if the current site has jQuery included, you can send JSON to a remote script:

$.post( "http://example.com/test.php", { foo: "bar" } );
Related Question