Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues of Playwright 1.49.0 #547

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
node-version: ${{ matrix.node }}
- run: yarn install
- run: yarn playwright-core install chromium
- run: yarn playwright-core install chromium --no-shell
- run: yarn build
- run: yarn test
build-and-push-image:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"clean": "shx rm -rf dist tmp",
"dev": "tsc -w --preserveWatchOutput",
"example": "yarn --cwd example build",
"pretest": "playwright-core install chromium",
"pretest": "playwright-core install chromium --no-shell",
"release": "release-it",
"release:pre": "release-it --preRelease --npm.tag=next",
"test": "vitest run --coverage",
Expand Down
23 changes: 7 additions & 16 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export async function launchBrowser({
'--allow-file-access-from-files',
disableWebSecurity ? '--disable-web-security' : '',
disableDevShmUsage ? '--disable-dev-shm-usage' : '',
// #357: Set devicePixelRatio=1 otherwise it causes layout issues in HiDPI displays
headless ? '--force-device-scale-factor=1' : '',
// set Chromium language to English to avoid locale-dependent issues (e.g. minimum font size)
'--lang=en',
...(!headless && process.platform === 'darwin'
Expand All @@ -63,8 +65,7 @@ export async function launchBrowser({
}

export function getExecutableBrowserPath(browserType: BrowserType): string {
const executable = registry.findExecutable(getBrowserName(browserType))!;
return executable.executablePath()!;
return playwright[browserType].executablePath();
}

export function getFullBrowserName(browserType: BrowserType): string {
Expand All @@ -80,29 +81,19 @@ export function checkBrowserAvailability(path: string): boolean {
}

export function isPlaywrightExecutable(path: string): boolean {
return registry
.executables()
.some((exe) => pathEquals(exe.executablePath() ?? '', path));
return [playwright.chromium, playwright.firefox, playwright.webkit].some(
(exe) => pathEquals(exe.executablePath() ?? '', path),
);
}

export async function downloadBrowser(
browserType: BrowserType,
): Promise<string> {
const executable = registry.findExecutable(getBrowserName(browserType))!;
const executable = registry.findExecutable(browserType);
logInfo('Rendering browser is not installed yet. Downloading now...');
const restartLogging = suspendLogging();
await registry.install([executable], false);
logSuccess(`Successfully downloaded browser`);
restartLogging();
return executable.executablePath()!;
}

function getBrowserName(
browserType: BrowserType,
): BrowserType | 'chromium-headless-shell' {
if (browserType === 'chromium' && !process.argv[1].endsWith('preview.js')) {
return 'chromium-headless-shell';
} else {
return browserType;
}
}