> For the complete documentation index, see [llms.txt](https://devlog.joonas.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devlog.joonas.io/chrome-extension/css-injection.md).

# CSS injection

팝업창이나 background에서 동작한다면, `chrome.tabs.insertCSS` 를 사용할 수 있다.

content\_script 등을 지정해서 특정 조건에서만 동작하게 했다면, 위 메소드는 사용할 수 없다.

대신, 동적으로 파일을 읽어서 head에 추가하는 방법이 있는데, 그러기 위해서는 먼저 그 파일을 ["web\_accessible\_resources"](https://developer.chrome.com/extensions/manifest/web_accessible_resources) 에 추가하여 권한을 먼저 등록해주어야한다.

Links

* <https://stackoverflow.com/questions/33716881/chrome-extension-how-to-insert-css-conditioned-on-variable-from-chrome-storage/33719884>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://devlog.joonas.io/chrome-extension/css-injection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
