在Google Chrome中保持控制台脚本的持久性 [英] Keep the console script persistent in Google Chrome

查看:513
本文介绍了在Google Chrome中保持控制台脚本的持久性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我想在Google Chrome控制台中使用的脚本。但是这个脚本将重新加载页面。有点像这样:

  setInterval(function(){location.reload();},3000); 

问题是,一旦它被重新加载,脚本停止并且控制台被清除。我尝试了保留登录导航选项:它保留了日志,但重新加载后脚本不会重新启动。



我应该怎么做?感谢:)

解决方案

实际上没有办法做到这一点。我发现的唯一可能的方法是开发一个Chrome的扩展,并将脚本放在它上面。每次加载目标页面时都会执行脚本,因此当您执行location.refresh()方法时,下次加载页面时,脚本将再次执行,等等。如果您希望在页面加载之间保留一些数据,则可以使用localStorage。



在此处查找更多信息 https://developer.chrome.com/extensions/getstarted

如何通过扩展插入脚本?: https://developer.chrome.com/extensions/content_scripts

请记住,扩展的范围与其他所以你不能直接从扩展中访问在页面本身中声明的JS变量或函数,但是你可以与DOM进行交互。祝你好运

I have a script I want to use in the Google Chrome console. But this script is going to reload the page. A bit like this :

setInterval(function(){location.reload();},3000);

The problem is, once it's reloaded, the script stops and the console is cleared. I tried the option "Preserve log on navigation" : it preserves the log, but the script doesn't restart after reloading.

How should I do ? Thanks :)

解决方案

There is no way to actually do that. The only possible way I found is to develop a Chrome' extension and place your script on it. Your script will be excecuted every time the target page is loaded, so when you execute the location.refresh() method , the next time the page is loaded your script will be executed all again and so on. If you wish to persist some data between page loads, then you can use localStorage.


Find more information here https://developer.chrome.com/extensions/getstarted
How to inject scripts via extensions ?: https://developer.chrome.com/extensions/content_scripts

remember that the scope of the extensions is isolated from the rest of the page, so you cant directly access JS variables or functions declared in the page itself from an extension BUT you can interact with the DOM. Good luck

这篇关于在Google Chrome中保持控制台脚本的持久性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