Skip to content

[Bug]: Playwright Automation Incompatibility with Bitstreaming Download (StreamSaver.js) #39482

@RShettyMM

Description

@RShettyMM

Version

1.57.0

Steps to reproduce

Environment

  • Playwright Version: 1.57.0
  • Operating System: Linux (Azure DevOps Agent) / Windows (Local)
  • Browser: Chromium
  • Environment: Headless CI (Azure Pipelines)

Problem Description

We are experiencing significant flakiness and consistent failures in our CI environment when attempting to automate and verify file downloads. Our application utilizes StreamSaver.js to handle large backup files

Because StreamSaver uses a Service Worker to pipe data through a WritableStream directly to the filesystem, Playwright's standard page.waitForEvent('download') is often bypassed or fails to trigger.

While the feature works correctly on local headed/headless machines, the CI environment (Azure DevOps) frequently encounters:

  1. Download Event Timeouts: The event never fires despite the UI showing successful bitstreaming progress.
  2. Service Worker/CSP Interruption: Site isolation or Content Security Policy (CSP) in headless mode seems to interfere with the stream's ability to signal a completion that Playwright can recognize.

Current Workaround

We have implemented a custom interceptor using page.addInitScript to "hook" into the StreamSaver lifecycle:

await page.addInitScript(() => {
    const originalCreateWriteStream = (window as any).streamSaver?.createWriteStream;
    if (originalCreateWriteStream) {
        (window as any).streamSaver.createWriteStream = (filename, options) => {
            const writer = originalCreateWriteStream(filename, options);
            const originalClose = writer.close.bind(writer);
            writer.close = async () => {
                await originalClose();
                (window as any).streamSaver_finished = true; // Custom signal
            };
            return writer;
        };
    }
});

Despite this, we still encounter timing issues where the backend "preparation phase" (calculating metadata) causes the UI to report 0.0 Ki processed for longer than 60 seconds, leading to false-positive test failures.

Questions/Requests for Support

  1. Is there a native Playwright method to reliably intercept or monitor WritableStream or Service Worker-initiated downloads that do not follow the standard Content-Disposition attachment flow?
  2. Recommended Launch Arguments: Are there specific Chromium flags beyond --disable-web-security and bypassCSP: true that should be enabled in Azure DevOps agents to ensure Service Worker-based streaming is fully stable?
  3. Handling Zero-Byte Streams: How can we best distinguish between a slow-starting stream (backend calculation) and a failed stream connection without relying on brittle UI text polling?

Attachments

  • Playwright Config: (See attached playwright.config.ts)

index.html

  • Page Object Logic: (See attached backupRestorePage.ts)
  • Test Report: (See attached index.html)

Expected behavior

Download completed successfully.

Actual behavior

Test timeout of 150000ms exceeded.
Error: page.waitForTimeout: Test timeout of 150000ms exceeded.

at ../pages/clusterManager/backupRestorePage.ts:249

247 | throw new Error(❌ Backend failed to stream data after ${initialProcessingTimeout / 1000}s (Stuck at 0.0 Ki). Check system logs for lock failures.);
248 | }

249 | await page.waitForTimeout(2000);
| ^
250 | }
251 | });
252 |
at /__w/3/s/EPU_ui-test/pages/clusterManager/backupRestorePage.ts:249:32
at /__w/3/s/EPU_ui-test/pages/clusterManager/backupRestorePage.ts:206:13
at BackupRestorePage.clickStartBackupAndWaitForDownload (/__w/3/s/EPU_ui-test/pages/clusterManager/backupRestorePage.ts:167:16)
at /__w/3/s/EPU_ui-test/tests/02-clusterManagement/026-epp.backuprestore.spec.ts:70:9

index.html

Additional context

No response

Environment

Starting: Execute tests: 026-epp.backuprestore.spec.ts
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.231.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /__w/_temp/8902cb51-88e2-4a0f-acbb-5bcc4556bf18.sh
EPU_ui-test.code-workspace  node_modules       pipelines	      tests
GitVersion.yml		    package-lock.json  playwright.config.ts   utils
README.md		    package.json       switch-to-local.ps1
fixtures		    pages	       switch-to-nightly.ps1
Script use Test Plan with Id: 572956
Playwright-config use Test Plan with Id:  572956
TEST_CONFIG {"network":{"name":"epu-mm-test-05","ipAddress_IT":"10.58.229.161","ipAddress_OT":"10.1.99.88"}}
Network Name:  epu-mm-test-05
ipAddress_IT:  10.58.229.161
ipAddress_OT:  10.1.99.88
2026-03-02T10:53:34.311Z azure:pw:log [794099] TC-BACKUP_VERIFY_INITIAL_STATE: Verify No Modules Selected Initially - skipped
2026-03-02T10:56:12.916Z azure:pw:log [777210] [794250] TC-BACKUP: Complete Backup for Cluster settings Only - timedOut
2026-03-02T10:56:13.364Z azure:pw:log [777211] [794145] TC-BACKUP: Complete Backup for SEW Packages Only - skipped
2026-03-02T10:58:51.826Z azure:pw:log [777212] [794240] TC-BACKUP: Complete Backup for Application Installations Only - timedOut
2026-03-02T10:58:51.827Z azure:pw:log [777214] [794143] TC-BACKUP: Complete Backup with Cluster Settings and SEW Packages Simultaneously Installations - skipped
2026-03-02T10:58:51.827Z azure:pw:log [794232] TC-BACKUP: Complete Backup with SEW Packages and Application Installations - skipped
2026-03-02T10:58:51.827Z azure:pw:log [794144] TC-BACKUP: Complete backup with Cluster Settings and Application Installations Only - skipped
2026-03-02T10:58:51.828Z azure:pw:log [777215] TC-BACKUP: Select All Backup Modules and then Deselect All Modules and Verify Total Count Matches Selected Items - skipped
2026-03-02T10:58:51.828Z azure:pw:log [790271] TC-BACKUP: Deselect Previously Selected Module and Verify Count Decreases - skipped
2026-03-02T10:58:51.829Z azure:pw:log [777217] [777218]TC-BACKUP: Click Confirm Selection for Cluster Settings Backup completion and verify download - skipped
2026-03-02T10:58:51.829Z azure:pw:log [777219] [777220] TC-BACKUP: Complete Backup Process and Download Backup File to Local Machine Successfully - skipped
2026-03-02T10:58:51.829Z azure:pw:log [794146] TC-BACKUP: Deselect and Reselect Same Module - skipped
2026-03-02T10:58:51.829Z azure:pw:log [794255] TC-BACKUP: Perform Two Consecutive Backups - skipped
2026-03-02T10:58:51.829Z azure:pw:log [794256] TC-BACKUP: Toggle Same Module Multiple Times Before Confirmation - skipped
2026-03-02T10:58:52.062Z azure:pw:log Using run 1544792 to publish test results
2026-03-02T10:58:52.062Z azure:pw:log AZURE_PW_TEST_RUN_ID: 1544792
2026-03-02T10:58:52.063Z azure:pw:log Start publishing test results for 14 test(s)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions