function

Type:
<string>
It runs JavaScript code with runtime access to a headless browser.
  • CLI
  • JavaScript
  • Shell
  • Python
  • Ruby
const mql = require('@microlink/mql')

const { status, data } = await mql('https://microlink.io', {
  function: '({ page }) => page.evaluate("jQuery.fn.jquery")',
  scripts: ['https://code.jquery.com/jquery-3.5.0.min.js']
})

mql.render(data.function)
The function will receive any query parameter provided, plus:

Compression

Since the function body can be large, you can compress it:
const { compressToURI } = require('lz-ts')
const mql = require('@microlink/mql')

const code = ({ page }) => page.evaluate('jQuery.fn.jquery')

const { status, data } = await mql('https://microlink.io', {
  function: `lz#${compressToURI(code.toString())}`,
  meta: false,
  scripts: 'https://code.jquery.com/jquery-3.5.0.min.js'
})

mql.render(data.function)
You should to prefix the compressed data with the compressor alias.
The following compression algorithms are supported:
  • brotli (br)
  • gzip (gz)
  • lz-string (lz)
Read how to compress to know more.

NPM packages

Require NPM packages on runtime is supported.
const mql = require('@microlink/mql')

const code = ({ statusCode, response }) => {
  const { result } = require('lodash')
  return result(response, statusCode ? 'status' : 'statusText')
}

const ping = (url, props) =>
  mql(url, { function: code.toString(), meta: false, ...props }).then(
    ({ data }) => data.function
  )

// try passing `statusCode: false`
await ping('https://example.com', { statusCode: true })
The list of allowed NPM packages are:
If you want to request a npm package, please feel free to .