# evaluate

Type:

\<string\> \| \<function\>

It evaluates the JavaScript provided inside the browser context over the target URL, returning the result.

It's quite similar to [selector](https://microlink.io/docs/sdk/methods/extract/selector), but designed to specify the value to be obtained in a JavaScript-like way.

```js
importcreateClientfrom'microlink.io'

constmicrolink=createClient()

constgetNextVersion=url=>

microlink.extract(url,{

version:{

evaluate:'window.next.version',

type:'string'

}

})

const{version}=awaitgetNextVersion('https://vercel.com')

console.log(`Next.js version is: ${version}`)
```

You can combine evaluate with types for data correctness.

It can evaluate anything browser compatible in the JavaScript context. A function is serialized to its source before being sent, so it can be as long as you need — but it runs in the page, not in your process, so it can only reach what the page can:

```js
constgetExcerpt=url=>

microlink.extract(url,{

excerpt:{

evaluate:async()=>{

constresponse=awaitwindow.fetch(

'https://cdn.jsdelivr.net/npm/@mozilla/readability/Readability.js'

)

constscript=awaitresponse.text()

window.eval(script)

constreader=newwindow.Readability(window.document)

returnreader.parse().excerpt

},

type:'string'

}

})

const{excerpt}=awaitgetExcerpt(

'https://levelup.gitconnected.com/how-to-load-external-javascript-files-from-the-browser-console-8eb97f7db778'

)

console.log(excerpt)
```

When the logic outgrows a single expression — clicks, waits, npm packages — reach for [function](https://microlink.io/docs/sdk/methods/function), which gives the function full Puppeteer access instead of a page-side evaluation.