## Table of Contents

- [Function: Troubleshooting](#function-troubleshooting)
- [Error handling](#error-handling)
- [Resource errors](#resource-errors)
- [Function-specific errors](#function-specific-errors)
- [Fixing resource limit errors](#fixing-resource-limit-errors)
- [General debugging](#general-debugging)
- [See also](#see-also)

---

[API](https://microlink.io/docs/api/getting-started/overview)

[GUIDES](https://microlink.io/docs/guides) [MQL](https://microlink.io/docs/mql/getting-started/overview) [SDK](https://microlink.io/docs/sdk/getting-started/overview) [CARDS](https://microlink.io/docs/cards/getting-started/overview)

API GUIDES MQL SDK CARDS

Getting Started

[Overview](https://microlink.io/docs/guides)

[What is Microlink](https://microlink.io/docs/guides/what-is-microlink)

[Screenshot](https://microlink.io/docs/guides/screenshot)

[Customizing output](https://microlink.io/docs/guides/screenshot/customizing-output)

[Browser settings](https://microlink.io/docs/guides/screenshot/browser-settings)

[Page interaction](https://microlink.io/docs/guides/screenshot/page-interaction)

[Delivery and embedding](https://microlink.io/docs/guides/screenshot/embedding)

[Caching and performance](https://microlink.io/docs/guides/screenshot/caching-and-performance)

[Private pages](https://microlink.io/docs/guides/screenshot/private-pages)

[Troubleshooting](https://microlink.io/docs/guides/screenshot/troubleshooting)

[Data extraction](https://microlink.io/docs/guides/data-extraction)

[Defining rules](https://microlink.io/docs/guides/data-extraction/defining-rules)

[Page preparation](https://microlink.io/docs/guides/data-extraction/page-preparation)

[Delivery and response shaping](https://microlink.io/docs/guides/data-extraction/delivery-and-response)

[Caching and performance](https://microlink.io/docs/guides/data-extraction/caching-and-performance)

[Private pages](https://microlink.io/docs/guides/data-extraction/private-pages)

[Troubleshooting](https://microlink.io/docs/guides/data-extraction/troubleshooting)

[Embed](https://microlink.io/docs/guides/embed)

[SDK](https://microlink.io/docs/guides/embed/sdk)

[Iframe parameter](https://microlink.io/docs/guides/embed/iframe)

[Custom HTML/CSS](https://microlink.io/docs/guides/embed/metadata-api)

[Custom previews with AI](https://microlink.io/docs/guides/embed/custom-previews-with-ai)

[Caching and performance](https://microlink.io/docs/guides/embed/caching-and-performance)

[Private pages and proxy](https://microlink.io/docs/guides/embed/private-pages-and-proxy)

[Troubleshooting](https://microlink.io/docs/guides/embed/troubleshooting)

[Markdown](https://microlink.io/docs/guides/markdown)

[Choosing scope](https://microlink.io/docs/guides/markdown/choosing-scope)

[Delivery and response shaping](https://microlink.io/docs/guides/markdown/delivery-and-response)

[Function](https://microlink.io/docs/guides/function)

[Writing functions](https://microlink.io/docs/guides/function/writing-functions)

[Browser interaction](https://microlink.io/docs/guides/function/browser-interaction)

[Profiling and performance](https://microlink.io/docs/guides/function/profiling-and-performance)

[Troubleshooting](https://microlink.io/docs/guides/function/troubleshooting)

[PDF](https://microlink.io/docs/guides/pdf)

[Page size and layout](https://microlink.io/docs/guides/pdf/page-size-and-layout)

[Page preparation](https://microlink.io/docs/guides/pdf/page-preparation)

[Delivery and embedding](https://microlink.io/docs/guides/pdf/embedding)

[Caching and performance](https://microlink.io/docs/guides/pdf/caching-and-performance)

[Private pages](https://microlink.io/docs/guides/pdf/private-pages)

[Troubleshooting](https://microlink.io/docs/guides/pdf/troubleshooting)

[Metadata](https://microlink.io/docs/guides/metadata)

[Choosing fields](https://microlink.io/docs/guides/metadata/choosing-fields)

[Extending results](https://microlink.io/docs/guides/metadata/extending-results)

[Delivery and response shaping](https://microlink.io/docs/guides/metadata/delivery-and-response)

[Page preparation](https://microlink.io/docs/guides/metadata/page-preparation)

[Caching and performance](https://microlink.io/docs/guides/metadata/caching-and-performance)

[Private pages](https://microlink.io/docs/guides/metadata/private-pages)

[Troubleshooting](https://microlink.io/docs/guides/metadata/troubleshooting)

[Insights](https://microlink.io/docs/guides/insights)

[Technology detection](https://microlink.io/docs/guides/insights/technology-detection)

[Lighthouse reports](https://microlink.io/docs/guides/insights/lighthouse-reports)

[Caching and performance](https://microlink.io/docs/guides/insights/caching-and-performance)

[Troubleshooting](https://microlink.io/docs/guides/insights/troubleshooting)

[Common patterns](https://microlink.io/docs/guides/common/caching)

[Caching patterns](https://microlink.io/docs/guides/common/caching)

[Private pages](https://microlink.io/docs/guides/common/private-pages)

[Proxy](https://microlink.io/docs/guides/common/proxy)

[Troubleshooting](https://microlink.io/docs/guides/common/troubleshooting)

[Production patterns](https://microlink.io/docs/guides/common/production-patterns)

API GUIDES MQL SDK CARDS

Getting Started

[Overview](https://microlink.io/docs/guides)

[What is Microlink](https://microlink.io/docs/guides/what-is-microlink)

[Screenshot](https://microlink.io/docs/guides/screenshot)

[Customizing output](https://microlink.io/docs/guides/screenshot/customizing-output)

[Browser settings](https://microlink.io/docs/guides/screenshot/browser-settings)

[Page interaction](https://microlink.io/docs/guides/screenshot/page-interaction)

[Delivery and embedding](https://microlink.io/docs/guides/screenshot/embedding)

[Caching and performance](https://microlink.io/docs/guides/screenshot/caching-and-performance)

[Private pages](https://microlink.io/docs/guides/screenshot/private-pages)

[Troubleshooting](https://microlink.io/docs/guides/screenshot/troubleshooting)

[Data extraction](https://microlink.io/docs/guides/data-extraction)

[Defining rules](https://microlink.io/docs/guides/data-extraction/defining-rules)

[Page preparation](https://microlink.io/docs/guides/data-extraction/page-preparation)

[Delivery and response shaping](https://microlink.io/docs/guides/data-extraction/delivery-and-response)

[Caching and performance](https://microlink.io/docs/guides/data-extraction/caching-and-performance)

[Private pages](https://microlink.io/docs/guides/data-extraction/private-pages)

[Troubleshooting](https://microlink.io/docs/guides/data-extraction/troubleshooting)

[Embed](https://microlink.io/docs/guides/embed)

[SDK](https://microlink.io/docs/guides/embed/sdk)

[Iframe parameter](https://microlink.io/docs/guides/embed/iframe)

[Custom HTML/CSS](https://microlink.io/docs/guides/embed/metadata-api)

[Custom previews with AI](https://microlink.io/docs/guides/embed/custom-previews-with-ai)

[Caching and performance](https://microlink.io/docs/guides/embed/caching-and-performance)

[Private pages and proxy](https://microlink.io/docs/guides/embed/private-pages-and-proxy)

[Troubleshooting](https://microlink.io/docs/guides/embed/troubleshooting)

[Markdown](https://microlink.io/docs/guides/markdown)

[Choosing scope](https://microlink.io/docs/guides/markdown/choosing-scope)

[Delivery and response shaping](https://microlink.io/docs/guides/markdown/delivery-and-response)

[Function](https://microlink.io/docs/guides/function)

[Writing functions](https://microlink.io/docs/guides/function/writing-functions)

[Browser interaction](https://microlink.io/docs/guides/function/browser-interaction)

[Profiling and performance](https://microlink.io/docs/guides/function/profiling-and-performance)

[Troubleshooting](https://microlink.io/docs/guides/function/troubleshooting)

[PDF](https://microlink.io/docs/guides/pdf)

[Page size and layout](https://microlink.io/docs/guides/pdf/page-size-and-layout)

[Page preparation](https://microlink.io/docs/guides/pdf/page-preparation)

[Delivery and embedding](https://microlink.io/docs/guides/pdf/embedding)

[Caching and performance](https://microlink.io/docs/guides/pdf/caching-and-performance)

[Private pages](https://microlink.io/docs/guides/pdf/private-pages)

[Troubleshooting](https://microlink.io/docs/guides/pdf/troubleshooting)

[Metadata](https://microlink.io/docs/guides/metadata)

[Choosing fields](https://microlink.io/docs/guides/metadata/choosing-fields)

[Extending results](https://microlink.io/docs/guides/metadata/extending-results)

[Delivery and response shaping](https://microlink.io/docs/guides/metadata/delivery-and-response)

[Page preparation](https://microlink.io/docs/guides/metadata/page-preparation)

[Caching and performance](https://microlink.io/docs/guides/metadata/caching-and-performance)

[Private pages](https://microlink.io/docs/guides/metadata/private-pages)

[Troubleshooting](https://microlink.io/docs/guides/metadata/troubleshooting)

[Insights](https://microlink.io/docs/guides/insights)

[Technology detection](https://microlink.io/docs/guides/insights/technology-detection)

[Lighthouse reports](https://microlink.io/docs/guides/insights/lighthouse-reports)

[Caching and performance](https://microlink.io/docs/guides/insights/caching-and-performance)

[Troubleshooting](https://microlink.io/docs/guides/insights/troubleshooting)

[Common patterns](https://microlink.io/docs/guides/common/caching)

[Caching patterns](https://microlink.io/docs/guides/common/caching)

[Private pages](https://microlink.io/docs/guides/common/private-pages)

[Proxy](https://microlink.io/docs/guides/common/proxy)

[Troubleshooting](https://microlink.io/docs/guides/common/troubleshooting)

[Production patterns](https://microlink.io/docs/guides/common/production-patterns)

## Function: Troubleshooting

[Copy for LLM](https://microlink.io/docs/guides/function/troubleshooting.md "Copy content for LLM")

\|

[View as Markdown](https://microlink.io/docs/guides/function/troubleshooting.md "View content as Markdown")

## Error handling

When a function throws, the result comes back with `isFulfilled: false` and the error details at `result.value`:

```js
const microlink = require('@microlink/function')

const failing = ({ name }) => name()

const fn = microlink(failing)

const result = await fn('https://example.com', { name: 'Kiko' })

console.log(result.isFulfilled) // false

console.log(result.value.name) // 'TypeError'

console.log(result.value.message) // 'name is not a function'
```

Non-Error throws (like `throw 'oh no'`) are normalized into a `NonError` with the thrown value as the message.

## Resource errors

When a function exceeds its plan limits, the API returns a descriptive error instead of failing the entire request:

| Error              | Trigger                                                              |
| ------------------ | -------------------------------------------------------------------- |
| `TimeoutError`     | Function wall-clock time exceeded the plan limit                     |
| `CpuTimeError`     | Function CPU time exceeded the plan limit                            |
| `MemoryError`      | Function memory usage exceeded the plan limit                        |
| `CodeSizeError`    | Function code exceeds the 1024 bytes free plan limit                 |
| `ConcurrencyError` | Too many concurrent function executions for the free plan (1 per IP) |

Each error message is plan-aware:

```json
{

  "isFulfilled": false,

  "value": {

    "name": "TimeoutError",

    "message": "Function exceeded the 5s free plan timeout. Upgrade to pro for up to 28s."

  }

}
```

## Function-specific errors

- **EINVALFUNCTION** — the function string has invalid JavaScript syntax. Check quotes, brackets, template strings, and arrow function formatting.
- **EINVALEVAL** — the function executed but threw at runtime. Check undefined variables, DOM queries that return null, or mistakes inside `page.evaluate`.

## Fixing resource limit errors

**TimeoutError** — the function exceeded its plan timeout (5s free, ~28s pro):

1.  Reduce the function to a trivial check such as `({ page }) => page.title()` to confirm the page itself loads in time.
2.  Set `meta: false` unless metadata is part of the requirement.
3.  Replace fixed waits with `waitForSelector` whenever possible.
4.  Move heavy post-processing to your own server.

**CpuTimeError** — the function used too much CPU time:

1.  Simplify the computation or break it into smaller steps.
2.  Avoid CPU-intensive operations like large JSON parsing or complex regular expressions.
3.  Move heavy processing to your own server and use the function only for data extraction.

**MemoryError** — the function exceeded its memory limit (16 MB free, 32 MB pro):

1.  Reduce the amount of data held in memory at once.
2.  Avoid loading entire pages into memory when you only need a small part.
3.  Use streaming or pagination patterns when dealing with large datasets.

**CodeSizeError** — the function code exceeds the 1024 bytes free plan limit:

1.  Use the [@microlink/function](https://www.npmjs.com/package/@microlink/function) library, which compresses code automatically.
2.  Compress the function body manually with `lz#`, `br#`, or `gz#` prefixes.
3.  Upgrade to pro for unlimited code size.

**ConcurrencyError** — too many concurrent function executions (1 per IP on the free plan):

1.  Wait for the current function execution to finish before sending another request.
2.  Upgrade to pro for unlimited concurrency.

## General debugging

1.  Start simple — reduce the function to `({ page }) => page.title()` to isolate whether the problem is in your code or the target page.
2.  Disable metadata — set `meta: false` unless metadata is part of the requirement.
3.  Check profiling — inspect `result.profiling` to understand where time is being spent.
4.  Use the right context — keep orchestration in the outer function and DOM-only code inside `page.evaluate`.
5.  Watch for null — DOM queries like `document.querySelector()` return null when the element doesn't exist. Always use optional chaining or null checks.

## See also

- [Profiling and performance](https://microlink.io/docs/guides/function/profiling-and-performance) — understand execution phases and optimize.
- [Common troubleshooting](https://microlink.io/docs/guides/common/troubleshooting) — timeouts, blocked sites, auth issues, and debug headers that apply to every workflow.
- [Function reference](https://microlink.io/docs/api/parameters/function) — response shape, plan limits, and resource errors.

Last updated on May 24, 2026

[Edit on GitHub](https://github.com/microlinkhq/www/blob/master/src/content/docs/guides/function/troubleshooting.md)