w3c / geolocation

W3C Geolocation API
https://www.w3.org/TR/geolocation/
81 stars 56 forks source link

Gracefully handle documents that are not fully active #90

Closed marcoscaceres closed 3 years ago

marcoscaceres commented 3 years ago

Closes #78

The following tasks have been completed:

Implementation commitment:

cc @rakina


Preview | Diff

reillyeon commented 3 years ago

Maybe I'm missing the issue this change is attempting to fix but what happens after the following sequence of events,

  1. Document is fully active.
  2. Script calls navigator.geolocation.watchPosition().
  3. Document becomes not fully active.
  4. A "significant" change in position occurs.
  5. Document becomes fully active.

As written it seems like when a significant change in position occurs while the document is not fully active it will cause the watch to be canceled. Is this intentional? More likely it seems like we want to explicitly cancel all pending requests on transition to being not fully active. We definitely don't want to deliver a position update while not fully active but we may want to preserve active watches and check on transition back to fully active whether a significant change in position has occurred.

marcoscaceres commented 3 years ago

Yeah, I agree. We might need some kind of independent watcher that checks before the callbacks happen.

marcoscaceres commented 3 years ago

@rakina @reillyeon, I've reworked this a bit so now:

  1. if not fully active and the API is called, gracefully return an arbitrary number.
  2. if document suddenly becomes not fully active, drop the position request on the floor (and keep dropping them until such time as as the doc becomes fully active).
  3. Do the above also for page visibility too - so that only fully active visible documents receive position updates.

I'll put together some tests for what I can.

marcoscaceres commented 3 years ago

I think it might not be possible to test this with WPT. The limitation that we have is that I can't spin up a tab, then switch back to the original test's tab, which would cause the background tab to be "hidden".

Similarly, with an iframe: removing the iframe makes it "hidden", but it simultaneously trashes the iframe's window object, hence you can't call geolocation on it (unless you steal a reference to geolocation before it is GC'ed, but at that point you are dealing with dead objects).

rakina commented 3 years ago

Similarly, with an iframe: removing the iframe makes it "hidden", but it simultaneously trashes the iframe's window object, hence you can't call geolocation on it (unless you steal a reference to geolocation before it is GC'ed, but at that point you are dealing with dead objects).

Is this still true for the window on a nested iframe too? (so you detach the parent iframe but watch on the nested iframe). Also what about testing the "watch position -> detach, update position -> attach again, see no location update is sent"?

If that's not possible, I guess the only way to test this is through BFCache. Currently @hiroshige-g is setting up the foundations for BFCache WPTs at https://github.com/web-platform-tests/wpt/pull/28950. I think he's planning to write a Geolocation WPT eventually, but if you want to try writing one now you're more than welcome to! (also it's great to have a feedback on the WPT foundations from a non-BFCache person :) )

marcoscaceres commented 3 years ago

Is this still true for the window on a nested iframe too? (so you detach the parent iframe but watch on the nested iframe). Also what about testing the "watch position -> detach, update position -> attach again, see no location update is sent"?

I holds true there too. Once the iframe is removed, the whole document and the window object is GC'd. Reattaching it creates a both a new Window and a new Document (i.e., so position updates are not sent).

Currently @hiroshige-g is setting up the foundations for BFCache WPTs at web-platform-tests/wpt#28950. I think he's planning to write a Geolocation WPT eventually, but if you want to try writing one now you're more than welcome to! (also it's great to have a feedback on the WPT foundations from a non-BFCache person :) )

@hiroshige-g I've be happy to help review those, as it would be an opportunity for me to learn about BFCache.

I'm going to go ahead and merge this, as at least it gets all the browsers aligned on behavior and it's a great privacy improvement.