简体   繁体   English

父文档是否可以读取Shadow DOM元素的内容?

[英]Is it possible for a parent document to read the content of Shadow DOM elements?

I'd like to run a bookmarklet to capture the current state of a document (web page) as HTML. 我想运行一个书签,以HTML格式捕获文档(网页)的当前状态。 The document is built using Polymer, so most of the elements are inside shadow roots, which means that their contents are not included in the output of document.body.innerHTML . 该文档是使用Polymer构建的,因此大多数元素都在阴影根内部,这意味着它们的内容未包含在document.body.innerHTML的输出中。

Is it possible to export a JavaScript-generated document as HTML, including the content of Shadow DOM elements? 是否可以将JavaScript生成的文档导出为HTML,包括Shadow DOM元素的内容?

What you want is to capture the composed/rendered dom tree. 您要捕获的是合成/渲染的dom树。 Here are a few examples of doing this that may be useful: 以下是一些可能有用的示例:

The latter shows the <content> , which is probably not what you want. 后者显示<content> ,可能不是您想要的。 But you could easily modify it to only contain the rendered nodes. 但是您可以轻松地对其进行修改,使其仅包含渲染的节点。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM