Skip to content

Check also URL file extension to activate the extension#59

Merged
paolosimone merged 2 commits into
mainfrom
fix-jsonl-file
Feb 2, 2025
Merged

Check also URL file extension to activate the extension#59
paolosimone merged 2 commits into
mainfrom
fix-jsonl-file

Conversation

@paolosimone
Copy link
Copy Markdown
Owner

@paolosimone paolosimone commented Feb 2, 2025

Context

The extensions checks the content type to decide whether to activate, but there are cases in which the content type is wrongly set, e.g. when opening .json in raw.githubusercontent.com or .jsonl local files in Chrome it's set to to Content-Type: text/plain.

Change

Leveraging "force activation" functionality introduced in #54 now the default fallback behavior is to check the URL file extension to be either .json or .jsonl.

Note that the check is performed as fallback and it can gracefully fail, since there is no guarantee that a URL ending with .json actually contains only the JSON, e.g. https://github.com/paolosimone/virtual-json-viewer/blob/master/samples/test.json shows Github's web page.

Being an opinionated fallback, the user can opt-out by simply disabling the "Force extension activation" setting.

The setting will be upgraded the first time the extension UI is loaded. If the user already set a custom URL regex it won't be overwritten.


⚠️ POSSIBLY BREAKING CHANGE

The custom URL regex is now checked against location.origin + location.pathname instead of location.href, i.e. excluding query parameters. See MDN.

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.

1 participant