From 4577926411120b39b83f618177d7a58b82459df7 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Wed, 4 Feb 2026 14:15:14 +0000 Subject: [PATCH] fix: do not force swiftshader on chromium mac --- .../src/server/bidi/bidiChromium.ts | 3 ++- .../src/server/chromium/chromium.ts | 8 +++++--- .../src/server/utils/hostPlatform.ts | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/playwright-core/src/server/bidi/bidiChromium.ts b/packages/playwright-core/src/server/bidi/bidiChromium.ts index d44a2e2a38c52..1a78c23c655f2 100644 --- a/packages/playwright-core/src/server/bidi/bidiChromium.ts +++ b/packages/playwright-core/src/server/bidi/bidiChromium.ts @@ -23,6 +23,7 @@ import { kBrowserCloseMessageId } from './bidiConnection'; import { chromiumSwitches } from '../chromium/chromiumSwitches'; import { RecentLogsCollector } from '../utils/debugLogger'; import { waitForReadyState } from '../chromium/chromium'; +import { hasGpuMac } from '../utils/hostPlatform'; import type { BrowserOptions } from '../browser'; import type { SdkObject } from '../instrumentation'; @@ -114,7 +115,7 @@ export class BidiChromium extends BrowserType { throw new Error('Arguments can not specify page to be opened'); const chromeArguments = [...chromiumSwitches(options.assistantMode)]; - if (os.platform() === 'darwin') { + if (os.platform() !== 'darwin' || !hasGpuMac()) { // See https://issues.chromium.org/issues/40277080 chromeArguments.push('--enable-unsafe-swiftshader'); } diff --git a/packages/playwright-core/src/server/chromium/chromium.ts b/packages/playwright-core/src/server/chromium/chromium.ts index b7d2dd294d5ef..bcc69d40f161b 100644 --- a/packages/playwright-core/src/server/chromium/chromium.ts +++ b/packages/playwright-core/src/server/chromium/chromium.ts @@ -22,7 +22,7 @@ import path from 'path'; import { chromiumSwitches } from './chromiumSwitches'; import { CRBrowser } from './crBrowser'; import { kBrowserCloseMessageId } from './crConnection'; -import { debugMode, headersArrayToObject, headersObjectToArray, } from '../../utils'; +import { debugMode, hasGpuMac, headersArrayToObject, headersObjectToArray } from '../../utils'; import { wrapInASCIIBox } from '../utils/ascii'; import { RecentLogsCollector } from '../utils/debugLogger'; import { ManualPromise } from '../../utils/isomorphic/manualPromise'; @@ -313,8 +313,10 @@ export class Chromium extends BrowserType { throw new Error('Arguments can not specify page to be opened'); const chromeArguments = [...chromiumSwitches(options.assistantMode, options.channel)]; - // See https://issues.chromium.org/issues/40277080 - chromeArguments.push('--enable-unsafe-swiftshader'); + if (os.platform() !== 'darwin' || !hasGpuMac()) { + // See https://issues.chromium.org/issues/40277080 + chromeArguments.push('--enable-unsafe-swiftshader'); + } if (options.headless) { chromeArguments.push('--headless'); diff --git a/packages/playwright-core/src/server/utils/hostPlatform.ts b/packages/playwright-core/src/server/utils/hostPlatform.ts index 635d65d3d98ce..8df9ceb34281a 100644 --- a/packages/playwright-core/src/server/utils/hostPlatform.ts +++ b/packages/playwright-core/src/server/utils/hostPlatform.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { execSync } from 'child_process'; import os from 'os'; import { getLinuxDistributionInfoSync } from './linuxUtils'; @@ -133,3 +134,17 @@ function toShortPlatform(hostPlatform: HostPlatform): ShortPlatform { } export const shortPlatform = toShortPlatform(hostPlatform); + +let hasGpuMacValue: boolean | undefined; + +export function hasGpuMac() { + try { + if (hasGpuMacValue === undefined) { + const output = execSync('system_profiler SPDisplaysDataType').toString(); + hasGpuMacValue = output.includes('Metal: Supported') || output.includes('Metal Support: Metal'); + } + return hasGpuMacValue; + } catch (e) { + return false; + } +}