src/content/docs/linter/rules/no-playwright-eval.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.4.2` - Diagnostic Category: [`lint/nursery/noPlaywrightEval`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - This rule belongs to the following domains: - [`playwright`](/linter/domains#playwright) - Sources: - Same as [`playwright/no-eval`](https://github.com/playwright-community/eslint-plugin-playwright/blob/main/docs/rules/no-eval.md){
"linter": {
"rules": {
"nursery": {
"noPlaywrightEval": "error"
}
}
}
}
Disallow usage of page.$eval() and page.$$eval().
These methods are discouraged in favor of locator.evaluate() and locator.evaluateAll().
Locator-based evaluation is more reliable and follows Playwright's recommended patterns.
await page.$eval('.foo', el => el.textContent);
const texts = await page.$$eval('.foo', els => els.map(el => el.textContent));
const text = await page.locator('.foo').evaluate(el => el.textContent);
const texts = await page.locator('.foo').evaluateAll(els => els.map(el => el.textContent));