Skip to content

Transformers.js benchmarks fail to run on Safari Beta with TypeError: undefined is not a function (near '...e of A...') #135

Description

@sudonatalie

Safari: Version 26.4 (21624.1.16.11.4)

When running the suite of tests on Safari Beta (to access WebGPU), I see all Transformers.js workloads failing with the same error of the form:

[Error] Workload Feature-Extraction-wasm failed:
Error: Workload Feature-Extraction-wasm encountered an error: TypeError: undefined is not a function (near '...e of A...')
errorHandler — benchmark-runner.mjs:425
dispatchEvent
(anonymous function) — suite-runner.mjs:123
	runAllSuites (benchmark-runner.mjs:442)

The AI-suggested fix that does resolve this for me is a polyfill that retrofits Symbol.asyncIterator onto the global ReadableStream prototype if it's missing:

diff --git a/resources/shared/benchmark.mjs b/resources/shared/benchmark.mjs
index 2bb28d2..6f3e179 100644
--- a/resources/shared/benchmark.mjs
+++ b/resources/shared/benchmark.mjs
@@ -2,6 +2,21 @@
 import { StepRunner, AsyncStepRunner } from "./step-runner.mjs";
 import { Params } from "./params.mjs";
 
+if (typeof ReadableStream !== "undefined" && !ReadableStream.prototype[Symbol.asyncIterator]) {
+    ReadableStream.prototype[Symbol.asyncIterator] = async function* () {
+        const reader = this.getReader();
+        try {
+            while (true) {
+                const { done, value } = await reader.read();
+                if (done) return;
+                yield value;
+            }
+        } finally {
+            reader.releaseLock();
+        }
+    };
+}
+
 /**
  * BenchmarkStep
  *

I don't see these errors on the the Safari Technology Preview (Release 240 (WebKit 21625.1.10.19.3)), so not sure if this is worth fixing, but thought I'd note it in case other's hit the same issue when running on other browsers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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