core icon indicating copy to clipboard operation
core copied to clipboard

browser.setCookie is not a function` when using `hubBrowser()` in production

Open zangetsu02 opened this issue 6 months ago • 0 comments

Describe the bug When I try to generate a PDF of a protected Nuxt page using hubBrowser(), authentication fails because I cannot set cookies—browser.setCookie is not defined in the production build.

Steps to reproduce Steps to reproduce the behavior:

  1. In a Nuxt endpoint:
export default defineEventHandler(async (event) => {
  const session_token = getCookie(event, 'better-auth.session_token')
  const { page, browser } = await hubBrowser()
  browser.setCookie({
    name: 'better-auth.session_token',
    value: session_token,
    domain: 'localhost',
    path: '/',
    sameParty: true,
    httpOnly: true,
    secure: false,
  })
  const id = Number.parseInt(event.context.params!.id) as number
  await page.goto(`${getRequestURL(event).origin}/ddt/${id}/_pdf`)
  setHeader(event, 'Content-Type', 'application/pdf')
  return page.pdf({ format: 'A4' })
})
  1. Build and deploy to production
  2. Invoke the api

What is Expected? The hubBrowser() API should expose a setCookie (or equivalent) method so I can pass my session/auth cookies before navigating.

PDF generation succeeds without authentication errors.

The nuxt hub logs Image

In the develpment enviroment, this works perfectly

zangetsu02 avatar May 30 '25 14:05 zangetsu02