{
// Proxy the default addShadow method in order to transparently intercept
// attachShadow calls and store a reference to the shadow root object for
// later use.
//
// We store shadow root references in a WeakMap in order to ensure that we're
// not leaking data to other scripts on the page. Additionally, this
// implementation uses a WeakMap to ensure that we don't keep references to
// shadow roots for nonexistent elements.
const shadowRootMap = new WeakMap();
const attachShadow = Element.prototype.attachShadow;
Element.prototype.attachShadow(function(options) {
const shadowRoot = attachShadow.call(this, options);
shadowRootMap.set(this, shadowRoot);
return shadowRoot;
});
// Use getShadowRoot to retrieve the shadow root of a custom element while
// iterating through DOM nodes or undefined.
function getShadowRoot(el) {
return shadowRootMap.get(el);
}
}
...
Element.prototype.attachShadow = function(options) {
const shadowRoot = attachShadow.call(this, options);
shadowRootMap.set(this, shadowRoot);
return shadowRoot;
};
...
--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/8d3a8391-6d86-460b-96ac-f940f37eaa95%40chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/65dc1d32-61a9-4aa4-939a-c262dc984d8dn%40chromium.org.