Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not allowed to load local resource #13528

Closed
isurendrasingh opened this issue Jul 2, 2018 · 21 comments
Closed

Not allowed to load local resource #13528

isurendrasingh opened this issue Jul 2, 2018 · 21 comments

Comments

@isurendrasingh
Copy link

  • Electron Version: 2.0.3
  • Operating System (Platform and Version): Windows 10 64-bit

Expected Behavior
When the app launches, it displays the Angular 6 index page. But when the reload is done it displays the following error in console "Not allowed to load local resource".

screenshot 32

When the reload is done, it shows:
screenshot 33

@welcome
Copy link

welcome bot commented Jul 2, 2018

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

@jabreuar
Copy link

jabreuar commented Aug 5, 2018

I got the same bug. how do we fix it? I had tried several approaches

@isurendrasingh
Copy link
Author

isurendrasingh commented Aug 6, 2018

@jabreuar Don't know how to fix this. And no reply from developer team. Opened this issue a month ago and no update

@isurendrasingh
Copy link
Author

isurendrasingh commented Aug 6, 2018

@Robbyn666 not working!! I have edited the package.json inside node_modules/electron/package.json, the "directories": { "output": "release/" } was inside this package.json. But the error is same.

This is the error i'm getting after reloading:
Not allowed to load local resource: file:///C:/Electron/angular-electron/dist/angular-electron/

@isurendrasingh
Copy link
Author

@Robbyn666 Still not getting it. This is my package.json
{ "name": "angular-electron", "version": "0.0.0", "main": "main.js", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", "electron": "electron .", "electron-build": "ng build --prod && electron ." }, "private": true, "dependencies": { "@angular/animations": "^6.1.0", "@angular/common": "^6.1.0", "@angular/compiler": "^6.1.0", "@angular/core": "^6.1.0", "@angular/forms": "^6.1.0", "@angular/http": "^6.1.0", "@angular/platform-browser": "^6.1.0", "@angular/platform-browser-dynamic": "^6.1.0", "@angular/router": "^6.1.0", "core-js": "^2.5.4", "rxjs": "^6.0.0", "zone.js": "~0.8.26" }, "devDependencies": { "@angular-devkit/build-angular": "~0.7.0", "@angular/cli": "~6.1.2", "@angular/compiler-cli": "^6.1.0", "@angular/language-service": "^6.1.0", "@types/jasmine": "~2.8.6", "@types/jasminewd2": "~2.0.3", "@types/node": "~8.9.4", "codelyzer": "~4.2.1", "electron": "^2.0.6", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", "karma": "~1.7.1", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~2.0.0", "karma-jasmine": "~1.1.1", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "~5.3.0", "ts-node": "~5.0.1", "tslint": "~5.9.1", "typescript": "~2.7.2" } }
In which object do i add "directories": { "output": "release/" } ??

@isurendrasingh
Copy link
Author

@Robbyn666 Well i'm loading like this
win.loadURL(file://${__dirname}/dist/angular-electron/index.html);

But i'm trying to load it like yours but getting error url not defined. Can you update the code of url?

@jabreuar
Copy link

jabreuar commented Aug 8, 2018

@isurendrasingh I am using a quick start angular+electron from https://github.com/maximegris/angular-electron

@alwaysloseall
Copy link

@isurendrasingh
Add this configuration when you instantiate the BrowserWindow.

new BrowserWindow({
  webPreferences: {
    webSecurity: false
  }
});

@whyboris
Copy link

whyboris commented Dec 4, 2018

confirming @alwaysloseall has the solution when using angular-electron
Thank you!

@tyrants666
Copy link

tyrants666 commented Apr 21, 2019

I tried to fix this my whole day & finally found the solution,

"build": { "appId": "myledgerapp", "extends": null, "files": [ "./build/**/*", "./public/electron.js" ] }
We need to add files in build section where electron.js is my entry point.

@SangNguyen2810
Copy link

@alwaysloseall I am using react with electron and your solution works too, thanks a lot.

@btxtiger
Copy link

@tyrants666 which file is this?

@InventorSingh
Copy link

I solved this problem by loading the file like this:
win.loadURL(
url.format({
pathname: path.join(__dirname, /dist/app-name/index.html),
protocol: "file:",
slashes: true
})
);

Also, make sure in angular.json file, you have the right "outputPath": "dist/app-name",

@MutableLoss
Copy link

MutableLoss commented Mar 17, 2020

You can also receive this generic error message when the file passed to the loadURL method is missing. If you're running into this on production, it's worth double checking your build files. Unless I'm overlooking something specific to Angular, you shouldn't ever be forced to disable webSecurity.

@Mrinalaot
Copy link

Getting ERROR - "Not allowed to load local resource" after building my angular application when hosting with Github pages.
But with "ng serve" it is working fine in my local.
Build command - ng build --prod --output-path docs --base-href /user-management/
Hosting /docs with github pages.
Please suggest!!!!!!!!!!! ☺

@btxtiger
Copy link

btxtiger commented Apr 3, 2020

@Mrinalaot for me it was some config in the package.json. I don't remember what exactly. But try to remove everything but dependencies, dev-dependencies, scripts, and add the rest step by step

@VictorGorban
Copy link

@isurendrasingh
Add this configuration when you instantiate the BrowserWindow.

new BrowserWindow({
  webPreferences: {
    webSecurity: false
  }
});

Yes, It does resolve the file:// problem. You are a world savior)

@MRVirus007
Copy link

MRVirus007 commented Apr 8, 2021

@isurendrasingh I do not know where my contribution is, but we solved the problem by changing the output folder. Then the problem was gone.

package.json

"directories": { "output": "release/" }

Thanks man, You're our hero.

@alexthelion
Copy link

alexthelion commented Aug 16, 2021

Worked for me:
build: {
"directories": { "output": "release/" }
Other build config....
}

@mqliutie
Copy link

mqliutie commented Mar 23, 2023

Worked for me: build: { "directories": { "output": "release/" } Other build config.... }

Hi bro, where shoud I add this code? I am using electron-builder to pack my app. filesfield includes:

"files": [
    "dist/",
    "build/"
]

@chrismarino23
Copy link

I tried to fix this my whole day & finally found the solution,

"build": { "appId": "myledgerapp", "extends": null, "files": [ "./build/**/*", "./public/electron.js" ] } We need to add files in build section where electron.js is my entry point.

Still working bro, nice move!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

17 participants