-
Hi, in my extension, I use the same css file <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="@/assets/style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="manifest.open_in_tab" content="true" />
<title data-locale="extension_name"></title>
</head>
<body>
<div id="app"></div>
<script type="module" src="main.ts"></script>
</body>
</html> When building the extension, the style.css lands in the However, I use the same css file also in an injection script with shadowRootUI like this: import { createApp } from 'vue'
import App from './App.vue'
import PrimeVue from 'primevue/config'
import { MyPreset } from '@/composables/presets'
import '@/assets/style.css'
export default defineContentScript({
registration: 'runtime',
matches: ['<all_urls>'],
cssInjectionMode: 'ui',
main(ctx) {
const primeVueTheme = {
theme: {
preset: MyPreset,
options: {
prefix: 'myPrefix',
},
},
}
// Define the UI
createShadowRootUi(ctx, {
name: 'injected-dialog',
position: 'inline',
anchor: 'body',
append: 'last',
onMount: (container) => {
// Define how the UI will be mounted inside the container
const app = createApp(App).use(PrimeVue, primeVueTheme)
app.mount(container)
return app
},
onRemove: (app) => {
// Unmount the app when the UI is removed
app?.unmount()
},
}).then((ui) => {
// Mount the UI
ui.mount()
})
},
}) This then results in an Thanks for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Yes, though it requires some workarounds. Put it in your public folder, or, if it needs to be processed by Vite, make it an unlisted CSS entrypoint. Then in your HTML pages, use a reference like In your content script, you'll have to add the CSS to the page manually by creating a async onMount(uiContainer, shadow) {
const url = browser.runtime.getURL('/<path-to-style>.css');
const myStyles = document.createElement('style');
const myStyle.textContent = await (await fetch(url)).text();
shadow.querySelector('head').append(myStyles);
// The rest of your code
} There are several reasons why fetching the CSS text content is better than using a link with a URL, but you could try that if you want. Mainly that the CSS needs to be loaded before the UI is mounted. Otherwise you see flashing styles and layout shifts. |
Beta Was this translation helpful? Give feedback.
Yes, though it requires some workarounds. Put it in your public folder, or, if it needs to be processed by Vite, make it an unlisted CSS entrypoint.
Then in your HTML pages, use a reference like
href="/<path-to-style>.css"
instead of use an alias or relative path.In your content script, you'll have to add the CSS to the page manually by creating a
link
orstyle
element yourself.There are several rea…