Google Chrome Is it possible to include SQLite db in the extension

Is it possible to include a DB file packaged with the extension when downloading it. I am trying to include a small database with zip codes so that the extension does not require finding a suitable zip code.

maybe at all?

+3
source share
1 answer

Basically what I would do in the Chrome Extension, it packs it using the zip_codes.json file. Then, when your extension loads, use XHR to read this file. For example, the snippet below is asynchronous (you can also use it synchronously if you want) to get the zip codes stored in your extension.

var zipcodes = {};
var xhr = new XMLHttpRequest();
xhr.open('GET', chrome.extension.getURL('zip_codes.json'), false);
xhr.onreadystatechange = function() {
  zip_codes = JSON.parse(xhr.responseText);
  console.log(zip_codes);
}

, , - localStorage , , , .

, zip_codes.json :

{
  33445: 'Some zip'
}

, :

console.log(zip_codes[33445]);

, !

+4

Source: https://habr.com/ru/post/1787027/


All Articles