Skip to content

Commit

Permalink
updated createShadowRoot to not get overwritten by react renders
Browse files Browse the repository at this point in the history
  • Loading branch information
sghsri committed Mar 29, 2024
1 parent 7da1090 commit 47e78d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chrome-extension-toolkit",
"version": "0.0.60",
"version": "0.0.61",
"description": "A template for creating npm packages using TypeScript and VSCode",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
13 changes: 10 additions & 3 deletions src/dom/createShadowRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* An extension of HTMLDivElement that represents a shadow root for use within an Extension Content Script.
*/
interface HTMLShadowDOMElement extends HTMLDivElement {
shadowRoot: ShadowRoot;
shadowRoot: ShadowRoot & {
INJECTION_POINT: HTMLDivElement;
};
/**
* Adds a style sheet to the shadow root.
* @param path the path to the style sheet relative to the extension's root directory. uses chrome.runtime.getURL to get the absolute path.
Expand Down Expand Up @@ -31,12 +33,17 @@ export function createShadowDOM(id: string, options?: ShadowRootInit): HTMLShado
...(options || {}),
});

div.addStyle = async function (path: string) {
const INJECTION_POINT = document.createElement('div');
INJECTION_POINT.id = 'INJECTION_POINT';
div.shadowRoot.appendChild(INJECTION_POINT);
div.shadowRoot.INJECTION_POINT = INJECTION_POINT;

div.addStyle = async (path: string) => {
const style = await fetch(chrome.runtime.getURL(path));
const styleNode = document.createElement('style');
const parsedStyle = await style.text();
styleNode.textContent = parsedStyle;
this.shadowRoot.appendChild(styleNode);
div.shadowRoot.appendChild(styleNode);
};

html.appendChild(div);
Expand Down

1 comment on commit 47e78d1

@github-actions
Copy link

Choose a reason for hiding this comment

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

Lines Statements Branches Functions
Coverage: 9%
9.09% (27/297) 14.86% (11/74) 9.72% (7/72)

Please sign in to comment.