Puppeteer, Jest, Unhandled rejection: MissingAPIError: indexedDB API not found

See original GitHub issue

As there are close to no resources on how to test indexedDB, I figured out that one way could be by end-to-end testing using Puppeteer and Jest. However with Dexie it throws this error:

Unhandled rejection: MissingAPIError: indexedDB API not found This is clearly a Dexie.js error, if I try to open the indexedDB normally everything work as expected.

describe('IndexedDB', () => {
  const puppeteerConfig = {
    headless: false
  };
  let browser, page, db;

  beforeEach(async () => {
    browser = await puppeteer.launch(puppeteerConfig);
    page = await browser.newPage();
    await page.goto('http://localhost:3000', {waitUntil: 'networkidle2'});
    db = require('../../../services/cache/indexedDb').default
  });

  afterEach(async () => {
    await db.clear();
    await browser.close();
  });


  describe('test', function () {

    it('should test add', async function () {
      await db.photos.add({id: 1, date: '2014-01-09'})
    });
  });
});`

my config

const tables = {
  photos: "id, year, month",
};

const db = new Dexie(config.cache.dbName);
db.version(config.cache.version).stores(tables);

export default db;

Everything is working normally, not with Puppeteer and Chromium

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:12

github_iconTop GitHub Comments

1reaction
dfahlandercommented, Jan 17, 2019

That exception happens when there’s no indexedDB property present on the global object, specifically i in node. Dexie can be configured to rely on a given indexedDB implementation instead, such as fake-indexedDB or indexeddbshim. To enable that, do set the static properties Dexie.dependencies.indexedDB and Dexie.dependencies.IDBKeyRange prior to instanciating your Dexie instance

0reactions
s0thlcommented, Jul 26, 2019

I would be very surprised if different BrowserWindow instances would not share the same database. But I’m not an Electron expert. In a normal web scenario, the same database are shared across windows, iframes web workers and service workers as long as they are on the same origin (= hostname part of the URL).

At least for me, they really don’t. Thats why I am asking for any workaround, like accessing the Dexie singleton in renderer one from renderer two.

Also, I’m not using a worker yet. For now, I just open windows (one main + children) and try to find a way to read/write to database using Pixie from the main window’s indexedDB (everything is being done on renderer process).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Puppeteer, Jest, Unhandled rejection: MissingAPIError ...
I have tried to initialize it from the renderer process first, then make use of it in the main process but still getting...
Read more >
indexedDB is not defined" when testing React component ...
Actually, Jest is used to simulate the DOM in memory, not in an actual headless browser. For that reason, you have to mock...
Read more >
MissingAPIError: indexedDB API missing
MissingAPIError : indexedDB API missing ``` 議論はここでされてて、 - [Puppeteer, Jest, Unhandled rejection: MissingAPIError: indexedDB API ...
Read more >
Dexie.MissingAPIError
Description. Happens when indexedDB API could not be found when trying to open database. This is usually the case when using Dexie from...
Read more >
Testing your IndexedDB code with Jest
The reason why our test didn't work is because indexedDB is undefined in the global namespace; IndexedDB is a browser API, so does...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found