Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix: do not force swiftshader on chromium mac (#39129)
Dmitry Gozman6a6719eecd09
diff --git a/packages/playwright-core/src/server/bidi/bidiChromium.ts b/packages/playwright-core/src/server/bidi/bidiChromium.tsindex d44a2e2a38..1a78c23c65 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/40277080chromeArguments.push('--enable-unsafe-swiftshader');}diff --git a/packages/playwright-core/src/server/chromium/chromium.ts b/packages/playwright-core/src/server/chromium/chromium.tsindex b7d2dd294d..bcc69d40f1 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.tsindex 635d65d3d9..8df9ceb342 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;+ }+}