简体   繁体   English

如何在谷歌浏览器中运行自己的JavaScript

[英]How to run your own javascript in google chrome

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. 因此,有一个使用Flash的在线测验,我的朋友说他有一个脚本,可以从Flash应用程序中提取答案并显示答案。 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? 如何将这个脚本添加或运行到chrome中,以便发生这种情况? In general, how can you run your javascript on a certain site on chrome? 一般来说,如何在chrome的某个网站上运行javascript? This concept interests me, and I didn't know it was possible to force sites to do stuff. 这个概念让我很感兴趣,我不知道是否可以强迫网站做事。

You can open the developers tools by pressing your F12 key or Ctrl + Shift + i . 您可以通过按F12键或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. 您可以在此处输入要在当前打开的页面上执行的任意JavaScript代码。


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时打开控制台时,它们实际上会显示以下警告:

Facebook is just an example. Facebook只是一个例子。 The same warning is applicable for any site. 同样的警告适用于任何站点。

It's quite a broad question. 这是一个广泛的问题。 However. 然而。 there are 3 main answers: 主要有3个答案:

  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. 您可以在页面的上下文中运行代码,检查和调试其自己的代码,对DOM进行实时修改等。

  2. To make a script execute every time you load some page, the traditionally used approach is Userscripts , a notion that came from Firefox. 为了使脚本在每次加载某些页面时都能执行,传统上使用的方法是Userscripts ,这是来自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. 谷歌Chrome可以(或至少使用以前可以)直接处理它们,但现在大多数人使用的扩展, TamperMonkey ,运行userscripts你。

  3. Finally, if you need more powerful tools for interacting with your browser, you have Chrome Extensions . 最后,如果您需要更强大的工具来与浏览器进行交互,则可以使用Chrome扩展程序 They are, basically, JavaScript scripts empowered with access to Chrome APIs . 基本上,它们是可访问Chrome API的 JavaScript脚本。 In this context, JS code injected into pages is called Content Scripts . 在这种情况下,注入页面的JS代码称为Content Scripts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Chrome 控制台上的本地计算机上运行 javascript 文件? - How to run a javascript file on your local machine on the chrome console? 如何将自己的 Javascript 添加到另一个网站 - How to add your own Javascript to another website 如何在Google Chrome Javascript控制台中编写和运行脚本? - How to write and run scripts in the Google Chrome Javascript Console? 如何在不编写自己的 API 的情况下读取 javascript 中的 sqlite 信息? - How to read in sqlite information in javascript without writing your own API? 如何在另一个 javascript 中创建然后使用您自己的 function - how to create and then use your own function inside another javascript 如何打开网页并在其上运行JavaScript? - How to open a webpage and run your JavaScript on it? 我如何链接您的 google chrome 扩展程序和 c # 应用程序 - How i can to link your google chrome extension and c # application Google Chrome扩展程序如何退出自己的后台进程? - How can a Google Chrome extension exit its own background process? 如何在onload事件之前运行JavaScript代码段(Google Chrome扩展程序) - How to run JavaScript snippet right before onload event(Google Chrome Extension) 如何为谷歌折线图/谷歌折线图传奇操纵编写自己的自定义图例 - How to write your own custom legends for google line chart/ Google line chart legend manipulation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM