Skip to content

Conversation

@lenacohen
Copy link
Contributor

@lenacohen lenacohen commented Feb 27, 2025

Comment on lines 406 to 410
let widgetFrame = document.createElement('iframe');
let shadowHost = document.createElement("div");
let shadowRoot = shadowHost.attachShadow({ mode: "closed" });
shadowRoot.appendChild(widgetFrame);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could replace the iframe with the shadowHost, but didn't see a benefit to doing that in the spirit of minimizing change. Let me know if you think I should.

Copy link
Member

@ghostwords ghostwords Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is probably no point to keeping the iframe but there is also no harm in it? And we do need some way to select the correct placeholder in tests, but we could use the placeholder's text or className or something else inside the shadow root to do it instead. I don't have a preference either way, but maybe testing against widgets will present reasons for removing the iframe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll leave it as is for now.

@ghostwords ghostwords added the widgets Click-to-activate placeholders for blocked but potentially useful social buttons/widgets label Feb 27, 2025
Copy link
Member

@ghostwords ghostwords left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This round of feedback is about testing updates. I still have to test against real-world widget examples.

), widgetsJson)

def switch_to_shadow_host_frame(self, selector):
shadow_host = self.find_el_by_css("div.widget-shadow-host")
Copy link
Member

@ghostwords ghostwords Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than exposing an identifier for tests, let's loop over all the divs and look for one with a shadow host that contains the iframe we want. (The line above assumes the first matching div will be the one we want, which seems to work at the moment but may not in the future.)

Something like,

    def switch_to_placeholder_frame(self, selector):
        for el in self.driver.find_elements(By.CSS_SELECTOR, "div"):
            try:
                shadow_root = el.shadow_root
            except NoSuchShadowRootException:
                continue
            iframe = shadow_root.find_element(By.CSS_SELECTOR, selector)
            self.driver.switch_to.frame(iframe)
            return
        raise NoSuchElementException("Failed to find placeholder frame")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works, thank you!

@lenacohen lenacohen force-pushed the widget-iframe-inside-shadow-dom branch from 02e4cc9 to ca9d736 Compare April 28, 2025 20:49
lenacohen and others added 3 commits April 29, 2025 10:54
Closed shadow roots interfere with testing, and possibly accessibility: https://jschof.dev/posts/2024/4/web-components-and-you-7/. We don't need to prevent the placeholder from being accessed by outside JS to prevent the known UI bugs
As it adds unwanted space below the placeholder on livestream.eff.org
@ghostwords ghostwords force-pushed the widget-iframe-inside-shadow-dom branch from 7390807 to 42ee2b4 Compare May 14, 2025 18:11
@ghostwords ghostwords changed the title Fix widget styling bugs Fix widget styling issues by using shadow DOM May 14, 2025
@ghostwords
Copy link
Member

Is there anything we can do for cases like https://www.twz.com/sea/ukraine-situation-report-russian-navy-creating-new-drone-regiments-in-wake-of-enemy-successes where our placeholder is newly hidden because it no longer overrides anything with a lower z-index?

Using shadow DOM isolates placeholder styles from page styles, which is great. Our z-index no longer working is less great though. While it's nice to no longer overlap navbars, I think it's a poor tradeoff if it means our placeholders can now be more easily hidden by site error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

widgets Click-to-activate placeholders for blocked but potentially useful social buttons/widgets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants