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
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