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

Geolocation API test (+ a bit of a clean up) #1

Merged
merged 3 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions features/geolocation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Geolocation</title>
</head>
<body>
<p><a href="../index.html">[Home]</a></p>

<p>Allowing geolocation permission will cause this page to pull latest location information and show it on this page every 1s. Switching to a different tab or an app should prevent page from getting the location. You can verify that it's true by switching tabs, or apps, and comming back to this page after couple of seconds. Last update time should be > 1s and be marked in red.</P>

<p id="demo"></p>

<script>
const demo = document.getElementById("demo");

function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, currentPositionError);
} else {
demo.innerHTML = "Geolocation is not supported by this browser.";
}
}

function currentPositionError(err) {
demo.innerHTML = `🛑 Location not available ("${err.message}").<br/>${demo.innerHTML}`;
}

let lastUpdate = null;

function showPosition(position) {
let diff = 0;
if (lastUpdate !== null) {
diff = Date.now() - lastUpdate;
}

lastUpdate = Date.now();
const diffSec = Math.round(diff/1000);
const color = diffSec > 1 ? 'red' : 'green';

if (diffSec === 0) {
return;
}

demo.innerHTML = `Last update <span style='color: ${color}'>${diffSec}s</span> ago (lat ${position.coords.latitude} lon ${position.coords.longitude})<br/>${demo.innerHTML}`;
}

setInterval(getLocation, 1000);
</script>


</body>
</html>
10 changes: 8 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Client Test Pages - Home</title>
</head>
<body>

Expand All @@ -11,11 +14,14 @@ <h1>Client Test Pages</h1>
<h2>Trackers</h2>

<ul>
<li><a href="trackers/1major-via-script.html">1 major tracker loaded via script</a>
<li><a href="./trackers/1major-via-script.html">1 major tracker loaded via script</a>
</ul>

<h2>Browser Features</h2>

<ul>
<li><a href="./features/geolocation.html">Geolocation</a>
</ul>


</body>
Expand Down
13 changes: 6 additions & 7 deletions trackers/1major-via-script.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>1 major tracker loaded via script</title>

<script src="//doubleclick.net/tracker.js">
</script>

<script src="//doubleclick.net/tracker.js"></script>
</head>
<body>
<p><a href="../index.html">[Home]</a></p>

<p>1 major tracker loaded via script src</p>

<p>
<a href="../index.html">[Home]</a>
</p>

</body>
</html>