# noPlaywrightUnsafeReferences

Rule `biome/noPlaywrightUnsafeReferences`. Disallow using variables from outside the function passed to `page.evaluate()` and `page.addInitScript()`.

- Source: biome
- Technologies: Testing
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 30.6M weekly downloads of presets that enable it
- Trend: +109.3% last quarter
- Rank: #533 by reach, #168 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| Biome | `nursery/noPlaywrightUnsafeReferences` | yes | unsafe | group nursery, since 2.6.5 | [docs](https://biomejs.dev/linter/rules/no-playwright-unsafe-references/) |

## Code examples

### Incorrect: the rule reports this

```js
const x = 7;
const y = 8;
await page.evaluate(() => x * y);
```

```js
const theme = "dark";
await page.addInitScript(() => {
    localStorage.setItem("theme", theme);
});
```

### Correct: the rule accepts this

```js
const x = 7;
const y = 8;
await page.evaluate(([x, y]) => x * y, [x, y]);

const theme = "dark";
await page.addInitScript((theme) => {
    localStorage.setItem("theme", theme);
}, theme);

await page.evaluate(() => document.title);
```

Examples from the Biome documentation.

## Enable it

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "noPlaywrightUnsafeReferences": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Biome recommended](https://lintradar.dev/presets/biome-recommended.md) | Biome | `@biomejs/biome` | 491 | 28.5M | +106.8% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |

## Related rules

- [biome/noPlaywrightMissingAwait](https://lintradar.dev/rules/biome/noPlaywrightMissingAwait.md): Enforce Playwright async APIs to be awaited or returned.
- [biome/noQuickfixBiome](https://lintradar.dev/rules/biome/noQuickfixBiome.md): Disallow `quickfix.biome` in supported editor settings.
- [biome/noObsoleteAttributes](https://lintradar.dev/rules/biome/noObsoleteAttributes.md): Disallow obsolete attributes on HTML elements.
- [biome/noQwikUseVisibleTask](https://lintradar.dev/rules/biome/noQwikUseVisibleTask.md): Disallow `useVisibleTask$()` functions in Qwik components.
- [biome/noMissingVarFunction](https://lintradar.dev/rules/biome/noMissingVarFunction.md): Require `var()` when using a declared CSS custom property.
- [biome/noReactNativeDeepImports](https://lintradar.dev/rules/biome/noReactNativeDeepImports.md): Disallow deep imports from the `react-native` package.

---

Web page: https://lintradar.dev/rules/biome/noPlaywrightUnsafeReferences. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
