Cloudflare - v1.3.0
    Preparing search index...

    Class BrowserBinding<E>

    Accessor for the Browser Rendering binding.

    Browser Rendering was the one binding in this package with no accessor, which meant the one Worker using it reached env.BROWSER directly. An absent binding therefore arrived at the browser driver as undefined and failed somewhere inside it, in that library's terms rather than in terms of the deployment that forgot to declare it. This class makes that a MissingBindingError naming BROWSER, like every other resource.

    Every other binding here has a capability service beside it. This one does not, and that is deliberate. Doing anything with a browser beyond holding the binding means driving it — launching, navigating, evaluating — which needs @cloudflare/puppeteer, a real runtime dependency rather than a type. Taking it on would put a browser automation library in the dependency tree of every Worker that installs this package to get a KV accessor.

    The driving itself also has exactly one consumer today, and a capability with one implementation and one caller has not yet earned the interface. If a second appears, the shape to copy is ./middlewares: a separate subpath behind an optional peer, so a consumer that does not render pages never resolves the dependency.

    Fetcher rather than a browser-library type for the same reason — it is what the runtime hands over, and naming it costs no dependency.

    const browser = new BrowserBinding()

    if (!browser.isBound(env)) {
    return fail('This deployment cannot render pages')
    }

    const session = await puppeteer.launch(browser.resolve(env))

    Bayu Dwiyan Satria

    1.0.0

    1.3.0

    Type Parameters

    Hierarchy (View Summary)

    Index
    • get name(): string

      The binding name this instance resolves.

      Returns string

      The binding name as declared in wrangler.json.

    • Checks whether the binding is available on the given environment.

      Use this to degrade gracefully when a binding is optional.

      Parameters

      • env: E

        The Worker environment.

      Returns boolean

      true when the binding is present.

    • Resolves the binding without throwing.

      Parameters

      • env: E

        The Worker environment.

      Returns Fetcher<undefined, never>

      The resolved binding, or null when it is not configured.