Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on Android 3.2 webview #331

Open
trialforce opened this issue Nov 8, 2018 · 3 comments
Open

Error on Android 3.2 webview #331

trialforce opened this issue Nov 8, 2018 · 3 comments

Comments

@trialforce
Copy link

trialforce commented Nov 8, 2018

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 trialforce changed the title Erro on Android 3.2 webview Error on Android 3.2 webview Nov 8, 2018
@trialforce
Copy link
Author

trialforce commented Nov 8, 2018

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
Copy link
Collaborator

brettz9 commented Nov 10, 2018

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
Copy link
Collaborator

brettz9 commented Dec 5, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants