Vue-cli-plugin-electron-builder: [Question] Not allowed to load local resource

Created on 26 Aug 2019  路  2Comments  路  Source: nklayman/vue-cli-plugin-electron-builder

This is the error that I get in development
Not allowed to load local resource: file:///C:/Users/first.last/Documents/ElectronApp/public/icon.png

This is what I get in production
Not allowed to load local resource: file:///C:/Users/first.last/AppData/Local/Programs/ElectronApp/resources/app.asar/icon.png

I am trying to show a notification from the renderer process and it takes in an icon string parameter so I am passing it ${__static}\\icon.png, but I keep getting the error above. Anyone know how I can go about fixing this (the icon is in my public folder)?

Most helpful comment

My colleague figured it out. He said that for security reasons (when webSecurity is on), electron won't/shouldn't let you load a file "directly" from disk (i.e. a file path like the 2 URIs in my previous post) so he said to import it so that webpack resolves the path to somewhere in the bundle.

import icon from '../public/icon.png';
new Notification(title, { icon, requireInteraction: true });

All 2 comments

Can you explain how you fixed the issue so that others with the same problem can fix it for themselves?

My colleague figured it out. He said that for security reasons (when webSecurity is on), electron won't/shouldn't let you load a file "directly" from disk (i.e. a file path like the 2 URIs in my previous post) so he said to import it so that webpack resolves the path to somewhere in the bundle.

import icon from '../public/icon.png';
new Notification(title, { icon, requireInteraction: true });
Was this page helpful?
0 / 5 - 0 ratings