Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with not fully active documents #78

Closed
marcoscaceres opened this issue May 24, 2021 · 10 comments · Fixed by #90
Closed

Deal with not fully active documents #78

marcoscaceres opened this issue May 24, 2021 · 10 comments · Fixed by #90
Labels

Comments

@marcoscaceres
Copy link
Member

marcoscaceres commented May 24, 2021

See guide - example using Geolocation, which is not covered in our spec I think.

Cc @rakina for review.

@marcoscaceres marcoscaceres changed the title Active/inactive documents Deal with active/inactive documents May 24, 2021
@rakina
Copy link
Member

rakina commented May 24, 2021

Thanks! I think this is already somewhat implicitly specified by step 4 of "request position", which waits for the document to become visible, and bfcached/non-fully active documents should not be visible. But I think it is better to make it more explicit (wait for the document to become fully active also).

also cc @fergal @domenic

@marcoscaceres
Copy link
Member Author

Ok, so, it might be worth checking if the document is still active as part of acquire position.

I'll verify what browsers do there... if they silently ignore the request or error.

@Tom333Trinity

This comment has been minimized.

@marcoscaceres

This comment has been minimized.

@marcoscaceres
Copy link
Member Author

Did a little digging... both Chromium and WebKit simply do the following check:

if (!frame())
   return 0;

But I couldn't find any other checks for when .watchPosition() is actually running.

It's hard to test if the callbacks are invoked, as even .watchPosition() only fires once.... I'll see if I can try on my phone and move around a bit.

Gecko unfortunately throws. I can probably fix that in Gecko easily enough though.

@marcoscaceres
Copy link
Member Author

@rakina ok, below is a simple test case... I'll covert it to a WPT, but would like your feedback before I do.

The neat thing in all browsers is that removal and reattachment does indeed kill the geolocation service for the frame.

  async function runTest() {
    const iframe = document.createElement("iframe");
    iframe.src = "empty.html";
    document.body.appendChild(iframe);
    console.log("loading iframe");
    await new Promise((r) => {
      iframe.onload = r;
    });

    // steal geolocation
    const geo = win.navigator.geolocation;

    // queue up some position watchers...
    console.log(geo.watchPosition(console.log, console.error));
    console.log(geo.watchPosition(console.log, console.error));
    console.log(geo.watchPosition(console.log, console.error));
    geo.getCurrentPosition(console.log, console.error)
    geo.getCurrentPosition(console.log, console.error)
    geo.getCurrentPosition(console.log, console.error)

    // make doc no longer fully active
    iframe.remove();

    // try to use geolocation
    try {
      console.log("watchPosition", geo.watchPosition(console.log, console.error));
    } catch (err) {
      console.log(err);
    }

    try {
      console.log(
        "getCurrentPosition",
        geo.getCurrentPosition(console.log, console.error)
      );
    } catch (err) {
      console.log(err);
    }
    // re-attach
    console.log("reattach");
    document.body.appendChild(iframe);

    // And we are back! But dead... 
    iframe.contentWindow.navigator.geolocation.getCurrentPosition(
      console.log,
      console.error
    );
    iframe.contentWindow.navigator.geolocation.watchPosition(
      console.log,
      console.error
    );

    console.log("done");
  }

  runTest();

@marcoscaceres
Copy link
Member Author

@marcoscaceres
Copy link
Member Author

marcoscaceres commented Jun 9, 2021

Sent Gecko patch: https://phabricator.services.mozilla.com/D117273

@marcoscaceres
Copy link
Member Author

@rakina
Copy link
Member

rakina commented Jun 11, 2021

Thanks a lot @marcoscaceres! I think the test looks good, neat that you can test it with just iframes. CC-ing @hiroshige-g who is working on BFCache WPTs so that he can make a similar test but with BFCache involved (he's also currently working on a guide to write BFCache tests) and @fergald who is involved in BFCache WPT stuff as well.

@marcoscaceres marcoscaceres changed the title Deal with active/inactive documents Deal with not fully active documents Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants