Currently I am trying to inject some HTML onto Youtube's Page with a chrome extension that I am working on. They use custom HTML on their page and so I am creating custom DOM Nodes like theirs.
const channelSection = document.createElement("ytd-rich-section-renderer");
However, when I execute the above node I do not see my injected HTML anywhere on the page. To bug test this, I instead switched out the tag name for a basic div tag and it worked then.
For reference, I was looking at this other stackoverflow question to accomplish my goal. Thanks for the help!
Edit: Thanks for all the responses! So after reloading the extension a couple of times, I can actually see my custom HTML injected in the page via the console.
content.js
const ce = function(tag) {
return document.createElement(tag)
}
const channelSection = ce("ytd-rich-section-renderer");
channelSection.classList.add("style-scope", "ytd-rich-grid-renderer");
let content = ce("div");
content.classList.add("style-scope", "ytd-rich-section-renderer");
let subContent = ce("ytd-rich-shelf-renderer");
subContent.classList.add("style-scope", "ytd-rich-section-renderer");
let dismiss = ce("div");
dismiss.setAttribute("id", "dismissable");
dismiss.classList.add("style-scope", "ytd-rich-shelf-renderer");
// Heading
let richShelf = ce("div");
richShelf.setAttribute("id", "rich-shelf-header");
richShelf.classList.add("style-scope", "ytd-rich-shelf-renderer");
// Put Cards In here
let contents = ce("div");
contents.setAttribute("id", "contents");
contents.classList.add("style-scope", "ytd-rich-shelf-renderer");
dismiss.appendChild(richShelf);
dismiss.appendChild(contents);
subContent.appendChild(dismiss);
content.appendChild(subContent);
channelSection.appendChild(content);
// This works
let mainPage = document.querySelector("#contents");
mainPage.prepend(channelSection);
Now my main issue that is I only see the channelSection and content nodes on the page. Am I appending the DOM nodes incorrectly possibly?