内容脚本中的页面变量 [英] Page variables in content script

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

问题描述

有什么方法可以从谷歌浏览器内容脚本中检索页面的JavaScript变量吗? 如果您确实需要,你可以在页面的DOM中插入< script> 元素;您的< script> 元素中的代码将被执行,并且代码将在窗口范围内访问JavaScript变量。然后,您可以使用 data - 属性并触发自定义事件,将它们传递回内容脚本。



听起来很尴尬吗?为什么是这样呢,serg引用的文档中的所有原因都是故意的。但如果你确实需要这样做,那么可以这样做。请参阅此处此处获取更多信息。祝你好运!


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

解决方案

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.

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!

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

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