Fist a couple of observations:
- The reason you're seeing multiple onPageFinished calls are most likely redirects.
- Unfortunately there isn't a reliable way for you to determine when a redirect chain has ended (especially in the presence of JavaScript-initiated redirects that occur after a timeout).
- I don't know of a reliable way to do what you want based on the URL alone. Consider how would you decide what the host bit is of "my-app.appspot.com" or "2.my-app.appspot.com"?
- browsers also have this problem - if you go to a page that does a couple of redirects you'll see the address bar change.
That being said there are a couple of things you could do:
- If the host changing too frequently is only a UI problem (that is - it just looks bad) maybe throttle the changes (don't allow it to change more often than once per second, for example (don't forget about the last update with the final/current URL))?
- Have a set of best-effort transformation rules (like
"m.*" -> "www.*"
), if you do this I'd recommend having some option for the user to see the 'real' URL too.