Skip to content

Commit

Permalink
Remove content_script inject function for now
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Nov 26, 2024
1 parent 83860ea commit c84c11e
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions programs/develop/webpack/plugin-css/common-style-loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,50 @@ export interface StyleLoaderOptions {
loader?: string
}

function whereToInsertStyleTag(element: HTMLElement) {
// Function to check if the shadow root exists
const insertElement = () => {
// @ts-expect-error - global reference.
const shadowRoot = window.__EXTENSION_SHADOW_ROOT__
// function whereToInsertStyleTag(element: HTMLElement) {
// // Function to check if the shadow root exists
// const insertElement = () => {
// // @ts-expect-error - global reference.
// const shadowRoot = window.__EXTENSION_SHADOW_ROOT__

if (shadowRoot) {
shadowRoot.appendChild(element)
// if (shadowRoot) {
// shadowRoot.appendChild(element)

if (process.env.EXTENSION_ENV === 'development') {
console.log('Element inserted into shadowRoot')
}
} else {
document.head.appendChild(element)
if (process.env.EXTENSION_ENV === 'development') {
console.log('Element inserted into document.head')
}
}
}
// if (process.env.EXTENSION_ENV === 'development') {
// console.log('Element inserted into shadowRoot')
// }
// } else {
// document.head.appendChild(element)
// if (process.env.EXTENSION_ENV === 'development') {
// console.log('Element inserted into document.head')
// }
// }
// }

// If the shadowRoot is already available, insert immediately
// @ts-expect-error - global reference.
if (window.__EXTENSION_SHADOW_ROOT__) {
insertElement()
return
}
// // If the shadowRoot is already available, insert immediately
// // @ts-expect-error - global reference.
// if (window.__EXTENSION_SHADOW_ROOT__) {
// insertElement()
// return
// }

// Use MutationObserver to wait for the shadow root to be available
const observer = new MutationObserver(() => {
// @ts-expect-error - global reference.
if (window.__EXTENSION_SHADOW_ROOT__) {
insertElement()
observer.disconnect() // Stop observing once the shadow root is found
} else {
// Disconnect the observer if the shadow root is not found after 5 seconds
setTimeout(() => {
observer.disconnect()
}, 5000)
}
})
// // Use MutationObserver to wait for the shadow root to be available
// const observer = new MutationObserver(() => {
// // @ts-expect-error - global reference.
// if (window.__EXTENSION_SHADOW_ROOT__) {
// insertElement()
// observer.disconnect() // Stop observing once the shadow root is found
// } else {
// // Disconnect the observer if the shadow root is not found after 5 seconds
// setTimeout(() => {
// observer.disconnect()
// }, 5000)
// }
// })

// Observe changes to the `document.body` or `document.head`
observer.observe(document.body, {childList: true, subtree: true})
}
// // Observe changes to the `document.body` or `document.head`
// observer.observe(document.body, {childList: true, subtree: true})
// }

export async function commonStyleLoaders(
projectPath: string,
Expand All @@ -67,9 +67,9 @@ export async function commonStyleLoaders(
? miniCssLoader
: {
loader: require.resolve('style-loader'),
options: {
insert: whereToInsertStyleTag
}
// options: {
// insert: whereToInsertStyleTag
// }
},
{
loader: require.resolve('css-loader'),
Expand Down

0 comments on commit c84c11e

Please sign in to comment.