2

So there's an online quiz which uses flash, and my friend claims he has a script which pulls the answers from the flash app and displays them. I want to test this out, but I have a question:

How can I add or run this script to chrome so that this happens? In general, how can you run your javascript on a certain site on chrome? This concept interests me, and I didn't know it was possible to force sites to do stuff.

4
  • 4
    Try the dev tools developer.chrome.com/devtools Commented Sep 16, 2014 at 15:08
  • There is a plugin for firefox named Greasemonkey, that can run custom Javascript on desired sites, the equivalent for it is Tampermonkey in Chrome but I've not test it yet Commented Sep 16, 2014 at 15:11
  • @Serj - accurate info - but this question is tagged with Chrome and not Firefox. Commented Sep 16, 2014 at 15:11
  • 2
    Make sure that you know what exactly that code does.it's not a good idea to run arbitrary codes on the console. Commented Sep 16, 2014 at 15:13

2 Answers 2

3

You can open the developers tools by pressing your F12 key or Ctrl+Shift+i. You can also right click on any element in the page and select "inspect element".

Once the developers tools are open, you can navigate to the right most tab called "console". There you can enter arbitrary JavaScript code to be executed on the currently open page.


Be careful what you paste into that console though! Someone might give you some malicious code to run. When you open the console while you browse Facebook, they actually display this warning:

Facebook is just an example. The same warning is applicable for any site.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks. Can you explain, when I paste: <script> document.getElementById("demo").innerHTML = "Hello JavaScript!"; </script> into the console it says "unexpected token" for the very first "<"
@user29855 What you quoted is HTML code. You need just the script - which is between the tags.
@user29855 - and this is why you should never blindly execute code you know nothing about. All you have to do is remove the <script> on both sides of the code.
@Lix I wasn't aware of the dangers of Hello World
@user29855 That would mean the document contains no element with id demo. To do a very simple Hello world, use console.log().
|
2

It's quite a broad question. However. there are 3 main answers:

  1. For one-time fiddling, you have the power of Dev Tools at your fingertips. You can run code in the context of the page, examine and debug its own code, make realtime modifications to the DOM etc.

  2. To make a script execute every time you load some page, the traditionally used approach is Userscripts, a notion that came from Firefox. Google Chrome is able (or at least used used to be able) to handle them directly, but now most people use an extension, TamperMonkey, that runs userscripts for you.

  3. Finally, if you need more powerful tools for interacting with your browser, you have Chrome Extensions. They are, basically, JavaScript scripts empowered with access to Chrome APIs. In this context, JS code injected into pages is called Content Scripts.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.