Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot catch Chrome's 'Cannot Load Local Resource' error in try/catch block

I am attempting to open a local folder by setting window.location.href to file://folder/, which I can do in IE, cannot in Chrome.

My goal is to catch whenever a browser blocks local file access so I can call some other code. Chrome's console is showing me 'Not allowed to load local resource:...' but I am not able to catch it with a try/catch block

Attempt:

 function OpenLocalResource() {
   try {
     //Fails in Chrome (expected)
     window.location.href = 'file://folder/whatever/';
   } catch (err) {
     //Chrome gives script error 'Not allowed to load local resource:' 
     //I am expecting to hit this catch block but it does not 
     alert("Error hit!");
   }
 }

 OpenLocalResource();

How can I detect when a browser does not allow local resource access?

like image 914
Eric Phillips Avatar asked Nov 09 '22 21:11

Eric Phillips


1 Answers

It's a security setting, I don't think you can catch it. But you could start chrome using the cmd prompt and adding --allow-file-access.

like image 97
Jannik Rasmussen Avatar answered Nov 14 '22 23:11

Jannik Rasmussen