npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@browserless/function

v10.12.1

Published

Execute arbitrary JavaScript code in a secure browser sandbox with access to page DOM and network.

Readme

@browserless/function: Run abritrary JavaScript inside a browser sandbox.

See function section our website for more information.

Install

Using npm:

npm install @browserless/function --save

About

This package provides a secure sandbox for running arbitrary JavaScript code with runtime access to a browser page. It executes user-provided functions in an isolated VM environment, with optional access to Puppeteer's page API.

What this package does

The @browserless/function package allows you to:

  • Execute arbitrary JavaScript in a secure, isolated VM sandbox
  • Access the browser page from within the sandbox for DOM manipulation
  • Capture console output and execution profiling data
  • Pass custom data to the sandboxed function at runtime
  • Handle errors gracefully with structured result objects

Usage

const createFunction = require('@browserless/function')

// Simple function without page access
const code = ({ query }) => query.value * 2

const myFn = createFunction(code)
const result = await myFn('https://example.com', { query: { value: 21 } })

console.log(result)
// => { isFulfilled: true, value: 42, profiling: {...}, logging: {...} }

Accessing the page

When your code references page, browserless automatically provides access to the Puppeteer page:

const createFunction = require('@browserless/function')

// Function with page access
const code = async ({ page }) => {
  const title = await page.title()
  const content = await page.evaluate(() => document.body.innerText)
  return { title, content }
}

const scraper = createFunction(code)
const result = await scraper('https://example.com')

console.log(result)
// => { isFulfilled: true, value: { title: 'Example', content: '...' }, ... }

Available context

The sandboxed function receives these properties:

| Property | Description | |----------|-------------| | page | Puppeteer Page object (if referenced in code) | | device | Device descriptor with userAgent and viewport | | ...opts | Any custom options passed at runtime |

Result object

The function returns a structured result:

| Property | Description | |----------|-------------| | isFulfilled | true if execution succeeded, false if error | | value | Return value (success) or error object (failure) | | profiling | Execution timing and performance data | | logging | Captured console output (log, warn, error, etc.) |

Options

const myFn = createFunction(code, {
  // Browserless instance factory
  getBrowserless: () => require('browserless')(),
  
  // Number of retries on failure
  retry: 2,
  
  // Execution timeout in milliseconds
  timeout: 30000,
  
  // Options passed to browserless.goto()
  gotoOpts: {
    scripts: ['https://cdn.example.com/library.js'],
    waitUntil: 'networkidle0'
  },
  
  // VM sandbox options (passed to isolated-function)
  vmOpts: { /* ... */ }
})

Examples

Interact with page elements

const createFunction = require('@browserless/function')

const code = async ({ page }) => {
  await page.waitForSelector('button.submit')
  await page.type('input', '[email protected]', { delay: 200 })
  await page.click('button.submit')
  await page.waitForNavigation()
  return page.title()
}

const clickAndGetTitle = createFunction(code)
const result = await clickAndGetTitle('https://example.com')

Inject external scripts

const createFunction = require('@browserless/function')

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

const getjQueryVersion = createFunction(code, {
  gotoOpts: {
    scripts: ['https://code.jquery.com/jquery-3.6.0.min.js']
  }
})

const result = await getjQueryVersion('https://example.com')
// => { isFulfilled: true, value: '3.6.0', ... }

Use npm modules in sandbox

const createFunction = require('@browserless/function')

const code = async ({ page }) => {
  const _ = require('lodash')
  const text = await page.evaluate(() => document.body.innerText)
  return _.words(text).length
}

const countWords = createFunction(code)
const result = await countWords('https://example.com')

Handle errors

const createFunction = require('@browserless/function')

const code = () => {
  throw new Error('Something went wrong')
}

const myFn = createFunction(code)
const result = await myFn('https://example.com')

console.log(result.isFulfilled) // => false
console.log(result.value.message) // => 'Something went wrong'

How it fits in the monorepo

This is an extended functionality package for advanced use cases. It makes the repository more extensible and customizable for any edge case you may encounter.

Dependencies

| Package | Purpose | |---------|---------| | @browserless/errors | Error normalization and typed errors | | isolated-function | Secure VM sandbox execution | | require-one-of | Auto-detects browserless installation | | acorn / acorn-walk | AST parsing to detect page usage in code |

License

@browserless/functions © Microlink, released under the MIT License. Authored and maintained by Microlink with help from contributors.

The logo has been designed by xinh studio.

microlink.io · GitHub microlinkhq · X @microlinkhq