Next.js Discord

Discord Forum

(literally) use playwright in Nextjs app

Unanswered
Balinese posted this in #help-forum
Open in Discord
BalineseOP
i want to literally use playwright inside a server-side route. reason being that it has some features that I want to use.

example:
import type { NextApiRequest, NextApiResponse } from "next";
import { chromium } from 'playwright'

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse,
) {
  const browser = await chromium.launch()
  const page = await browser.newPage();
  // do some stuff i wanted to do, not for E2E testing
}


this code generates this error when accessing the route:
../../node_modules/.pnpm/playwright-core@1.44.1/node_modules/playwright-core/lib/vite/recorder/assets/codicon-DMa5iZz2.ttf
Module parse failed: Unexpected character '' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

0 Replies