Getting Tailwind to work in content scripts

I'm following the instructions from https://docs.plasmo.com/quickstarts/with-tailwindcss, with the exception that I did not pnpm create plasmo --with-tailwindcss because my project was already started. However I did all the other stuff. I think I must be doing the getStyle export wrong? The style is not being injected. any idea what may be going wrong? This is my content script: contents/my-content-script.tsx
import type {
PlasmoCSConfig,
PlasmoCSUIJSXContainer,
PlasmoCSUIProps,
PlasmoRender
} from "plasmo"
import cssText from "data-text:~style.scss";
import type { PlasmoGetStyle } from "plasmo"

import type { FC } from "react"
import { createRoot } from "react-dom/client"
import CenterContent from "~components/center-content"

export const config: PlasmoCSConfig = {
matches: ["https://the-host-for-mycontent-script.com/*"] // ommited the host for this example
}

export const getStyle: PlasmoGetStyle = () => {

// This doesn't work. The style element doesn't show up?

const style = document.createElement("style")
style.textContent = cssText
return style

// This also doesn't work.

// const style = document.createElement("style")
// style.id = 'this-doesnt-show-up-on-the-page-anywhere'
// style.textContent = `
// .wtf {
// color: red !important;
// }
// `
// return style
}

export const getRootContainer = () =>
new Promise((resolve) => {
const checkInterval = setInterval(() => {
//
const xpath = `//h1[contains(text(),"this part works fine")]`;
const targetElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

if (targetElement) {
clearInterval(checkInterval);
const rootContainerParent = targetElement.parentNode?.parentNode?.parentNode as HTMLElement;

const rootContainer = document.createElement('div');
rootContainer.id = 'my-root';
rootContainer.classList.add('w-full', 'h-full', 'flex', 'flex-col');

rootContainerParent.replaceChildren(rootContainer)
resolve(rootContainer)
}
}, 137)
})

const PlasmoOverlay: FC<PlasmoCSUIProps> = () => {
return (
<>
<h1 className="text-bold text-2xl wtf">
------- This H1 shows up but the class styling doesn't work ------
</h1>
</>
)
}

export const render: PlasmoRender<PlasmoCSUIJSXContainer> = async ({
createRootContainer
}) => {
const rootContainer = await createRootContainer()
const root = createRoot(rootContainer)
root.render(<PlasmoOverlay />)
}

export default PlasmoOverlay
import type {
PlasmoCSConfig,
PlasmoCSUIJSXContainer,
PlasmoCSUIProps,
PlasmoRender
} from "plasmo"
import cssText from "data-text:~style.scss";
import type { PlasmoGetStyle } from "plasmo"

import type { FC } from "react"
import { createRoot } from "react-dom/client"
import CenterContent from "~components/center-content"

export const config: PlasmoCSConfig = {
matches: ["https://the-host-for-mycontent-script.com/*"] // ommited the host for this example
}

export const getStyle: PlasmoGetStyle = () => {

// This doesn't work. The style element doesn't show up?

const style = document.createElement("style")
style.textContent = cssText
return style

// This also doesn't work.

// const style = document.createElement("style")
// style.id = 'this-doesnt-show-up-on-the-page-anywhere'
// style.textContent = `
// .wtf {
// color: red !important;
// }
// `
// return style
}

export const getRootContainer = () =>
new Promise((resolve) => {
const checkInterval = setInterval(() => {
//
const xpath = `//h1[contains(text(),"this part works fine")]`;
const targetElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

if (targetElement) {
clearInterval(checkInterval);
const rootContainerParent = targetElement.parentNode?.parentNode?.parentNode as HTMLElement;

const rootContainer = document.createElement('div');
rootContainer.id = 'my-root';
rootContainer.classList.add('w-full', 'h-full', 'flex', 'flex-col');

rootContainerParent.replaceChildren(rootContainer)
resolve(rootContainer)
}
}, 137)
})

const PlasmoOverlay: FC<PlasmoCSUIProps> = () => {
return (
<>
<h1 className="text-bold text-2xl wtf">
------- This H1 shows up but the class styling doesn't work ------
</h1>
</>
)
}

export const render: PlasmoRender<PlasmoCSUIJSXContainer> = async ({
createRootContainer
}) => {
const rootContainer = await createRootContainer()
const root = createRoot(rootContainer)
root.render(<PlasmoOverlay />)
}

export default PlasmoOverlay
2 Replies
k_nearest_neighbor
k_nearest_neighbor•11mo ago
here's a screenshot of that code if it is easier to read with syntax highlighting
No description
illmagination
illmagination•11mo ago
Have you whitelisted your files in your tailwind.config? module.exports ={ content:['./src/*/.{ts,tsx,js,jsx}'] } ^ google that. In phone and it's messing up the correct syntax
Want results from more Discord servers?
Add your server
More Posts
Opening content script only if an element is present on the page?I want to show my extension in a sidebar only if a certain value is present in the html of the page.how to import/use external component libraries? and how to register components?Hello, I would like to know how to import a library that will be used throughout the project (optionHow to insert a file using chrome.scripting?I am migrating this example from google tutorial https://github.com/GoogleChrome/chrome-extensions-sWhat is the correct way use an image url from assets to show notification?I use this: ```ts import iconUrl from "url:/assets/icon.png" chrome.notifications.create({ type:which is a good/scalable folder structure for a big extension?Hi, If I want to create an extension that has several content scripts that are very long (has many lHMR for other chromium browsersIs it possible to run a development server for opera, firefox, brave, edge, etc? I tried chaining ruParcel throwing an error in productionAs described here: https://github.com/PlasmoHQ/plasmo/issues/661, the following error is thrown: ```Is there an extension repository that shows how the testing should be done?Is there an extension repository that shows how the testing should be done? I want to see how the baHow do I troubleshoot my plasmo production build?My app is working well in development, but when I tried moving to the production build it no longer From popup.tsx to content.tsI want to make a function from my content.ts that executes when a button on popup.tsx is clicked. I