简体   繁体   English

尝试从Chrome扩展程序而不是从开发人员控制台访问gmail中的iframe时出现未定义错误

[英]I get undefined error when trying to access iframes in gmail from my chrome extension but not from the developer console

I'm making a chrome extension (content script) that will add text after the "More" in the top black bar in gmail. 我正在制作一个Chrome扩展程序(内容脚本),该扩展程序将在gmail顶部黑色栏中的“更多”后面添加文本。 Those elements are encapsulated in the canvas_frame iframe. 这些元件被封装在canvas_frame iframe中。

When I try to access those elements with: 当我尝试通过以下方式访问这些元素时:

document.getElementById('canvas_frame').contentWindow.document.getElementById('gbz').innerHTML = scr;

I get Uncaught TypeError: Cannot read property 'document' of undefined . 我收到Uncaught TypeError: Cannot read property 'document' of undefined But if I type that code directly into the chrome developer console it works. 但是,如果我直接在chrome开发人员控制台中键入该代码,它将可以正常工作。 Why is this? 为什么是这样? How can I access and modify that element from my chrome extension. 如何访问和从我的浏览器扩展程序修改该元素。

I'm new with javascript so I am likely missing something obvious. 我是新的JavaScript,所以我可能失去了一些东西明显。 Thanks. 谢谢。

尝试

document.getElementById('canvas_frame').contentDocument.document.getElementById('gbz').innerHTML = src;

I have built Chrome Extensions myself and have encountered this issued, there are a couple of ways to mitigate it, one is to run a timer loop in JS looking for #canvas_frame and stop it when you find it, the other is to listen for DOM node insert events and again, if the element you are looking for has been inserted, start doing what you want to do. 我自己构建了Chrome扩展程序,并遇到了此问题,有两种方法可以缓解它,一种是在JS中运行计时器循环以查找#canvas_frame并在找到它时将其停止,另一种方法是侦听DOM节点插入事件,如果已插入您要查找的元素,请再次执行该操作。

While canvas_frame has been the "content area" element for Gmail to interact with if that's what you need to do, currently (as of a few days ago) I've encountered instances of Google Apps Gmail that DO NOT have a content_frame, or rather, have one for an instant when the page loads and then it gets removed, I'm not sure what shenanigans Google is pulling, but since they don't provide an official API for making Gmail Chrome Extensions (so very unfortunately), we are at their mercy as Extension developers... 尽管canvas_frame一直是Gmail可以与之交互的“内容区域”元素,但目前(截至几天前),我遇到的Google Apps Gmail实例没有content_frame,或者,请在页面加载后立即将其删除,然后再将其删除。我不确定Google在拉扯什么恶作剧,但是由于它们没有提供用于制作Gmail Chrome浏览器扩展程序的官方API(因此非常遗憾),作为扩展开发人员摆布...

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

相关问题 如何从Selenium访问Chrome开发者控制台 - how do I access Chrome Developer Console from Selenium 尝试从Chrome扩展程序获取Cookie时出错 - Error Trying to Get Cookies From Chrome Extension 尝试从两个不同的 windows 访问时,Chrome 扩展程序崩溃? - Chrome extension crashes when trying to access from two different windows? 尝试从控制台获取我的 javascript 时出现未定义的消息 - Undefined message when trying to fetch my javascript from the console 当我试图确保我的 javascript 代码正常工作时,我在 Google Chrome 上的控制台上收到此错误 - I get this error on my console on Google Chrome when I am trying to make sure that my javascript code is working 通过Chrome扩展程序访问GMail API? 403禁止 - GMail API access from chrome extension? 403 Forbidden Chrome扩展程序:是否可以通过扩展程序访问$ 0(选定的控制台元素)? - Chrome extension: is there a ways to access the $0 (the selected console element) from an extension? 如何使用 Javascript 从 Chrome 扩展中获取每条 Gmail 邮件的 ID - How to get ID of each gmail message with Javascript from chrome extension 我的错误控制台中出现未定义的错误 - I get an undefined error in my error console 从Chrome开发人员工具控制台获取上次返回的值 - Get last returned value from Chrome developer tools console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM