Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

playwright using indexedDB

is it possible to somehow interact with indexeddb ?

I want to test UI using test data in indexeddb.

I am using the code from the documentation https://developer.mozilla.org/en-US/docs/Web/API/IDBFactory and I get the error

 indexedDB is not defined 
window is not defined
like image 862
desert rose Avatar asked Sep 16 '26 16:09

desert rose


1 Answers

Yes you can use page.evaluate to execute JavaScript inside your page: https://playwright.dev/docs/api/class-page#page-evaluate

// @ts-check
const playwright = require('playwright');

(async () => {
  // Try to add 'firefox' to the list ↓
  for (const browserType of [playwright.chromium, playwright.firefox, playwright.webkit]) {
    const browser = await browserType.launch();
    const context = await browser.newContext();
    const page = await context.newPage();
    await page.goto('https://example.org/');
    console.log(await page.evaluate(() => {
      return typeof window.indexedDB
    }));
    await browser.close();
  }
})();

Make sure to pass any values which you want to share from Node.js with the browser as a second argument, see here: https://playwright.dev/docs/next/evaluating

like image 195
Max Schmitt Avatar answered Sep 19 '26 06:09

Max Schmitt