Skip to content

fix: log error when saveAs is called from a web worker#1

Closed
ynsacc2024-sys wants to merge 2 commits into
masterfrom
fix/web-worker-saveas-error
Closed

fix: log error when saveAs is called from a web worker#1
ynsacc2024-sys wants to merge 2 commits into
masterfrom
fix/web-worker-saveas-error

Conversation

@ynsacc2024-sys

Copy link
Copy Markdown
Owner

Fixes eligrey#778saveAs() was silently a no-op when called from a web worker,
leaving developers guessing why their download didn't happen. This change
replaces the silent no-op with a console.error that includes a link to the
original issue for context.

Changes

  • src/FileSaver.js (line 76–77): /* noop */console.error('…')
  • Adds a test suite (mocha + jsdom). The project previously had echo "Error: no test specified" && exit 0 as its npm test script, so this is its first
    real test coverage.
  • 4 new tests, all passing locally with npm test.

Behavior change

Any code path that relied on the silent no-op will now see a console error.
This is intentional — silent failures are worse than visible ones. If a
stricter behavior (throw) is preferred, happy to swap console.error for a
thrown Error in a follow-up.

Closes eligrey#779 (which proposed essentially this fix 3 years ago).

Adds 4 tests covering:
- web worker no-op behavior (eligrey#779, fixes silent failure from eligrey#778)
- module loading via <script> tag (window.saveAs attached)
- module loading via CommonJS (module.exports == window.saveAs)
- no-throw sanity check for normal browser load

Upstream previously had 'Error: no test specified && exit 0' as the test
script, so this is the project's first real test coverage.
Fixes eligrey#778, addresses the proposal in eligrey#779.

saveAs() was a silent no-op when called from a web worker, leaving developers
guessing why their download didn't happen. Replace the no-op with a
console.error that points to the original issue for context.

Behavior change: any code path that relied on the silent no-op will now see
a console error. In practice this is desirable since it surfaces a real
programming error; if a stricter behavior (throw) is preferred, a follow-up
can swap console.error for a thrown Error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

saveAs fails on chrome with no error

1 participant