freeCodeCamp / devdocs

API Documentation Browser
https://devdocs.io
Mozilla Public License 2.0
35.06k stars 2.33k forks source link

Direct URLs redirect to the front page #658

Closed monk-time closed 5 years ago

monk-time commented 7 years ago

Visiting any documentation page by its direct url works only if I don't have any devdocs cookies. Otherwise I get redirected to the front page, with HTTP 302 in the log. Navigating through the site or via opensearch engine works fine though.

Video using a fresh Firefox profile: https://sendvid.com/314llcup

Win7x64, Firefox 54.0.1 x32

monk-time commented 7 years ago

Works fine now. Browser for a split second redirects to the front page and then returns back (through XHR) to a proper doc page.

I guess dd8c80060a4017cfb6b805b7cf28b0ab589337c8 fixed this issue?

Thibaut commented 7 years ago

Hey - dd8c80060a4017cfb6b805b7cf28b0ab589337c8 is completely unrelated.

Browser for a split second redirects to the front page and then returns back (through XHR) to a proper doc page.

This is intended, to work around a limitation of app cache (the app must be loaded from the root path). I'm not sure why in your video, the app failed to open the page after the redirection. If you can still reproduce, please try to capture the network logs and post screenshots (open the dev tools before loading the page, to get the full logs). Also, make sure you've enabled cookies, as the redirection relies on a cookie to tell the app which page it should open after it loads.

monk-time commented 7 years ago

I have tried again in the same environment (also with a fresh profile, so all default browser settings are unchanged, including cookies), and everything works fine. Don't know what the issue was, maybe my network was acting up.

monk-time commented 6 years ago

I am getting the same issue again. Entering a direct url or pressing F5 on any inner DevDocs page redirects to the main page, and if I open them in a new tab it loads the front page instead. As in the video in the OP, I can reproduce this in a fresh profile with no extensions installed. If I delete the site's cookies, I can F5 just fine but only once: trying it again redirects.

