Chrome 扩展:在内容脚本中获取页面变量 [英] Chrome Extension: Get Page Variables in Content Script
问题描述
有没有办法从 Google Chrome 内容脚本中检索页面的 javascript 变量?
Is there any way to retrieve a page's javascript variables from a Google Chrome Content Script?
推荐答案
如果确实需要,可以在页面的 DOM 中插入一个 元素;
元素中的代码将被执行,并且该代码将可以访问窗口范围内的 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屋!