Skip to content

eegprep-lean: PyfetchTransport's User-Agent header fails every read in Safari and Firefox #419

Closed

Description

@neuromechanist

What happens

In Safari and Firefox, every read through PyfetchTransport fails, so a JupyterLite or Pyodide notebook cannot load a NEMAR dataset with eegprep-lean. Chrome works.

PyfetchTransport.get (packages/eegprep-lean/src/eegprep_lean/transport.py) sends User-Agent: eegprep-lean on every request. Chrome drops a User-Agent set by a script, so its requests stay simple. WebKit and Firefox send it, which makes each read a CORS preflighted request. zarr.nemar.org allows only Range in Access-Control-Allow-Headers, so the preflight is refused:

Request header field User-Agent is not allowed by Access-Control-Allow-Headers.

Measured in headless WebKit 26.6 and Firefox 155 (Playwright 1.63) against zarr.nemar.org, with Chrome 153 as the control, for OpenScience-Collective/osa#496. The same request without the header answers 200, and with Range 206, in all three. With a transport that sends no User-Agent, the WebKit kernel reads nm000132 (240 stores, then a (4, 500) window in uV at 250 Hz).

In WebKit this showed up as a hang rather than an error, because of a separate Pyodide fault with stackless rejections that OSA works around in OpenScience-Collective/osa#502. With that fix, the read raises TransportError instead, and still fails.

Fix

Send only Range from PyfetchTransport, as FetchTransport already does, for the reason its docstring gives. Keep USER_AGENT for UrllibTransport, where it matters (the NEMAR hosts refuse the default Python-urllib agent). The comment on USER_AGENT saying "Browsers set their own and ignore this" is true of Chrome only, and should say so.

Allowing User-Agent on the NEMAR hosts instead would add a preflight to every chunk read in Safari and Firefox, so the client-side change is the better one.

After the fix

OSA vendors the wheel by commit (src/assistants/nemar/runtime/, see its README), and the notebook site serves that same wheel, so the fix reaches readers through a re-vendor in OSA, not a PyPI release.

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