Here's the content of Firefox's Browser Console:

  1. [NO REDIRECT] On the first visit to https://devdocs.io/dom/fetch_api/using_fetch (by pasting the url into the address bar) after clearing all history, incl. Offline Website Data and Site Preferences:

    The first request:

    GET https://devdocs.io/dom/fetch_api/using_fetch [HTTP/2.0 200 OK 643ms]
    Request headers: ``` Host: devdocs.io User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate, br Connection: keep-alive Upgrade-Insecure-Requests: 1 ```
    Response headers: ``` date: Sun, 26 Nov 2017 14:37:11 GMT content-type: text/html;charset=utf-8 set-cookie: __cfduid=d84033c00b1e973381df56b67367845671511707027; expires=Mon, 26-Nov-18 14:37:07 GMT; path=/; domain=.devdocs.io; HttpOnly content-security-policy: default-src 'self' *; script-src 'self' 'nonce-devdocs' http://cdn.devdocs.io https://cdn.devdocs.io https://www.google-analytics.com https://secure.gaug.es http://*.jquery.com https://*.jquery.com; font-src 'none'; style-src 'self' 'unsafe-inline' *; img-src 'self' * data:; vary: Accept-Encoding etag: W/"4f13c8b62c2b68452f83574477f269a4" cache-control: max-age=0, private, must-revalidate via: 1.1 vegur server: cloudflare-nginx cf-ray: 3c3d9577c8188679-ARN content-encoding: br X-Firefox-Spdy: h2 ```
    Response cookies: ``` __cfduid value: d84033c00b1e973381df56b67367845671511707027 expires: 2026-11-18T14:37:07.000Z path: / domain: .devdocs.io httpOnly: true ```

    The rest of requests:

    GET https://cdn.devdocs.io/assets/application-0c9f89412357d9e7423c96841ccecc4811e1de4e1ffba05054487918312e9714.css [HTTP/2.0 200 OK 251ms]
    GET https://devdocs.io/assets/application-40a3647dabf93551918e154aab9eb5136fda62ce03308ffda0f582fa643e4518.js [HTTP/2.0 200 OK 40ms]
    GET XHR https://docs.devdocs.io/dom/index.json [HTTP/2.0 200 OK 266ms]
    GET https://www.google-analytics.com/analytics.js [HTTP/2.0 200 OK 157ms]
    GET https://devdocs.io/favicon.ico [HTTP/2.0 200 OK 40ms]
    GET https://devdocs.io/favicon.ico [HTTP/2.0 200 OK 0ms]
    GET XHR https://docs.devdocs.io/dom/fetch_api/using_fetch.html [HTTP/2.0 200 OK 50ms]
    GET https://cdn.devdocs.io/assets/docs-1-32d738d3e43c29e8afebf217a71bf9017dc99ecb04985aa2fe56f6f72e365d7d.png [HTTP/2.0 200 OK 50ms]
    GET https://www.google-analytics.com/r/collect [HTTP/2.0 200 OK 30ms]
    GET https://secure.gaug.es/track.js [HTTP/1.1 200 OK 616ms]
    GET https://secure.gaug.es/track.gif [HTTP/1.1 200 OK 130ms]
  2. [UNEXPECTED REDIRECT] After pressing F5 while on the same page:

    The first request:

    GET  https://devdocs.io/dom/fetch_api/using_fetch  [HTTP/2.0 302 Found 1226ms]
    Request headers: ``` Host: devdocs.io User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate, br Cookie: __cfduid=d84033c00b1e973381df56b67367845671511707027; _ga=GA1.2.1953125058.1511707093; _gid=GA1.2.550528259.1511707093; _gauges_unique_hour=1; _gauges_unique_day=1; _gauges_unique_month=1; _gauges_unique_year=1; _gauges_unique=1 Connection: keep-alive Upgrade-Insecure-Requests: 1 If-None-Match: W/"4f13c8b62c2b68452f83574477f269a4" Cache-Control: max-age=0 ```
    Request cookies: ``` __cfduid: d84033c00b1e973381df56b67367845671511707027 _ga: GA1.2.1953125058.1511707093 _gid: GA1.2.550528259.1511707093 _gauges_unique_hour: 1 _gauges_unique_day: 1 _gauges_unique_month: 1 _gauges_unique_year: 1 _gauges_unique: 1 ```
    Response headers: ``` date: Sun, 26 Nov 2017 15:10:37 GMT content-type: text/html;charset=utf-8 set-cookie: initial_path=%2Fdom%2Ffetch_api%2Fusing_fetch; path=/; expires=Sun, 26 Nov 2017 15:10:52 -0000 location: https://devdocs.io/ vary: Accept-Encoding via: 1.1 vegur server: cloudflare-nginx cf-ray: 3c3dc6857bf58607-ARN X-Firefox-Spdy: h2 ```
    Response cookies: ``` initial_path: value: /dom/fetch_api/using_fetch path: / ```

    The rest of requests:

    NS_ERROR_XPC_BAD_CONVERT_NATIVE: Could not convert Native argument arg 1 [nsIInterfaceRequestor.getInterface]  [2 repeats] network-monitor.js:306 
    GET  https://devdocs.io/  [HTTP/2.0 200 OK 0ms]
    GET  https://cdn.devdocs.io/assets/application-0c9f89412357d9e7423c96841ccecc4811e1de4e1ffba05054487918312e9714.css  [HTTP/2.0 200 OK 0ms]
    GET  https://devdocs.io/assets/application-40a3647dabf93551918e154aab9eb5136fda62ce03308ffda0f582fa643e4518.js  [HTTP/2.0 200 OK 0ms]
    GET  https://cdn.devdocs.io/assets/docs-20eacf216bf401f2799774fc0ccc7b11b11ca17978e720f17787e7aed85f9a8d.js  [HTTP/2.0 200 OK 0ms]
    GET  https://cdn.devdocs.io/assets/docs-1-32d738d3e43c29e8afebf217a71bf9017dc99ecb04985aa2fe56f6f72e365d7d.png  [HTTP/2.0 200 OK 0ms]
    GET  https://www.google-analytics.com/analytics.js  [HTTP/2.0 200 OK 107ms]
    GET  XHR  https://docs.devdocs.io/css/index.json  [HTTP/2.0 200 OK 150ms]
    GET  XHR  https://docs.devdocs.io/dom/index.json  [HTTP/2.0 200 OK 209ms]
    GET  XHR  https://docs.devdocs.io/dom_events/index.json  [HTTP/2.0 200 OK 249ms]
    GET  https://devdocs.io/manifest.appcache  [HTTP/2.0 200 OK 460ms]
    GET  XHR  https://docs.devdocs.io/html/index.json  [HTTP/2.0 200 OK 70ms]
    GET  XHR  https://docs.devdocs.io/http/index.json  [HTTP/2.0 200 OK 50ms]
    GET  XHR  https://docs.devdocs.io/javascript/index.json  [HTTP/2.0 200 OK 50ms]
    GET  https://ghbtns.com/github-btn.html  [HTTP/2.0 200 OK 299ms]
    GET  https://cdn.devdocs.io/assets/docs-2-a9436bc10ff017438462895ddd5ea2a7bb28176d2241310916643a79968f2e86.png  [HTTP/2.0 200 OK 0ms]
    GET  https://www.google-analytics.com/r/collect  [HTTP/2.0 200 OK 20ms]
    GET  https://secure.gaug.es/track.js  [HTTP/1.1 200 OK 364ms]
    IndexedDB UnknownErr: ActorsParent.cpp:14814  (unknown) 
    Offline cache doesn't need to update, URL=https://devdocs.io/manifest.appcache 
    GET  https://secure.gaug.es/track.gif  [HTTP/1.1 200 OK 130ms]
    GET  https://api.github.com/repos/Thibaut/devdocs  [HTTP/1.1 200 OK 725ms]
