Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bhollis
Copy link
Owner

@bhollis bhollis commented May 16, 2025

Apparently Microsoft SharePoint will render pages from its service worker after the first load. The service worker downloads a JSON document and then processes it into HTML to return to the browser. However, they fail to change the content type header of the response, so they are effectively stating "This is JSON". And of course if you say it's JSON, JSONView will display it as JSON.

This fixes it by specifically looking for a header that indicates we're getting a response from SharePoint, rather than trying to second-guess responses generically.

Fixes #210

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR centralizes JSON-detection logic into a shared module and adds a special case to ignore SharePoint service-worker responses that wrongly claim to be JSON.

  • Extracted common background logic (detection, storage, messaging) into background-common.ts
  • Updated Firefox and Chrome background scripts to use isEventJSON and installMessageListener
  • Special-cased detection of SharePoint pages by checking for the MicrosoftSharePointTeamServices header

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/content.ts Added trailing comma on errorPage invocation to align arguments
src/background-firefox.ts Switched to isEventJSON for header inspection; removed redundant listener and storage code
src/background-common.ts New shared module with isEventJSON, storage helpers (addJsonUrl, hasJsonUrl), and installMessageListener
src/background-chrome.ts Replaced inline detection and messaging with calls to shared isEventJSON and installMessageListener
Comments suppressed due to low confidence (3)

src/background-firefox.ts:13

  • [nitpick] The indentation level of this line appears inconsistent with the surrounding block. Aligning it with the if (header) { braces will improve readability.
addJsonUrl(event.url);

src/background-chrome.ts:13

  • [nitpick] Since this listener does not specify the "blocking" extraInfoSpec, returning the headers is unnecessary and could be removed to simplify the code.
return { responseHeaders: event.responseHeaders };

src/background-common.ts:7

  • Consider adding unit tests for isEventJSON, especially covering the case where a MicrosoftSharePointTeamServices header is present so it correctly returns undefined.
export function isEventJSON(

@bhollis bhollis merged commit 409d5a8 into master May 17, 2025
1 check passed
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.

Extension causes JSON parse error when loading SharePoint page

1 participant