Canvas API fetch from browser returns while(1); prefix
@alex-epstein▲ 1 net votes
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.