Skip to content

[🐛 Bug]: Unable to obtain browser driver in Next.js Project #14745

@hharryz

Description

@hharryz

What happened?

Hi, there! I'm trying to deploy a Next.js project, and I encounter the bug when trying to use selenium-webdriver in my project for some scraper work, but when I try the smoke test, the following bug occurs:

Error: Unable to obtain browser driver.
        For more information on how to install drivers see
        https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/. Error: Unable to obtain Selenium Manager at /Users/harryz/code/nextjs-selenium/.next/server/bin/macos/selenium-manager
    at build (src/app/test.ts:7:66)
    at test (src/app/page.tsx:5:6)
   5 |
   6 | export default async function test() {
>  7 |     const driver = await new Builder().forBrowser(Browser.CHROME).build();
     |                                                                  ^
   8 |     try {
   9 |         await driver.get('http://localhost:3000');
  10 |         await driver.wait(until.titleIs('Next.js App'), 1000);
 ⨯ node_modules/.pnpm/[email protected]/node_modules/selenium-webdriver/common/driverFinder.js (38:1) @ getBinaryPaths
 ⨯ unhandledRejection: Error: Unable to obtain browser driver.
        For more information on how to install drivers see
        https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/. Error: Unable to obtain Selenium Manager at /Users/harryz/code/nextjs-selenium/.next/server/bin/macos/selenium-manager
    at build (src/app/test.ts:7:66)
    at test (src/app/page.tsx:5:6)
   5 |
   6 | export default async function test() {
>  7 |     const driver = await new Builder().forBrowser(Browser.CHROME).build();
     |                                                                  ^
   8 |     try {
   9 |         await driver.get('http://localhost:3000');
  10 |         await driver.wait(until.titleIs('Next.js App'), 1000);
  36 |     return binaryPaths(args)
  37 |   } catch (e) {
> 38 |     throw Error(
     | ^
  39 |       `Unable to obtain browser driver.
  40 |         For more information on how to install drivers see
  41 |         https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/. ${e}`,
 ⨯ node_modules/.pnpm/[email protected]/node_modules/selenium-webdriver/common/driverFinder.js (38:1) @ getBinaryPaths
 ⨯ unhandledRejection: Error: Unable to obtain browser driver.
        For more information on how to install drivers see
        https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/. Error: Unable to obtain Selenium Manager at /Users/harryz/code/nextjs-selenium/.next/server/bin/macos/selenium-manager
    at build (src/app/test.ts:7:66)
    at test (src/app/page.tsx:5:6)
   5 |
   6 | export default async function test() {
>  7 |     const driver = await new Builder().forBrowser(Browser.CHROME).build();
     |                                                                  ^
   8 |     try {
   9 |         await driver.get('http://localhost:3000');
  10 |         await driver.wait(until.titleIs('Next.js App'), 1000);
  36 |     return binaryPaths(args)
  37 |   } catch (e) {
> 38 |     throw Error(
     | ^
  39 |       `Unable to obtain browser driver.
  40 |         For more information on how to install drivers see
  41 |         https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/. ${e}`,

Note that it shouldn't be an issue of my PATH variable, etc, since I try to reproduce the bug by using node and nothing wrong happend and the selenium manager should automatically download the driver if there doesn't exist one(this is what happening when I try the smoke test with node)(node version v22.8.0).

I think it might be a problem in Next.js, hope you can help me figure that out.

To reproduce the bug, simply start a Next.js project, e.g.

pnpx create-next-app@latest
pnpm add selenium-webdriver
pnpm add -D typescript @types/selenium-webdriver

and the test code below:

import { Builder, Browser, By, Key, until } from  'selenium-webdriver';

import logging from 'selenium-webdriver/lib/logging';
let logger = logging.getLogger('webdriver')

export default async function test() {
    const driver = await new Builder().forBrowser(Browser.CHROME).build();
    try {
        await driver.get('http://localhost:3000');
        await driver.wait(until.titleIs('Next.js App'), 1000);
    } finally {
        await driver.quit();
    }
}

btw, Next.js with ver==14.x.. doesn't help either.

How can we reproduce the issue?

import { Builder, Browser, By, Key, until } from  'selenium-webdriver';

import logging from 'selenium-webdriver/lib/logging';
let logger = logging.getLogger('webdriver')

export default async function test() {
    const driver = await new Builder().forBrowser(Browser.FIREFOX).build();
    try {
        await driver.get('http://localhost:3000');
        await driver.wait(until.titleIs('Next.js App'), 1000);
    } finally {
        await driver.quit();
    }
}

Relevant log output

Error: Unable to obtain browser driver.
        For more information on how to install drivers see
        https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/. Error: Unable to obtain Selenium Manager at /Users/harryz/code/nextjs-selenium/.next/server/bin/macos/selenium-manager
    at build (src/app/test.ts:7:66)
    at test (src/app/page.tsx:5:6)
   5 |
   6 | export default async function test() {
>  7 |     const driver = await new Builder().forBrowser(Browser.CHROME).build();
     |                                                                  ^
   8 |     try {
   9 |         await driver.get('http://localhost:3000');
  10 |         await driver.wait(until.titleIs('Next.js App'), 1000);
 ⨯ node_modules/.pnpm/[email protected]/node_modules/selenium-webdriver/common/driverFinder.js (38:1) @ getBinaryPaths
 ⨯ unhandledRejection: Error: Unable to obtain browser driver.
        For more information on how to install drivers see
        https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/. Error: Unable to obtain Selenium Manager at /Users/harryz/code/nextjs-selenium/.next/server/bin/macos/selenium-manager
    at build (src/app/test.ts:7:66)
    at test (src/app/page.tsx:5:6)
   5 |
   6 | export default async function test() {
>  7 |     const driver = await new Builder().forBrowser(Browser.CHROME).build();
     |                                                                  ^
   8 |     try {
   9 |         await driver.get('http://localhost:3000');
  10 |         await driver.wait(until.titleIs('Next.js App'), 1000);
  36 |     return binaryPaths(args)
  37 |   } catch (e) {
> 38 |     throw Error(
     | ^
  39 |       `Unable to obtain browser driver.
  40 |         For more information on how to install drivers see
  41 |         https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/. ${e}`,
 ⨯ node_modules/.pnpm/[email protected]/node_modules/selenium-webdriver/common/driverFinder.js (38:1) @ getBinaryPaths
 ⨯ unhandledRejection: Error: Unable to obtain browser driver.
        For more information on how to install drivers see
        https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/. Error: Unable to obtain Selenium Manager at /Users/harryz/code/nextjs-selenium/.next/server/bin/macos/selenium-manager
    at build (src/app/test.ts:7:66)
    at test (src/app/page.tsx:5:6)
   5 |
   6 | export default async function test() {
>  7 |     const driver = await new Builder().forBrowser(Browser.CHROME).build();
     |                                                                  ^
   8 |     try {
   9 |         await driver.get('http://localhost:3000');
  10 |         await driver.wait(until.titleIs('Next.js App'), 1000);
  36 |     return binaryPaths(args)
  37 |   } catch (e) {
> 38 |     throw Error(
     | ^
  39 |       `Unable to obtain browser driver.
  40 |         For more information on how to install drivers see
  41 |         https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/. ${e}`,

Operating System

macOS

Selenium version

JavaScript "selenium-webdriver": "^4.26.0"

What are the browser(s) and version(s) where you see this issue?

Chrome 130.0.6723.117

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 130.0.6723.117

Are you using Selenium Grid?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!I-defectSomething is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions