-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not rendering shadow dom elements #430
Comments
You'd probably need to look into the node parser (https://github.com/niklasvh/html2canvas/blob/master/src/nodeparser.js) and check whether a node has a shadow DOM before queueing to render it. |
Here? negativeZindex.concat(nonInlineNonPositionedDescendants).concat(nonPositionedFloats) Can you give me a hint about next step? :) |
You'll need to to correctly order the nodes there for rendering (for more information see http://www.w3.org/TR/CSS21/visuren.html#z-index), but prior to that you'll need to fetch the shadow dom nodes for each context stack. |
@fernandezpaco have you looked into this any further? I'm pretty interested in this feature as well. |
@niklasvh Did somebody fix this issue? I'd be interested in using the library, but I'm using Polymer and ShadowDOM and it's not working for me. |
The above lines in @niklasvh can you confirm if this is right approach? |
Unfortunately this also fails because of the way html2canvas tag the node to be rendered and then clone the entire document and inability to pierce shadow-dom using Even when tagging the node up to the document root the tagging seems to be lost after the first shadow dom during the cloning. Not sure what's happening there. |
@niklasvh can you share a link (https://github.com/niklasvh/html2canvas/blob/master/src/nodeparser.js) again, it shows 404. |
@niklasvh : We are facing the same issue (unable to render SHADOW-DOM), let us know if anyone had worked on it. |
@srajabhoj Following version 1.0.0 rewrite, it's probably https://github.com/niklasvh/html2canvas/blob/master/src/NodeParser.js |
hey anyone got solution for this, also I am facing to capture images div which have scroll, please suggest way, any lead will be helpful |
My workaround is to clone the content and css that as you want to render a HTMLElement , then append it to However, it is very hard to do if you included many shadow-dom element in the content you want to render. Still have no idea on that. Here is my code in Angular const newRef = this.renderRef.nativeElement.cloneNode(true);
this.renderer.setStyle(newRef, 'filter', 'opacity(0)');
this.renderer.appendChild(document.body, newRef);
html2canvas(newRef).then(canvas => {
if (canvas.toBlob) {
canvas.toBlob(
blob => {
fileSaver.saveAs(blob, 'image.jpg');
this.renderer.removeChild(document.body, newRef);
alert('Image has been downloaded to your device');
},
'image/jpg',
0.8
);
}
}); |
@Jeffen this was very helpful, thank you! Also the file saver thing was of great help. Just in case anyone wonders how this works, I did it like this:
|
Is there any update on this issue? |
The The "composed tree" (or "flat tree" in other places) is described in the original ShadowDOM draft (click the "collapse" button in the red box to stay on that page instead of re-directing to the new page). Feel free to ask me if you're not familiar with any concept. If all ShadowRoots have If we want to support ShadowRoots with Once we know how to traverse the "composed tree" in general, then we'd need to update |
Slotted content could be trickier to handle. You'd need to find the corresponding slots in order to render the content into the correct place. <!--my-component-->
<div><slot name="some-region"></slot></div>
<slot></slot> <!--my-app-->
<my-component>
Default Slotted Content
<button slot="some-region">Button</button>
</my-component> |
Hi, did anyone reached a solution for this shadow dom problem? |
I don't think anyone has tried to implement this yet. Basic steps:
When traversing later, children of an element with a shadow root will be skipped if an element is seen to have a root (detected with the I'm not familiar with the html2canvas impl, but if needed, functions like |
I went ahead and made Shadow DOM composed tree traversal example, in case it helps someone eventually: https://codepen.io/trusktr/pen/0d5b3731fcb2ebe54f99316bfb55b117 The output shows the nodes of the composed tree in depth-first preorder (verify by inspecting the elements). If there are any parts of |
Hello! Has anybody tried this implementation with slots? I am getting the shadow root, but not the content inside the slot. https://stackblitz.com/edit/multi-slot-web-component-uwaya7?file=index.html "World" does not show which is in the slot. Thanks, |
I am working on a new project using polymer webcomponents.
The problem is that html2canvas is not rendering the shadow dom
Can you please tell me where should i work on your library in order to have support for webcomponents?
The text was updated successfully, but these errors were encountered: