Skip to content

Commit

Permalink
✨[init] add extra checks
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Dec 4, 2019
1 parent ba86cf8 commit 3f122bf
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/core/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,18 @@ export function isValidBrowsingContext() {
console.error('Cookies are not authorized, we will not send any data.')
return false
}
if (isDocPrerendered() || isLocalFile()) {
console.error('Execution is not allowed in the current context.')
return false
}
return true
}

function isLocalFile() {
return window.location.protocol === 'file:'
}

function isDocPrerendered() {
// https://www.w3.org/TR/resource-hints/#dfn-prerender
return document.visibilityState === 'prerender'
}

0 comments on commit 3f122bf

Please sign in to comment.