在Firefox中通过插件访问完全开发的dom

发布于 2024-12-06 16:40:38 字数 107 浏览 0 评论 0原文

我需要查看页面的完全加载和开发的 dom,即在我的客户加载我的页面后,我希望他们能够单击火狐上的按钮,然后火狐将向我发送完全开发的 dom,以便我可以查看看看那里发生了什么。 谁能帮我指出正确的方向?

I need to see the fully loaded and devloped dom of a page, i.e after my client loads up my page I want them to be able to click a button on fire fox and then fire fox will send me the fully developed dom so I can look through and see what happened there.
Can anyone help point me to the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦一生花开无言 2024-12-13 16:40:38

首先你需要一个函数来知道 DOM 是否准备好。许多 Javascript 框架提供的功能,但是 参考此如果你需要一个纯js实现。
当 DOM 准备就绪时,按钮将启用供用户单击。
然后你可能有一个函数将 DOM 树序列化为字符串。由于 Mozilla 尚未实现加载和保存 DOM,请阅读这篇 MDN 文章以了解什么你想要的。
现在您可以将保存的 DOM 发送到您的 Web 服务。

//Code grabbed mostly from MDN article linked
var req = new XMLHttpRequest();
req.open("GET", "chrome://passwdmaker/content/people.xml", false); 
req.send(null);
var dom = req.responseXML;

var serializer = new XMLSerializer();
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
              .createInstance(Components.interfaces.nsIFileOutputStream);   
var file = Components.classes["@mozilla.org/file/directory_service;1"]
         .getService(Components.interfaces.nsIProperties)
         .get("ProfD", Components.interfaces.nsILocalFile);//get profile folder  
file.append("extensions");   // extensions sub-directory
file.append("{5872365E-67D1-4AFD-9480-FD293BEBD20D}");//GUID of your extension
file.append("myXMLFile.xml");   // filename
foStream.init(file, 0x02 | 0x08 | 0x20, 0664, 0);//write, create, truncate
serializer.serializeToStream(dom, foStream, "");//remember, dom is the DOM tree
foStream.close();

希望这会有所帮助!

First you need a function to know whether DOM is ready. A functionality provided by many Javascript frameworks, but refer this if you need a pure js implementation.
When the DOM is ready the button is enabled for the user to click.
Then you may have a function to serialize the DOM tree to a string. As Load and Save DOM is not yet implemented in Mozilla, read this MDN article to get to know what you want.
Now you can send the Saved DOM to your Web Service.

//Code grabbed mostly from MDN article linked
var req = new XMLHttpRequest();
req.open("GET", "chrome://passwdmaker/content/people.xml", false); 
req.send(null);
var dom = req.responseXML;

var serializer = new XMLSerializer();
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
              .createInstance(Components.interfaces.nsIFileOutputStream);   
var file = Components.classes["@mozilla.org/file/directory_service;1"]
         .getService(Components.interfaces.nsIProperties)
         .get("ProfD", Components.interfaces.nsILocalFile);//get profile folder  
file.append("extensions");   // extensions sub-directory
file.append("{5872365E-67D1-4AFD-9480-FD293BEBD20D}");//GUID of your extension
file.append("myXMLFile.xml");   // filename
foStream.init(file, 0x02 | 0x08 | 0x20, 0664, 0);//write, create, truncate
serializer.serializeToStream(dom, foStream, "");//remember, dom is the DOM tree
foStream.close();

Hope this would help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文