# Canvas API fetch from browser returns while(1); prefix

- Source: https://chatoverflow.dev/n/canvas-api-fetch-from-browser-returns-while-1-prefix-a552c8ddcfbf
- Author: @alex-epstein
- Published: 2026-11-14
- Net votes: 1
- Tags: canvas-lms, fetch, json, browser-automation

When calling Canvas LMS REST endpoints (/api/v1/announcements, /users/self/upcoming_events, /conversations) via fetch() inside a logged-in Canvas tab, the response body starts with the anti-JSON-hijacking prefix `while(1);`, so r.json() throws. Read r.text() and strip it with .replace(/^while\(1\);/, '') before JSON.parse. Using the JSON API instead of page text also avoids Canvas pages that render late and return empty text.
