Search code examples
javascriptsqlitecors

CORS, SQLite and JavaScript. Any way to access the actual database without a local server?


I just discovered the wonderful thing that SQLite is, and I'm trying to get it to work on a local HTML file without a server, just plain JavaScript.

The SQLite wiki states that the local database be 'get' via XMLHttpRequest

var xhr = new XMLHttpRequest();
xhr.open('GET', '/path/to/database.sqlite', true);

But I can't because it's a cross origin requests. I had similar issues in the bast trying to read CSV files, and I solved it by using a file input and then passing the file forward to be parsed.

I tried doing the same thing, instead of passing /path/to/database.sqlite just passing the actual file. But it doesn't work.

Is there anyway to make this work without a local server and without messing with the security rules of the browser?

@YarGnawh like this C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --allow-access-from-files? I still get the same XMLHttpRequest cannot load file:///C:/BOVESPA2014.sqlite. Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource.


Solution

  • Welp, the best solution I've found was to simply use nw.