Chrome扩展程序:在内容脚本中获取页面变量 [英] Chrome Extension: Get Page Variables in Content Script

查看:620
本文介绍了Chrome扩展程序:在内容脚本中获取页面变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过Google Chrome内容脚本检索页面的javascript变量?

Is there any way to retrieve a page's javascript variables from a Google Chrome Content Script?

推荐答案

如果确实需要,可以在页面的DOM中插入一个<script>元素. <script>元素中的代码将被执行,并且该代码将可以在窗口范围内访问JavaScript变量.然后,您可以使用data-属性并触发自定义事件,将它们传达回内容脚本.

If you really need to, you can insert a <script> element into the page's DOM; the code inside your <script> element will be executed and that code will have access to JavaScript variables at the scope of the window. You can then communicate them back to the content script using data- attributes and firing custom events.

听起来很尴尬?是的,这是有意为之的,出于这种原因,是出于serg引用的文档中的所有原因.但是,如果您确实需要这样做,则可以完成.请参见此处此处以获取更多信息.祝你好运!

Sound awkward? Why yes, it is, and intentionally so for all the reasons in the documentation that serg has cited. But if you really, really need to do it, it can be done. See here and here for more info. And good luck!

这篇关于Chrome扩展程序:在内容脚本中获取页面变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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