shadow-dom

How to create a cross-browser sub document with iframe or shadow dom?

余生长醉 提交于 2019-11-29 09:11:21
I want to create a totally encapsulated sub-document in JavaScript, with its own <head> , <body> , styles, html, and js. Basically a shadow dom, or an iframe, but without an src attribute. Though I love the idea of shadow dom, its support is very low, and thus is not ready for prime time. So I have been working on creating an iframe, but have been hitting various road-blocks along the way. Here is a jsFiddle demonstrating my various attempts. The iframe cannot exist in the dom. This part is critical. To clarify, it is okay if it momentarily exists in the dom, but it must be able to be

Need help understanding the Shadow DOM

若如初见. 提交于 2019-11-29 06:35:53
Reading through articles and tutorials about the Shadow DOM, I came across a description which confused me a bit: "Shadow DOM refers to the ability of the browser to include a subtree of DOM elements into the rendering of a document, but not into the main document DOM tree." So a Shadow tree is not part of the DOM tree? But the browser will still see it and render its contents? From the Shadow DOM spec, A document tree is a node tree whose root node is a document. Any element can host zero or one associated node trees, called a shadow tree . A shadow host is an element that hosts one shadow

What is the difference between open and closed shadow DOM encapsulation mode?

∥☆過路亽.° 提交于 2019-11-28 23:24:34
I want to create a shadow DOM for an element so I can display elements for a Chrome extension without the page styles affecting them. When I looked at the documentation for Element.createShadowRoot I saw it was deprecated so I checked out Element.attachShadow . It said I had to provide an encapsulation mode but did not explain what the different modes do. I searched a bit but I wasn't able to find anything clearly explaining what the difference was. What is the difference between the modes and which one should I use for what I am trying to achieve? With the open mode you can access the Shadow

Click event not firing when React Component in a Shadow DOM

回眸只為那壹抹淺笑 提交于 2019-11-28 20:28:35
I have a special case where I need to encapsulate a React Component with a Web Component. The setup seems very straight forward. Here is the React Code: // React Component class Box extends React.Component { handleClick() { alert("Click Works"); } render() { return ( <div style={{background:'red', margin: 10, width: 200, cursor: 'pointer'}} onClick={e => this.handleClick(e)}> {this.props.label} <br /> CLICK ME </div> ); } }; // Render React directly ReactDOM.render( <Box label="React Direct" />, document.getElementById('mountReact') ); HTML: <div id="mountReact"></div> This mounts fine and the

How can I tell if an element is in a shadow DOM?

人走茶凉 提交于 2019-11-28 18:16:07
I have a project where I'm using the shadow DOM natively (not through a polyfill). I'd like to detect if a given element is contained within a shadow DOM or a light DOM. I've looked through all of the properties on the elements, but there don't seem to be any which vary based on the type of DOM an element is in. How can I determine if an element is part of a shadow DOM or a light DOM? Here is an example of what is considered "shadow DOM" and "light DOM" for the purpose of this question. (light root) • Document (light) • HTML (light) | • BODY (light) | • DIV (shadow root) | • ShadowRoot (shadow

selenium webdriver (chromedriver) and accessing shadow dom

懵懂的女人 提交于 2019-11-28 14:20:22
I'm testing out a new application that uses shadow dom like so: #shadow-root (open) <div class="th_filePicker"> <div class="th_fp_header"> <div class="th_fp_title" role="heading" aria-level="1" data-l10n-id="th_fp_title">Select Image</div> <div class="th_fp_Close"><button class="close-popup" data-l10n-id="close_popup" title="Close"></button></div> </div> </div> Does anyone have any idea on how I can access the elements in the file picker control - specifically, the close icon? One way would be to use a piercing CSS selector ( /deep/ or >>> ). Though it's not supported by all the browsers and

Dart, why does using innerHtml to set shadow root content work but appendHtml doesn't?

别来无恙 提交于 2019-11-28 11:12:45
问题 I have made this Gist to show the issue but essentially I have found that using shadowRoot.innerHtml = '...' works but using shadowRoot.appendHtml('...') doesn't work, it causes the console warning Removing disallowed element <STYLE> which I can't explain. Anyone know if this is simple the way it is meant to be or is it specific to Dart? 回答1: Removing disallowed element indicates that you need a NodeValidator. shadowRoot.append( new document.body.createFragment('....'), validator: new

How to query elements within shadow DOM from outside in Dart?

守給你的承諾、 提交于 2019-11-28 10:55:01
How can I select nodes within shadow DOM? Consider the following example: structure of "unshadowed" DOM <app-element> #shadow-root <h2></h2> <content> #outside shadow <h2></h2> </content> <ui-button> #shadow-root <h2></h2> </ui-button> </app-element> index.html <body> <app-element> <!-- OK: querySelect('app-element').querySelect('h2') --> <!-- OK: querySelect('app-element h2') --> <!-- There is no problem to select it --> <h2>app-element > content > h2</h2> </app-element> </body> templates.html <polymer-element name="ui-button" noscript> <template> <!-- FAIL: querySelect('app-element::shadow

Composing v1 nested web components

自作多情 提交于 2019-11-28 10:03:07
I'm new to webcomponents. Since v1 of webcomponents is available, I'm starting there. I have read various posts around the web about them. I'm particularly interested in composing them correctly. I have read about slots and have them working, although my efforts have not resulted in slotted webcomponents that work the way I expected. If I have compose nested web components like this, the DOM from the nested/slotted webcomponent does not get inserted in the slot of the parent: <parent-component> <child-component slot="child"></child-component> </parent-component> And here's the parent

How to access host element from within the shadow root using Shadow DOM v1?

。_饼干妹妹 提交于 2019-11-28 09:04:27
问题 Given an element contained in a shadow root, how can I get to the element that hosts the said shadow root? Is there a single way to accomplish this regardless of where an element is in the tree (i.e. given a reference to either element2 or element3 , get the reference to element1 )? element1 └ #shadow-root └ element2 └ element3 回答1: For Shadow DOM v1, you may use the getRootNode() method. Then get the host attribute: event.target.getRootNode().host 回答2: You can keep iterating parentNode until