1

When using the chrome.webNavigation API, the following code (used in background page of an extension):

  chrome.webNavigation.onCommitted.addListener(function(data) {
    console.log('onCommitted', data.tabId, data.url);
  });
  chrome.webNavigation.onBeforeNavigate.addListener(function(data) {
    console.log('onBeforeNavigate', data.tabId, data.url);
  });

produces this output when navigating to, say, 'http://drive.google.com'

newTest.js:18 onBeforeNavigate 606 http://drive.google.com/
newTest.js:18 onCommitted 606 https://drive.google.com/

Somewhere, even before the request was sent to the server, Chrome changed the url from http to https.

This behaviour is also exhibited in other cases. For instance for 'http://getpocket.com', where it also adds a new path:

newTest.js:18 onBeforeNavigate 626 http://getpocket.com/
newTest.js:18 onCommitted 626 https://getpocket.com/beta/

The server side redirects all come after onCommitted, but this is one case where Chrome modifies urls even before it sends a request to the server.

Is this behaviour documented somewhere, so I can predictably handle it?

Adi B
  • 1,189
  • 13
  • 32
  • 2
    Perhaps it's [HSTS](https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security)? – Xan Oct 12 '15 at 22:22

1 Answers1

1

For Google Drive, it's HTTP Strict Transport Security kicking in.

After it's set up, the browser will automatically redirect everything to HTTPS.

You can look under the hood at net-internals, e.g. chrome://net-internals/#hsts

static_sts_domain: drive.google.com
static_upgrade_mode: STRICT


In case of Pocket, this seems to be a 301 Moved Permanently redirect.

By design, browsers cache this response permanently (at least Chrome does) and rewrite links automatically without hitting the server until said cache is cleared.

Community
  • 1
  • 1
Xan
  • 74,770
  • 16
  • 179
  • 206
  • Possibly, in this case. But it also exhibits this behaviour in another case: > newTest.js:18 onBeforeNavigate 626 http://getpocket.com/ > newTest.js:18 onCommitted 626 https://getpocket.com/beta/ Does HSTS also allow specifying a path? – Adi B Oct 12 '15 at 22:28
  • Wait, do you have an extension for Pocket installed? It may be redirecting requests. – Xan Oct 12 '15 at 22:30
  • 1
    Inspect `chrome://net-internals/#events` to see what happens. It's the most detailed trace you'll get. – Xan Oct 12 '15 at 22:33
  • Nope, don't have a Pocket extension installed. Also checked HSTS: drive is configured in HSTS, Pocket isn't. – Adi B Oct 12 '15 at 22:33