Skip to content

Commit

Permalink
feat: Allow giving a css selector where the sandboxes should be stored (
Browse files Browse the repository at this point in the history
  • Loading branch information
indykoning authored Apr 12, 2023
1 parent d316982 commit da44d00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/main/snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ export function snippet(
libPath +
'partytown-' +
(isAtomics ? 'atomics.js?v=_VERSION_' : 'sandbox-sw.html?' + Date.now());
doc.body.appendChild(sandbox);
let sandboxParent = doc.querySelector(config?.sandboxParent ?? 'body');
if(!sandboxParent) {
console.warn(`Partytown sandboxParent element was not found on the page!`);
sandboxParent = doc.body
}

sandboxParent.appendChild(sandbox);
}

function fallback(i?: number, script?: HTMLScriptElement) {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ export interface PartytownConfig {
* https://partytown.builder.io/forwarding-events
*/
forward?: PartytownForwardProperty[];
/**
* The css selector where the sandbox should be placed.
* Default: body
*/
sandboxParent?: string;
mainWindowAccessors?: string[];
/**
* Rarely, a script will add a named function to the global scope with the
Expand Down

1 comment on commit da44d00

@vercel
Copy link

@vercel vercel bot commented on da44d00 Apr 12, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.