Skip to content

Commit 8be80d4

Browse files
author
Paul Boocock
committed
Remove module level references to window and document (close #928)
1 parent 14879a3 commit 8be80d4

File tree

22 files changed

+237
-157
lines changed

22 files changed

+237
-157
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Remove module level references to window and document (close #928)",
5+
"type": "none",
6+
"packageName": "@snowplow/browser-plugin-browser-features"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-plugin-browser-features",
10+
"email": "[email protected]"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Remove module level references to window and document (close #928)",
5+
"type": "none",
6+
"packageName": "@snowplow/browser-plugin-error-tracking"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-plugin-error-tracking",
10+
"email": "[email protected]"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Remove module level references to window and document (close #928)",
5+
"type": "none",
6+
"packageName": "@snowplow/browser-plugin-optimizely-x"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-plugin-optimizely-x",
10+
"email": "[email protected]"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Remove module level references to window and document (close #928)",
5+
"type": "none",
6+
"packageName": "@snowplow/browser-plugin-optimizely"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-plugin-optimizely",
10+
"email": "[email protected]"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Remove module level references to window and document (close #928)",
5+
"type": "none",
6+
"packageName": "@snowplow/browser-plugin-parrable"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-plugin-parrable",
10+
"email": "[email protected]"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Remove module level references to window and document (close #928)",
5+
"type": "none",
6+
"packageName": "@snowplow/browser-plugin-performance-timing"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-plugin-performance-timing",
10+
"email": "[email protected]"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Remove module level references to window and document (close #928)",
5+
"type": "none",
6+
"packageName": "@snowplow/browser-tracker-core"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-tracker-core",
10+
"email": "[email protected]"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Remove module level references to window and document (close #928)",
5+
"type": "none",
6+
"packageName": "@snowplow/browser-tracker"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-tracker",
10+
"email": "[email protected]"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Remove module level references to window and document (close #928)",
5+
"type": "none",
6+
"packageName": "@snowplow/javascript-tracker"
7+
}
8+
],
9+
"packageName": "@snowplow/javascript-tracker",
10+
"email": "[email protected]"
11+
}

libraries/browser-tracker-core/src/detectors.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,14 @@
2828
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
*/
3030

31-
const windowAlias = window,
32-
documentAlias = document;
33-
3431
/*
3532
* Checks whether sessionStorage is available, in a way that
3633
* does not throw a SecurityError in Firefox if "always ask"
3734
* is enabled for cookies (https://github.com/snowplow/snowplow/issues/163).
3835
*/
3936
export function hasSessionStorage() {
4037
try {
41-
return !!windowAlias.sessionStorage;
38+
return !!window.sessionStorage;
4239
} catch (e) {
4340
return true; // SecurityError when referencing it means it exists
4441
}
@@ -51,7 +48,7 @@ export function hasSessionStorage() {
5148
*/
5249
export function hasLocalStorage() {
5350
try {
54-
return !!windowAlias.localStorage;
51+
return !!window.localStorage;
5552
} catch (e) {
5653
return true; // SecurityError when referencing it means it exists
5754
}
@@ -68,8 +65,9 @@ export function localStorageAccessible() {
6865
return false;
6966
}
7067
try {
71-
windowAlias.localStorage.setItem(mod, mod);
72-
windowAlias.localStorage.removeItem(mod);
68+
const ls = window.localStorage;
69+
ls.setItem(mod, mod);
70+
ls.removeItem(mod);
7371
return true;
7472
} catch (e) {
7573
return false;
@@ -86,11 +84,11 @@ export function localStorageAccessible() {
8684
export function detectViewport() {
8785
var width, height;
8886

89-
if ('innerWidth' in windowAlias) {
90-
width = windowAlias['innerWidth'];
91-
height = windowAlias['innerHeight'];
87+
if ('innerWidth' in window) {
88+
width = window['innerWidth'];
89+
height = window['innerHeight'];
9290
} else {
93-
const e = documentAlias.documentElement || documentAlias.body;
91+
const e = document.documentElement || document.body;
9492
width = e['clientWidth'];
9593
height = e['clientHeight'];
9694
}
@@ -110,8 +108,8 @@ export function detectViewport() {
110108
* - http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
111109
*/
112110
export function detectDocumentSize() {
113-
var de = documentAlias.documentElement, // Alias
114-
be = documentAlias.body,
111+
var de = document.documentElement, // Alias
112+
be = document.body,
115113
// document.body may not have rendered, so check whether be.offsetHeight is null
116114
bodyHeight = be ? Math.max(be.offsetHeight, be.scrollHeight) : 0;
117115
var w = Math.max(de.clientWidth, de.offsetWidth, de.scrollWidth);

0 commit comments

Comments
 (0)