diff --git a/.github/workflows/player-safari.yml b/.github/workflows/player-safari.yml index 057ea172c6..fe81576848 100644 --- a/.github/workflows/player-safari.yml +++ b/.github/workflows/player-safari.yml @@ -14,10 +14,22 @@ on: - ".github/workflows/player-safari.yml" schedule: - cron: "23 7 * * *" + # One film many times: a fault that shows once in fifty runs needs hundreds of runs to prove gone. workflow_dispatch: + inputs: + fixtures: + description: "Films to run, comma-separated (empty runs every heavy film)" + default: "" + runs: + description: "Runs of each film" + default: "2" + browsers: + description: "Browsers, comma-separated" + default: "safari,chrome" concurrency: - group: player-safari-${{ github.ref }} + # Each dispatch is its own group: the runs of one proof go side by side instead of cancelling each other. + group: player-safari-${{ github.ref }}-${{ github.event_name == 'workflow_dispatch' && github.run_id || 'auto' }} cancel-in-progress: true jobs: @@ -66,9 +78,14 @@ jobs: - name: Run heavy films in Safari and Chrome working-directory: packages/player + env: + FIXTURES: ${{ inputs.fixtures }} + RUNS: ${{ inputs.runs || '2' }} + BROWSERS: ${{ inputs.browsers || 'safari,chrome' }} run: | sw_vers - CHROMEDRIVER="$CHROMEWEBDRIVER/chromedriver" bun run tests/perf/browsers/run.ts --browsers safari,chrome --runs 2 + CHROMEDRIVER="$CHROMEWEBDRIVER/chromedriver" bun run tests/perf/browsers/run.ts \ + --browsers "$BROWSERS" --runs "$RUNS" ${FIXTURES:+--fixtures "$FIXTURES"} - name: Upload results if: always() diff --git a/packages/core/src/runtime/pausedVideoFrames.test.ts b/packages/core/src/runtime/pausedVideoFrames.test.ts index 772a6f7f64..9d98d87ae7 100644 --- a/packages/core/src/runtime/pausedVideoFrames.test.ts +++ b/packages/core/src/runtime/pausedVideoFrames.test.ts @@ -269,6 +269,8 @@ it("does not retire an adopted decoded picture when its native snapshot lease en expect(video.currentTime).toBe(3); }); +const MAC_SAFARI = + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.2 Safari/605.1.15"; const MAC_CHROME = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36"; @@ -331,6 +333,7 @@ it("draws a held picture through a VideoFrame closed after the draw, else from t const video = document.createElement("video"); Object.defineProperty(video, "videoWidth", { value: 64 }); Object.defineProperty(video, "videoHeight", { value: 36 }); + vi.stubGlobal("navigator", { userAgent: MAC_CHROME }); vi.stubGlobal("VideoFrame", FakeVideoFrame); expect(captureNativeVideoFrame(video)?.width).toBe(64); const [first] = draws; @@ -350,3 +353,30 @@ it("draws a held picture through a VideoFrame closed after the draw, else from t expect(draws[1]?.source).toBe(video); vi.unstubAllGlobals(); }); + +// fails without the fix: seeking a film of 16 1080p videos, Safari never came back from making a VideoFrame of a +// video it had just paused. The frame route is for Chromium's image cache, which WebKit does not have. +it("draws a held picture from the video itself in WebKit, making no VideoFrame", () => { + const draws: unknown[] = []; + let framesMade = 0; + vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue({ + drawImage: (source: unknown) => draws.push(source), + } as unknown as CanvasRenderingContext2D); + const video = document.createElement("video"); + Object.defineProperty(video, "videoWidth", { value: 64 }); + Object.defineProperty(video, "videoHeight", { value: 36 }); + vi.stubGlobal("navigator", { userAgent: MAC_SAFARI }); + vi.stubGlobal( + "VideoFrame", + class { + constructor() { + framesMade++; + } + close() {} + }, + ); + expect(captureNativeVideoFrame(video)?.width).toBe(64); + expect(framesMade).toBe(0); + expect(draws).toEqual([video]); + vi.unstubAllGlobals(); +}); diff --git a/packages/core/src/runtime/pausedVideoFrames.ts b/packages/core/src/runtime/pausedVideoFrames.ts index 908cf6b0b6..511dd3158e 100644 --- a/packages/core/src/runtime/pausedVideoFrames.ts +++ b/packages/core/src/runtime/pausedVideoFrames.ts @@ -1,4 +1,4 @@ -import { MEDIA_ELEMENT_LEAD_SECONDS } from "./mediaClock"; +import { isWebKit, MEDIA_ELEMENT_LEAD_SECONDS } from "./mediaClock"; import { COLOR_GRADING_SOURCE_HIDDEN_ATTR } from "../colorGrading"; import { applyNativeVideoLook } from "./nativeVideoLook"; import { @@ -91,7 +91,10 @@ export function captureNativeVideoFrame(video: HTMLVideoElement): HTMLCanvasElem } } +const videoFrameOfAVideoCanHangThePage = isWebKit; + function videoFrameOf(video: HTMLVideoElement): VideoFrame | null { + if (videoFrameOfAVideoCanHangThePage()) return null; try { return new VideoFrame(video); } catch {