Comments (8)
Hello @ShaunLWM,
I don't think it's a boilerplate problem. Rather a lack of documentation. Let's dive into the problem:
First of all, contentscript should understand that we want an image from our extension and not from a page. For that we can use the chrome.runtime.getURL()
function. It looks like this:
import login from '@assets/img/login.svg'
...
<img src={chrome.runtime.getURL(login)} alt="login" />
Oops, still not working. Check the errors in chrome-extension page and discover the line saying our image should be listed under web_accessible_resources
in manifest. All right, let's do it. Open the manifest.ts
file in our root directory and add this:
web_accessible_resources: [
{
resources: [
...
'assets/svg/*.svg',
}
]
After that, reload the extension and you should see your image.
TLDR:
You want to wrap your image imports in chrome.runtime.getURL()
and list the folder with images in your manifest.ts
under web_accessible_resources
.
P.S. Mind that if you will try to import a png or jpg, you should add something like 'assets/png/*.png'
to the list of resources.
from chrome-extension-boilerplate-react-vite.
Thank you for your contribution. We will check and reply to you as soon as possible.
from chrome-extension-boilerplate-react-vite.
Understood. Will have a look. Thank you so much for the detailed explanation, appreciate it.
from chrome-extension-boilerplate-react-vite.
how about other resources like pdfs or so? I get compilation erros for those files.
[vite:build-import-analysis] Parse error @:1:34998
...
...
^
2: 7H7@ݶ��6,7���P%7l7`♥��>7�7�↨��c7�7�5�S5�5,���67���k6�6�8��6►7���8↔7d7��1�2@�7�7 L�ئ7�7 ����7�7Ё�@�6.7�Ŷ�+7r7��↑7R7@��x7�7�F��Z7�7�,���6(7���`�7��� �6�6�z���67��� �6$7��0 7:7�Ͷ�*7h7♥�@�6↑7����6�6A���6�6]�@k6�61���6�6�����6�6�I���6�6s���6♦7���8�7�7p��H�7�7�v��47p7�♠��7<7Ѷ�j7�7�3��97r7 ♣� �7�7�<��7�7@m��♣7.7@����7�70��y7�7�,���7�*8�·<�7�79���7§8`��P�6∟7����4�4�� 5`5д4��►6H6۵��5 6���$6h6�v5�5:�05@���5�5�����4�����������A6�6� n6�6�/���506���J6�6§��4�2`§6X6۵��6�6�F�►�6�6i��6�6�D�`�6�6t���43��22[8@�8(♣���7�8►�6@6ѵ�[6�6$��W6�6!��46p6��@
3: 686ϵ�26�6♣�@-6h6☻��)6`6���!6X6�@R6�6∟�@M6�6↑���6�6�a�@�6�6l� �6�6D��6�6�>��6�6�����67�����6�6C�@6�6���6�6X��w6�6�7��d6�6*��6�6�a�Ч6�6x��K6�6�▬�@26x6�♦��m6�60�p4�4P��4�4h��45H��4�4h��4�4���45p��45H��4�4H��45X�P4�4@��45���4@5��j4�4@��45��x4�4@�Z4�4↑�v4�48��4 5���4�4h��45`��45h��4�4H��4�4p�<45�d4�4P�X4�4 F7@ն��67���►�6
transforming (4259) node_modules\lodash\_hashDelete.js
index.js:38 GET chrome-extension://bcjighfjikochhpeopamggdmdjcbfdid/assets/js/index.js net::ERR_FILE_NOT_FOUND
dynamicImport @ index.js:38
(anonymous) @ index.js:39
preload @ index.js:8
(anonymous) @ index.js:37
Show 4 more frames
Show less
/:1 Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: chrome-extension://bcjighfjikochhpeopamggdmdjcbfdid/assets/js/index.js
from chrome-extension-boilerplate-react-vite.
Have you added the PDF extension to your resources?
from chrome-extension-boilerplate-react-vite.
@Jonghakseo I ended up using the vite plugin-url https://www.npmjs.com/package/@rollup/plugin-url to load binary files
from chrome-extension-boilerplate-react-vite.
@all-contributors please add @Araneline for question
from chrome-extension-boilerplate-react-vite.
I've put up a pull request to add @Araneline! 🎉
from chrome-extension-boilerplate-react-vite.
Related Issues (20)
- Theme Storage toggle failed in Content script example HOT 2
- Make husky use pnpm HOT 1
- use of experimental node features causes warnings HOT 1
- Error when importing tailwind css file into content script HOT 11
- How to sync web app authentication with chrome extension HOT 8
- Styles do not get applied using Styled Components library HOT 7
- vite preloadhelper shouldn't be using import statement HOT 9
- Add Mantien UI example integration HOT 4
- Cannot load the extension due to Content Script which is generated in wrong path HOT 1
- enabling source maps results in warning from inline-vite-preload-script.ts HOT 4
- Uncaught SyntaxError: Cannot use 'import.meta' outside a module HOT 1
- Files nested inside content/content-script doesn't auto reload on browser HOT 4
- Chakra styles are not loaded on injected content script HOT 2
- rollup packaging speed optimization HOT 1
- [Question] 각 페이지의 역할에 대해 궁금합니다! Wondering about the role of each page! HOT 5
- Boilerplate Redesign HOT 2
- HMR does not work on Content Scripts Change HOT 4
- Is there any way to use React Developer Tools for debugging my extension? HOT 5
- Why the document default language is Korean? HOT 2
- Chakra UI Components Not Rendering HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chrome-extension-boilerplate-react-vite.