Skip to content

Commit 3313c4b

Browse files
committed
Add support for prefers-reduced-motion
1 parent c639be1 commit 3313c4b

File tree

6 files changed

+27
-40
lines changed

6 files changed

+27
-40
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ services:
5757
WS_PORT: 8081
5858
DEBUG_PORT: 9221 # internal debug port
5959
HEALTH_PORT: 18080
60+
PREFERS_REDUCED_MOTION: false
6061
USER_DATA_DIR: /pw-data
6162
ports:
6263
- "8081:8081" # WebSocket stream

docker-compose.rwv.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ services:
1818
WS_PORT: 8081
1919
DEBUG_PORT: 9221 # internal debug port
2020
HEALTH_PORT: 18080
21+
PREFERS_REDUCED_MOTION: true
2122
USER_DATA_DIR: /pw-data
2223
ports:
2324
- "8081:8081"

dockerfile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
FROM mcr.microsoft.com/playwright:v1.55.0-jammy AS deps
22
WORKDIR /app
33
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
4-
PLAYWRIGHT_BROWSERS_PATH=/ms-playwright \
5-
NODE_OPTIONS="--unhandled-rejections=strict"
4+
PLAYWRIGHT_BROWSERS_PATH=/ms-playwright \
5+
NODE_OPTIONS="--unhandled-rejections=strict"
66
COPY package.json package-lock.json ./
77
RUN npm ci --no-audit --no-fund
88

@@ -15,15 +15,12 @@ FROM build AS prod-deps
1515
RUN npm prune --omit=dev
1616

1717
FROM mcr.microsoft.com/playwright:v1.55.0-jammy AS runner
18-
ENV NODE_ENV=production
1918
WORKDIR /app
20-
21-
# USER pwuser
22-
19+
ENV NODE_ENV=production \
20+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
21+
PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
2322
COPY --from=prod-deps /app/node_modules ./node_modules
2423
COPY --from=build /app/dist ./dist
2524
COPY self-test ./self-test
26-
2725
EXPOSE 8080 8081 9221
2826
CMD ["node", "dist/index.js"]
29-

src/antiAnim.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/browser.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { chromium } from 'playwright-core';
33
import { initCdpRootAsync, waitForCdpReadyAsync } from './cdpRoot.js';
44

55
const DEBUG_PORT = +(process.env.DEBUG_PORT || 9221);
6+
const PREFERS_REDUCED_MOTION = /^(1|true|yes|on)$/i.test(process.env.PREFERS_REDUCED_MOTION ?? '');
67
const USER_DATA_DIR = process.env.USER_DATA_DIR || (process.platform === 'win32'
78
? 'C:\\Temp\\remotewebview-profile'
89
: '/var/temp/remotewebview-profile');
@@ -22,15 +23,20 @@ async function startHeadlessIfNeededAsync(): Promise<void> {
2223
if (info?.webSocketDebuggerUrl) return;
2324

2425
await mkdir(USER_DATA_DIR, { recursive: true });
26+
const args = [
27+
`--remote-debugging-port=${DEBUG_PORT}`,
28+
'--no-sandbox',
29+
'--force-device-scale-factor=1',
30+
'--headless=new',
31+
...(PREFERS_REDUCED_MOTION ? ['--force-prefers-reduced-motion'] : []),
32+
];
33+
34+
if (PREFERS_REDUCED_MOTION)
35+
console.log('[browser] Launching with prefers-reduced-motion');
2536

2637
await chromium.launchPersistentContext(USER_DATA_DIR, {
2738
headless: true,
28-
args: [
29-
`--remote-debugging-port=${DEBUG_PORT}`,
30-
'--no-sandbox',
31-
'--force-device-scale-factor=1',
32-
'--headless=new',
33-
],
39+
args,
3440
});
3541

3642
const t0 = Date.now();

src/deviceManager.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { DeviceConfig, deviceConfigsEqual } from "./config.js";
44
import { getRoot } from "./cdpRoot.js";
55
import { FrameProcessor } from "./frameProcessor.js";
66
import { DeviceBroadcaster } from "./broadcaster.js";
7-
import { installAntiAnimCSSAsync } from "./antiAnim.js";
87
import { hash32 } from "./util.js";
98
import { SelfTestRunner } from "./selfTest.js";
109

@@ -26,6 +25,8 @@ export type DeviceSession = {
2625
lastProcessedMs?: number;
2726
};
2827

28+
const PREFERS_REDUCED_MOTION = /^(1|true|yes|on)$/i.test(process.env.PREFERS_REDUCED_MOTION ?? '');
29+
2930
const devices = new Map<string, DeviceSession>();
3031
let _cleanupRunning = false;
3132
export const broadcaster = new DeviceBroadcaster();
@@ -65,7 +66,12 @@ export async function ensureDeviceAsync(id: string, cfg: DeviceConfig): Promise<
6566
deviceScaleFactor: 1,
6667
mobile: true
6768
});
68-
await installAntiAnimCSSAsync(session);
69+
if (PREFERS_REDUCED_MOTION) {
70+
await session.send('Emulation.setEmulatedMedia', {
71+
media: 'screen',
72+
features: [{ name: 'prefers-reduced-motion', value: 'reduce' }],
73+
});
74+
}
6975

7076
await session.send('Page.startScreencast', {
7177
format: 'png',

0 commit comments

Comments
 (0)