indexeddbshim / IndexedDBShim

A polyfill for IndexedDB using WebSql
Other
968 stars 191 forks source link

Error on Android 3.2 webview #331

Open trialforce opened 6 years ago

trialforce commented 6 years ago

Hi! I'm developing a offline web app and it work very well with Android 4.4 >, but my employer need it's to work in a old 2011 tablet with Android 3.2, so I came to indexeddbshim. It has about 20 tablets with this awesome version.

I'm using dexie.js.

My code to starts with that:

window.shimIndexedDB.__useShim();

const db = new Dexie('mydatabase', {
    indexedDB: window.shimIndexedDB,
    IDBKeyRange: window.IDBKeyRange,
});

When I force the shim to work the app works well in current Chrome on Windows, but inside the Webview of Android 3.2 I get the following error:

Uncaught TypeError: Cannot read property '__db' of undefined at https://mywebserver/vendor/indexeddbshim.js:5650

When I click the next button I get the error above.

11-08 16:11:33.160 8889-8889/packagename W/Web Console: Unhandled rejection: TypeError: Cannot set property code of undefined which has only a getter at defineProperty (native) at defineProperty (https://mywebserver/vendor/polyfill.js:5345:12) at Function.defineProperty (https://mywebserver/vendor/polyfill.js:2558:14) at new DOMException (https://mywebserver/vendor/indexeddbshim.js:1506:16) at createNonNativeDOMException (https://mywebserver/vendor/indexeddbshim.js:1602:12) at createDOMException (https://mywebserver/vendor/indexeddbshim.js:1710:16) at https://mywebserver/vendor/indexeddbshim.js:2799:55 at https://mywebserver/vendor/polyfill.js:182:13 at Array.forEach (https://mywebserver/vendor/polyfill.js:3200:12) at IDBDatabase.transaction (https://mywebserver/vendor/indexeddbshim.js:2797:16) at https://mywebserver/vendor/dexie.min.js:1 11-08 16:11:33.160 8889-8889/packagename E/Web Console: Unhandled promise rejection at https://mywebserver/vendor/polyfill.js:4326

Any tips?

trialforce commented 6 years ago

I made a simple test, without dexie, to see if it work.

The websql example works, but shim don't, same error:

Uncaught TypeError: Cannot read property '__db' of undefined at indexeddbshim.js:5650

<!DOCTYPE html>
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div>TODO write content</div>
        <script src="polyfill.min.js"></script>
        <script src="indexeddbshim.js"></script>
        <script>
            var db = openDatabase('mydb', '1.0', 'my first database', 2 * 1024 * 1024);
            db.transaction(function (tx) {
                tx.executeSql('CREATE TABLE foo (id unique, text)');
                tx.executeSql('INSERT INTO foo (id, text) VALUES (1, "synergies")');

                tx.executeSql('SELECT * FROM foo', [], function (tx, results)
                {
                    var len = results.rows.length, i;

                    for (i = 0; i < len; i++)
                    {
                        alert(results.rows.item(i).text);
                    }
                });
            });

        </script>
        <script>
            (function () {
                var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
                var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction;
                var IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange;

                if (!indexedDB)
                {
                    window.alert("Seu navegador não suporta uma versão estável do IndexedDB. Alguns recursos não estarão disponíveis.");
                }

                var request = indexedDB.open("DBteste", 3);

                request.onerror = function (event) {
                    alert("Você não habilitou minha web app para usar IndexedDB?!");
                };

                request.onsuccess = function (event) {
                    db = request.result;
                };

                db.onerror = function (event) {
                    alert("Database error: " + event.target.errorCode);
                };

                request.onupgradeneeded = function (event) {
                    var db = event.target.result;
                    var objectStore = db.createObjectStore("nome", {keyPath: "minhaChave"});
                };

                alert('Okay!');
            })();
        </script>
    </body>
</html>
brettz9 commented 6 years ago

I'm hoping to get to some IndexedDBShim issues within one or two weeks, and maybe as with issue #330, setting @babel/preset-env might ensure our bundle is not using too advanced of features.

brettz9 commented 5 years ago

You might try again now with 4.0.1 which has just been released...