@browserless/goto

中文文档
14.1.6发布于 2026/11/07MITCommonJS近 30 天下载 2.5万

Navigate to web pages with built-in ad blocking, device emulation, and optimized loading for faster automation.

原始使用文档
文档目录15 节
  1. Install
  2. About
  3. What this package does
  4. Usage
  5. Options
  6. Smart waiting with waitUntil: 'auto'
  7. Built-in Ad Blocker
  8. Notifications
  9. Script and style injection
  10. Request interception
  11. Device emulation
  12. Return value
  13. How it fits in the monorepo
  14. Dependencies
  15. License
browserless browserless

Powered by microlink.io Last version Coverage Status NPM Status

@browserless/goto: Go to a page aborting unnecessary requests.

See the Go To section on our website for more details.

Install

Using npm:

npm install @browserless/goto --save

About

This package provides advanced page navigation with built-in ad blocking, smart waiting strategies, and extensive customization options. It's the core navigation engine that powers all browserless page loading operations.

What this package does

The @browserless/goto package allows you to:

  • Navigate to pages with optimized loading and smart waiting strategies
  • Block ads and trackers using a precompiled Ghostery ad-blocker engine
  • Inject scripts, modules, and styles into pages
  • Emulate devices with viewport, user agent, and media features
  • Intercept and abort requests by resource type
  • Handle cookies and HTTP authentication

Usage

const createGoto = require('@browserless/goto')
const puppeteer = require('puppeteer')

const goto = createGoto({ 
  timeout: 30000,
  defaultDevice: 'Macbook Pro 13'
})

const browser = await puppeteer.launch()
const page = await browser.newPage()

const { response, device, error } = await goto(page, {
  url: 'https://example.com',
  adblock: true,
  waitUntil: 'auto'
})

Options

OptionTypeDefaultDescription
urlstring—Target URL to navigate to
htmlstring—HTML content to render (instead of URL)
adblockbooleantrueEnable built-in ad blocker
waitUntilstring|string[]'auto'Navigation wait condition
timeoutnumber30000Navigation timeout in ms
devicestring'Macbook Pro 13'Device to emulate; a desktop device supplies the viewport, while the platform token inside the user agent follows the host OS
headersobject{}Extra HTTP headers
javascriptbooleantrueEnable/disable JavaScript
notificationsbooleanfalseAllow the notifications permission prompt
animationsbooleanfalseEnable CSS animations
colorSchemestring—'light' or 'dark' preference
flattenShadowDOMbooleanfalse (true for html())Serialize open shadow DOM into HTML (mutates the page DOM; closed shadow roots are skipped)
mediaTypestring—CSS media type ('screen', 'print')
timezonestring—Timezone to emulate
authenticateobject—HTTP authentication credentials
scriptsstring|string[]—Scripts to inject
modulesstring|string[]—ES modules to inject
stylesstring|string[]—Stylesheets to inject
clickstring|string[]—CSS selectors to click
scrollstring—CSS selector to scroll into view
abortTypesstring[][]Resource types to abort
waitForSelectorstring—Wait for selector to appear
waitForFunctionstring—Wait for function to return truthy
waitForTimeoutnumber—Wait for specified milliseconds
onPageRequestfunction—Request interception handler

Smart waiting with waitUntil: 'auto'

The default 'auto' mode intelligently waits for page readiness:

// Auto mode combines 'load' with 'networkidle2' smartly
await goto(page, { url: 'https://example.com', waitUntil: 'auto' })

// Standard Puppeteer wait conditions also supported
await goto(page, { url: 'https://example.com', waitUntil: 'networkidle0' })
await goto(page, { url: 'https://example.com', waitUntil: ['load', 'domcontentloaded'] })

Built-in Ad Blocker

The package includes a precompiled Ghostery ad-blocker engine that blocks ads and trackers automatically:

// Enabled by default
await goto(page, { url: 'https://example.com', adblock: true })

// Disable for specific pages
await goto(page, { url: 'https://example.com', adblock: false })

// The adblocker can be disabled mid-session
page.disableAdblock()

Cookie consent handling (opt-out) is included as part of adblock: true and powered by duckduckgo/autoconsent.

adblock: true also dismisses generic announcement dialogs that autoconsent does not cover: ARIA dialogs (role="dialog", role="alertdialog", aria-modal, <dialog open>) with no consent language and a single acknowledge-style button ("I understand", "Got it", "OK", or an aria-label="close" button). Dialogs containing form fields are left untouched unless they expose an explicit close button, and only <button> elements are clicked so a dismissal can never navigate. It also covers notification/push opt-in overlays that carry no dialog role, such as the one AliExpress renders over its header: those are clicked only when the copy is about notifications, the overlay sits in a positioned container smaller than the viewport, it holds no form fields and no consent language, and it exposes an explicitly dismissive control ("Not now", "No permitir", "Nicht jetzt", an aria-label="close" affordance). The affirmative control ("Allow", "Permitir") is never clicked, and a control inside a link is skipped so a dismissal cannot navigate.

Notifications

Notifications are denied by default, so sites skip the overlays they render to ask for them. Notification.permission and navigator.permissions.query({ name: 'notifications' }) both read denied, the pair of values Chrome reports for a user who blocked notifications, and window.Notification stays exposed as in stock Chrome.

The permission belongs to the page's browser context and is applied on every navigation, so pages sharing a context share the value, and a page driven without goto keeps Chrome's default.

// denied (default)
await goto(page, { url: 'https://example.com' })

// Chrome's out-of-the-box state, where `Notification.permission` reads `default`
await goto(page, { url: 'https://example.com', notifications: true })

Script and style injection

Inject external resources or inline code:

await goto(page, {
  url: 'https://example.com',
  // External URLs
  scripts: ['https://cdn.example.com/library.js'],
  // ES modules
  modules: ['https://cdn.example.com/module.mjs'],
  // CSS (URLs, paths, or inline)
  styles: [
    'https://cdn.example.com/styles.css',
    'body { background: red; }'
  ]
})

Request interception

Abort specific resource types to speed up navigation:

await goto(page, {
  url: 'https://example.com',
  abortTypes: ['image', 'stylesheet', 'font', 'media'],
  onPageRequest: (request, page) => {
    console.log('Request:', request.url())
  }
})

Device emulation

// Use preset device
await goto(page, { url: 'https://example.com', device: 'iPhone 13' })

// Custom viewport
await goto(page, {
  url: 'https://example.com',
  viewport: { width: 1920, height: 1080 }
})

// Custom headers
await goto(page, {
  url: 'https://example.com',
  headers: {
    'user-agent': 'custom-agent',
    'cookie': 'session=abc123'
  }
})

Return value

The goto function returns:

const { response, device, error } = await goto(page, { url })

// response: Puppeteer Response object (or undefined if navigation failed)
// device: { userAgent, viewport } used for the request
// error: Error object if navigation failed

How it fits in the monorepo

This is the core navigation engine used by the entire browserless ecosystem:

ConsumerPurpose
browserless (core)Powers .goto(), .html(), .text(), .pdf(), .screenshot()
@browserless/screenshotNavigation before capturing screenshots
@browserless/pdfNavigation before generating PDFs
@browserless/functionNavigation for sandboxed function execution
@browserless/lighthouseNavigation for Lighthouse audits

Dependencies

PackagePurpose
@browserless/devicesDevice descriptor lookups and emulation
@ghostery/adblocker-puppeteerAd and tracker blocking
debug-logfmtStructured debug logging
gotHTTP client for postinstall script
is-url-httpDetect if value is URL for injection
p-reflect / p-timeoutPromise utilities for timeouts
shallow-equalViewport comparison optimization
tough-cookieCookie string parsing

License

@browserless/goto © 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

版本与发布记录

@browserless/goto 共发布 394 个版本,首次发布于 2019/01/28;过去 12 个月发布了 95 个版本。

版本发布日期距今
14.1.6latest2026/11/071 天前
14.1.52026/11/062 天前
14.1.42026/11/062 天前
14.1.22026/11/035 天前
14.1.12026/11/026 天前
14.0.332026/10/2712 天前

关于 @browserless/goto 的常见问题

@browserless/goto 是什么?

Navigate to web pages with built-in ad blocking, device emulation, and optimized loading for faster automation.

如何安装 @browserless/goto?

在项目目录运行 npm install @browserless/goto,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:puppeteer(25)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@browserless/goto 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/browserless__goto 是否存在。

@browserless/goto 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@browserless/goto 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@browserless/goto 可以商用吗?

@browserless/goto 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@browserless/goto 的下载量有多少?

根据 npm 官方下载统计,@browserless/goto 在 2026/10/09 – 2026/11/07 这 30 天内被下载 24,713 次,日均约 824 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@browserless/goto 还在维护吗?

最新版本 14.1.6 发布于 2026/11/07(1 天前);至今共发布 394 个版本,其中过去 12 个月发布了 95 个;首次发布于 2019/01/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。