Check also URL file extension to activate the extension#59
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
.jsoninraw.githubusercontent.comor.jsonllocal files in Chrome it's set to toContent-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
.jsonor.jsonl.Note that the check is performed as fallback and it can gracefully fail, since there is no guarantee that a URL ending with
.jsonactually contains only the JSON, e.g.https://github.com/paolosimone/virtual-json-viewer/blob/master/samples/test.jsonshows 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.
The custom URL regex is now checked against
location.origin + location.pathnameinstead oflocation.href, i.e. excluding query parameters. See MDN.