0

I have tried to read a simple text file, whose URI is C:\reading.txt, in my computer through AJAX:

fetch("C:/reading.txt");

Web browser throws an exception during test of above statement and says:

Access to fetch at 'file:///C:/reading.txt' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, edge, chrome-untrusted, https, isolated-app.

I have tried this in Firefox, Chromium and Internet Explorer. All of them gave similar messages. Accessing local storage via AJAX may be dangerous, but I am just developing an offline application. Could we pass this restriction?

Protest against closing...

The application told here is not a network application. Thus, we can not apply HTTP on application layer. To do this the application must be published in a server technology like IIS, Apache Tomcat, JBoss etc. Pointed thread mentions web based applications, so it does not answer my question.

STEEL
  • 1
  • 1
  • If you’re developing an off-line application; don’t build it around a traditional web browser. Use something like Electron instead. – Quentin Feb 14 '23 at 07:05

1 Answers1

-1

You should start your browser with a specific flag to override the above security measure (https://cmatskas.com/interacting-with-local-data-files-using-chrome/):

chrome.exe --allow-file-access-from-file (for Windows)
open /Applications/Google\ Chrome.app --args  --allow-file-access-from-file (for MacOS)
IVO GELOV
  • 13,496
  • 1
  • 17
  • 26
  • I had following command run in order to start Chromium based Microsoft Edge: `msedge.exe --allow-file-access-from-file` Yet, nothing is different. – STEEL Feb 08 '23 at 10:04
  • https://stackoverflow.com/questions/18586921/how-to-launch-html-using-chrome-at-allow-file-access-from-files-mode – IVO GELOV Feb 08 '23 at 11:52
  • I thank you dear companion. I have found a solution in the thread. On the other hand, a similar security adjustment ought to be in Firefox based systems. I hope I can learn it too. – STEEL Feb 08 '23 at 17:42