j-f1 commented 6 years ago

Does anything show up in the browser console when the website fails to redirect?

monk-time commented 6 years ago

@j-f1 What do you mean? I've posted the contents of the console in two cases: the first is Working-As-Indented, no redirect, the second is when it redirects.

And if I browse normally, just clicking on inner links to open them in the same tab, it's also WAI, I don't get any redirects, errors or HTTP/2.0 302 Found.

j-f1 commented 6 years ago

Can you open the debugger and put a breakpoint on the line after t.prototype.setInitialPath = function() { and if that gets hit when you press F5, can you tell me what the value of this.getInitialPathFromCookie() is?

monk-time commented 6 years ago

Just to make sure I got it right:

  1. I open https://devdocs.io/css/animation
  2. Clear all history
  3. Set a breakpoint in https://devdocs.io/assets/application-40a3647dabf93551918e154aab9eb5136fda62ce03308ffda0f582fa643e4518.js on line 3669 inside t.prototype.setInitialPath
  4. Press F5
  5. Debugger hits the breakpoint, loading pauses, the url in the address bar is still https://devdocs.io/css/animation.
  6. Try the following in the console:
    > this.getInitialPathFromCookie
    < function app.Router</t.prototype.getInitialPathFromCookie()
    > this.getInitialPathFromCookie()
    < undefined
  7. After resuming https://devdocs.io/css/animation properly loads without redirect.
  8. Press F5 again, the breakpoint is still set.
  9. Debugger hits the breakpoint, loading pauses, the url in the address bar is https://devdocs.io
  10. Same results in the console
  11. After resuming https://devdocs.io/ loads.
j-f1 commented 6 years ago

Thanks for getting back to me! Those are the correct steps

That’s correct. The cookie library seems to be unable to read the cookie containing the redirect target. Can you repeat the steps and tell me what Cookies.get() and document.cookie return after the second reload (when you’re redirected to https://devdocs.io)?

monk-time commented 6 years ago

On step 6 (no redirect):

> Cookies.get()
< undefined
> document.cookie
< ""

On step 10 (redirect):

> Cookies.get()
< undefined
> document.cookie
< "_ga=GA1.2.481412407.1511715565; _gid=GA1.2.814896997.1511715565; _gat=1; _gauges_unique_hour=1; _gauges_unique_day=1; _gauges_unique_month=1; _gauges_unique_year=1; _gauges_unique=1"
monk-time commented 6 years ago

I have updated Firefox to 57.0.1 and restarted my router (receiving a new IP from my ISP) in the meanwhile, and now once again I can't reproduce this issue. Step 10 now returns "/css/animation" in the console and leaves me on the front page, but that's likely because of me executing that command in the console. Same steps without breakpoints load everything properly, and in my main profile everything is OK now too.

I am puzzled, to say the least.

jmerle commented 5 years ago

Closing this because we haven't had anyone report they have this issue for over a year.