edgi-govdata-archiving / version-tracking-ui

ARCHIVED--Bookmarklet to modify UI for Versionista website monitoring
MIT License
3 stars 1 forks source link

add link to HTML diff #2

Open titaniumbones opened 7 years ago

titaniumbones commented 7 years ago

either the generated gist or the "raw html" view in the main UI

jpmckinney commented 7 years ago

It doesn't seem to be possible with the bookmarklet.

A comparison URL looks like https://versionista.com/12345/1234567/1234567:0/. If you're logged in, that URL redirects to something like http://54.84.208.219/pa/.../ The gist URL is just that last URL plus gist (http://54.84.208.219/pa/.../gist).

A solution would need to request https://versionista.com/12345/1234567/1234567:0/, get the URL that it redirects to, add gist, and load that URL for the user.

However, It's not possible to load insecure (http) content from a secure (https) page, as that triggers a mixed content error (Blocked loading mixed active content).

jQuery uses XMLHTTPRequest, which will trigger a mixed content error. I tried using the new Fetch API in modern browsers, e.g. running the following after login:

fetch('https://versionista.com/12345/1234567/1234567:0/', {
  redirect: 'manual',
  credentials: 'same-origin'
}).then(function (response) {
  console.log(response)
});

However, that returns a Response with a type of opaqueredirect, and no information about the URL that the browser would have redirected to.

So, I don't think a bookmarklet can do it, because a bookmarklet is constrained by the security policies of the browser.