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

#8220: Inject sandbox into document root instead of body #8777

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 3 deletions src/utils/domUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ export async function setAnimationFrameInterval(
}

/**
* Wait for the document body element to be present.
* Wait for the document root element to be present.
*/
export async function waitForBody(): Promise<void> {
while (!document.body) {
export async function waitForDocumentRoot(): Promise<void> {
while (!document.documentElement) {
// eslint-disable-next-line no-await-in-loop -- Polling pattern
await sleep(20);
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/injectIframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import pDefer from "p-defer";
import pTimeout from "p-timeout";
import shadowWrap from "@/utils/shadowWrap";
import { waitForBody } from "@/utils/domUtils";
import { waitForDocumentRoot } from "@/utils/domUtils";

const TIMEOUT_MS = 3000;

Expand Down Expand Up @@ -47,8 +47,8 @@ async function _injectIframe(
Object.assign(iframe.style, style);

// The body might not be available yet
await waitForBody();
document.body.append(shadowWrap(iframe));
await waitForDocumentRoot();
document.documentElement.append(shadowWrap(iframe));
Copy link
Contributor

@twschiller twschiller Jul 8, 2024

Choose a reason for hiding this comment

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

Update "the body" comment. Add comment explaining where we're adding to the documentElement vs. the body

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for catching that


await iframeLoad;

Expand Down
Loading