简体   繁体   English

无法在内容脚本Firefox插件中获得作用域

[英]Unable to get scope in content script Firefox Addon

I am developing an addon for Firefox. 我正在为Firefox开发插件。 In a content script file I have the line 在内容脚本文件中,我有一行

angular.element(document.getElementById("angularAppDiv")).scope(); 

it returns null . 它返回null However if I type the same line into the browser console, I get the scope object? 但是,如果我在浏览器控制台中键入同一行,是否得到了范围对象? Could someone point out what's happening and why? 有人可以指出发生了什么事,为什么?

By default, content scripts loaded by add-ons and scripts loaded by web pages are insulated from each other: 默认情况下,加载项加载的内容脚本和网页加载的脚本相互隔离:

  • content scripts can't interact directly with page scripts or access JavaScript objects they create 内容脚本不能直接与页面脚本交互或访问它们创建的JavaScript对象
  • page scripts can't interact directly with content scripts or access objects they create. 页面脚本不能直接与内容脚本交互或访问它们创建的对象。

What you could do is to insert this script tag from content script into the page: 您可以做的是将此脚本标记从内容脚本插入页面:

document.head.innerHTML = document.head.innerHTML + '<script> console.log(angular.element(document.getElementById("angularAppDiv")).scope());</script>';

Check this link for more info. 检查链接以获取更多信息。

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

相关问题 Firefox插件构建器-无法使内容脚本正常工作 - Firefox addon builder--can't get the content script to work 在Firefox插件内容脚本中访问窗口对象? - Accessing the window object in Firefox addon content script? firefox插件中面板内容脚本和页面内容脚本之间的localStorage - localStorage between panel content script and page content script in firefox addon 在firefox插件中将每个顶级域用于内容脚本匹配 - Use every top level domain for content script matches in firefox addon 主脚本和内容脚本之间的数据交换— Firefox插件SDK - Data interchange between main and content script — Firefox Addon SDK firefox扩展从内容脚本调用addon函数 - firefox extension call to addon function from content script FireFox SDK插件-禁用/卸载时“分离内容脚本”? - FireFox SDK Addon - “Detach content script” on disable/unload? 如果任何地方都有“ return”语句,则Firefox插件的内容脚本将无法运行 - Firefox addon's content script will not run if there is a “return” statement anywhere Firefox插件:让内容脚本检索由插件脚本存储的数据(如果可能,使用上下文菜单) - Firefox addon: Have content script retrieve data stored by addon script (using a context menu if possible) 如何从Firefox插件获取iframe所显示页面的内容? - How from firefox addon to get the content of iframe the displayed page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM