Closed RoboticWater closed 4 months ago
Works just fine for .png but does not for .svg. Windows 11 Node 20 Chrome 125.
"vite": "^5.2.11",
"@crxjs/vite-plugin": "^2.0.0-beta.23",
"@vitejs/plugin-react": "^4.2.1",
import reactLogo from '../../img/logo.png';
chrome.notifications.create(`notification-${Date.now()}`, {
type: 'basic',
iconUrl: chrome.runtime.getURL(reactLogo),
title: 'Popup.js',
message: 'Hello from popup.js!',
});
Works just fine
But .svg didnt work
import reactLogo from '../../img/logo.svg';
chrome.notifications.create(`notification-${Date.now()}`, {
type: 'basic',
iconUrl: reactLogo,
title: 'Popup.js',
message: 'Hello from popup.js!',
});
When you look at the dist/
folder you will notice they are not even copied into the build.
Even when using vite-svg-loader
Its not even funny. It does not work even if you use manual string paths and put the .svg file into the assets folder. Chrome easily displays it but the service worker wont download it.
chrome.notifications.create(`notification-${Date.now()}`, {
type: 'basic',
iconUrl: chrome.runtime.getURL('/assets/logo.svg'),
title: 'Popup.js',
message: 'Hello from popup.js!',
});
It is clearly not a problem with crxjs. First someone has to say how to use .svgs with chrome notifications (maybe it is not possible).
All Google demos are using .pngs https://developer.chrome.com/docs/extensions/samples?api=notificationscreate
Did it work? Can we close the issue @RoboticWater
@Toumash yes, that worked, you can close the issue.
@RoboticWater i cannot close it, youre the author ;)
Issue resolved, see this comment for the answer.
Build tool
Vite
Where do you see the problem?
Describe the bug
When creating a notification using an imported image asset in a background script, I get the error
Uncaught (in promise) Error: Unable to download all specified images.
I'm usingchrome.runtime.getURL(reactLogo)
to get the asset URL, and if I put that URL in the browser, I'm able to access the image, so I doubt the problem is the asset itself.This error doesn't occur when I provide a URL to a non-cors protected image somewhere on the internet, so it seems to just be an issue loading assets from within the app.
Reproduction
Background script:
Manifest:
Logs
System Info
Severity
annoyance