Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support optional document isolation #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/dom/createShadowRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ interface HTMLShadowDOMElement extends HTMLDivElement {
* from the parent site's styles to prevent conflicts.
* @param id the id of the shadow root.
* @param options the optional options for the shadow root.
* @param isolate whether or not to isolate the extension's document flow from the parent site's document flow.
* @returns A Div that represents the shadow root with some additional methods added to it.
*/
export function createShadowDOM(id: string, options?: ShadowRootInit): HTMLShadowDOMElement {
export function createShadowDOM(id: string, options?: ShadowRootInit, isolate = false): HTMLShadowDOMElement {
const html = document.querySelector('html');
if (!html) {
throw new Error('Could not find html element');
Expand All @@ -47,5 +48,8 @@ export function createShadowDOM(id: string, options?: ShadowRootInit): HTMLShado
};

html.appendChild(div);

if(isolate) document.body.style.isolation = 'isolate';

return div as HTMLShadowDOMElement;
}
Loading