Vertex Google Chat Bot Shadow Dom Penetration

I have been trying and failing to penetrate the shadow-dom of the Google Vertex Chat Bot we are building at work, I need to style inside it. I Have tried many things, I threw in the suggestions my boss gave me from chat GPT that she insists should work. Thats to say I hav no one I work with who has ever worked with a shadow-dom so I am on my own here. I have watched a few videos but most seem to just show you how to build your own, not penetrate and existing one. Any guidance would be of help. <3

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Vertex Backup</title>
  <meta name="description" content="Webpage for xxxx">
  <link rel="stylesheet" href="assets/css/style.css">
  <script src="assets/js/vertex.js"></script>
  <script src="https://cloud.google.com/ai/gen-app-builder/client?hl=en_US"></script>
  <style type="text/css">
    .grecaptcha-badge {
      visibility: hidden;
    }
  </style>
</head>

<body> <!-- Widget JavaScript bundle -->
  <div class="host" id="host">
    <gen-search-widget configId="numbers" triggerId="searchWidgetTrigger">
    </gen-search-widget>
    <input id="searchWidgetTrigger" type="button" value="Try a POC AI chatbot" disabled />
    <div class="userConsentCheckbox" id="userConsent">
      Placeholder for the dynamically created checkbox
    </div>
  </div>
</body>

</html>

document.addEventListener("DOMContentLoaded", function () {
  console.log("linked");

  // Step 1: Create a Shadow DOM
  const host = document.getElementById("host");
  if (host) {
    const shadowRoot = host.attachShadow({ mode: "open" });

    // Step 2: Add some content to the Shadow DOM
    shadowRoot.innerHTML = `
      <style>
         .content {
            background: blue;
        }
      </style>
    `;

    // Step 3: Access the Shadow DOM
    const shadowContent = shadowRoot.querySelector(".content");
    if (shadowContent) {
      console.log(shadowContent.textContent); // Output: Inside Shadow DOM
    } else {
      console.error("Shadow DOM content not found.");
    }
  } else {
    console.error("Host element not found.");
  }

  console.log("inside function");

  // Create and append the button
  const aiButton = document.createElement("input");
  aiButton.type = "button";
  aiButton.id = "searchWidgetTrigger";
  aiButton.value = "Try a POC AI chatbot";
  aiButton.disabled = true; // Disabled by default
  document.body.appendChild(aiButton);

  // Create and append the container for the checkbox
  const aiContainer = document.createElement("div");
  aiContainer.className = "userConsentCheckbox";
  aiContainer.id = "userConsent";
  document.body.appendChild(aiContainer);

  // Create checkbox dynamically
  const aiCheckbox = document.createElement("input");
  aiCheckbox.type = "checkbox";
  aiCheckbox.id = "userConsentCheckbox";
  aiCheckbox.className = "userConsentCheckbox";
  aiCheckbox.checked = false; // Unchecked by default

  // Create label for the checkbox
  const aiLabel = document.createElement("label");
  aiLabel.htmlFor = "userConsentCheckbox"; // Set the label 'for' attribute
  aiLabel.appendChild(aiCheckbox);
  aiLabel.appendChild(document.createTextNode(" Consent to terms of use"));
  console.log(aiLabel);

  // Append label to container
  if (aiContainer) {
    aiContainer.appendChild(aiLabel);
    console.log("ai-container");

    // Add event listener to checkbox
    aiCheckbox.addEventListener("change", function () {
      aiButton.disabled = !this.checked;
      console.log("Checkbox state changed");
    });

    // Ensure the button is disabled initially
    aiButton.disabled = !aiCheckbox.checked;
  } else {
    console.error("Container element not found.");
  }

  // Create and configure the gen-search-widget element dynamically
  const genSearchWidget = document.createElement("gen-search-widget");
  genSearchWidget.setAttribute(
    "configId",
    "numbers"
  );
  genSearchWidget.setAttribute("triggerId", "searchWidgetTrigger");
  document.body.appendChild(genSearchWidget);
  
  //This was an attempt that didn't do what I wanted
  // Access the shadow DOM
  // genSearchWidget.addEventListener("click", () => {
  //   const genSearchShadowRoot = genSearchWidget.shadowRoot;
  //   if (genSearchShadowRoot) {
  //     const shadowContent = genSearchShadowRoot.querySelector(".content"); // Change this to the element you want to manipulate
  //     console.log("Shadow DOM!");
  //     if (shadowContent) {
  //       shadowContent.textContent = "Shadow DOM Content Modified!";
  //       console.log("Shadow DOM Content Modified!");
  //     } else {
  //       console.log("Element not found in shadow DOM.");
  //     }
  //   } else {
  //     console.log("Shadow root not found.");
  //   }
  // });
});

CHAT GPTS SUGGESTIONS

  1. Internal Styling: You can include a <style> tag directly inside the shadow DOM. This is the most common method as it keeps the styles encapsulated within the component. Here’s an example:
class MyComponent extends HTMLElement {
  constructor() {
    super();
    const shadow = this.attachShadow({mode: 'open'});
    shadow.innerHTML = `
      <style>
        p {
          color: blue;
        }
      </style>
      <p>Hello, Shadow DOM!</p>
    `;
  }
}
customElements.define('my-component', MyComponent);

In this example, a <p> element inside the shadow DOM is styled directly by CSS within the same shadow root.

  1. External Stylesheets: You can also link external stylesheets within the shadow DOM. This can be handy if you have common styles you wish to reuse across multiple components:
class MyComponent extends HTMLElement {
  constructor() {
    super();
    const shadow = this.attachShadow({mode: 'open'});
    shadow.innerHTML = `
      <link rel="stylesheet" href="/styles/component-styles.css">
      <p>Hello, Shadow DOM!</p>
    `;
  }
}
customElements.define('my-component', MyComponent);

Here, component-styles.css will only apply to the contents of the shadow DOM where it’s included.

  1. CSS Custom Properties (Variables): While regular styles don’t penetrate the shadow boundary, CSS custom properties do. This allows you to define a consistent theme or style externally that can be applied inside the shadow DOM.
/* In your global stylesheet */
:root {
  --main-color: green;
}
 
/* Inside your shadow DOM */
<style>
  p {
    color: var(--main-color);
  }
</style>

This way, the paragraph inside the shadow DOM will use the color defined by the --main-color variable.

  1. ::part and ::theme (Part of CSS Shadow Parts): If you need to style specific parts of your shadow DOM from outside, you can expose parts of the shadow DOM for styling using the ::part selector. This requires marking parts of your shadow DOM with the part attribute.
// Inside your shadow DOM definition
shadow.innerHTML = `
  <style>
    p {
      color: blue;
    }
  </style>
  <p part="highlight">Hello, Shadow DOM!</p>
`;
 
/* In your global stylesheet */
my-component::part(highlight) {
  color: red;
}

In this example, the <p> element can be styled from outside the shadow DOM because it’s exposed via the part="highlight" attribute.

These methods provide flexibility in styling components that use shadow DOM while maintaining the benefits of style encapsulation.

Sorry if this was too much info, it was just the easiest way to show what I am working with

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật