Skip to content

Commit

Permalink
Add a demo (#578)
Browse files Browse the repository at this point in the history
commit a27efd8
Author: Surgie Finesse <finesserus@gmail.com>
Date:   Tue Nov 3 20:27:05 2020 +1000

    Publish the playground only from the master branch

commit 2c38116
Author: Surgie Finesse <finesserus@gmail.com>
Date:   Tue Nov 3 19:50:56 2020 +1000

    Amend the look, fix an HTTPS detection code mistake

commit 5eae849
Author: Surgie Finesse <finesserus@gmail.com>
Date:   Tue Nov 3 15:37:17 2020 +1000

    Increase the demo page contrast

commit a58e25e
Merge: 94bc121 ae52f61
Author: Surgie Finesse <finesserus@gmail.com>
Date:   Tue Nov 3 00:00:13 2020 +1000

    Merge branch 'master' into feature/556-playground
    
    # Conflicts:
    #	playground/index.ts

commit 94bc121
Author: Surgie Finesse <finesserus@gmail.com>
Date:   Mon Nov 2 22:55:52 2020 +1000

    Fix the shadow

commit d790c1d
Author: Surgie Finesse <finesserus@gmail.com>
Date:   Mon Nov 2 22:53:11 2020 +1000

    Add an alert that tells why the Share button is disabled

commit 6b1b66c
Author: Surgie Finesse <finesserus@gmail.com>
Date:   Mon Nov 2 18:54:43 2020 +1000

    Add a favicon

commit b782efe
Author: Surgie Finesse <finesserus@gmail.com>
Date:   Mon Nov 2 18:45:41 2020 +1000

    Add demo links to the pages

commit 02384cf
Author: Surgie Finesse <finesserus@gmail.com>
Date:   Mon Nov 2 18:39:14 2020 +1000

    Redesign the playground, show the debug information on the playground

commit 5f4a8d9
Author: Surgie Finesse <finesserus@gmail.com>
Date:   Mon Nov 2 11:06:21 2020 +1000

    Beautify the playground distributive file structure

commit 98d55db
Author: Surgie Finesse <finesserus@gmail.com>
Date:   Mon Nov 2 10:31:37 2020 +1000

    Deploy the playground to GitHub Pages automatically

commit 732c2a3
Author: Surgie Finesse <finesserus@gmail.com>
Date:   Sun Nov 1 22:53:48 2020 +1000

    Update Webpack, use the logo image on the playground
    
    Webpack 5 is broken, it's too early to update to it
  • Loading branch information
Finesse committed Nov 3, 2020
1 parent 787f09c commit f6314aa
Show file tree
Hide file tree
Showing 11 changed files with 395 additions and 118 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/fingerprint_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ BUG REPORTS NOT USING THE TEMPLATE ARE SUBJECT TO BEING CLOSED WITHOUT COMMENT.

### Fingerprint data

Run `fp.get({ debug: true ))` and copy all debug messages from the browser console for both/all fingerprints involved.
Alternatively, provide a jsfiddle that reproduces the bug.
Provide the FULL DATA of both/all fingerprints using this page: https://fingerprintjs.github.io/fingerprintjs/.
Alternatively, provide a JSFiddle that reproduces the bug.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/other_bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ BUG REPORTS NOT USING THE TEMPLATE ARE SUBJECT TO BEING CLOSED WITHOUT COMMMENT.

### Fingerprint data

If applicable, run `fp.get({ debug: true ))` and copy all debug messages from the browser console for both/all fingerprints involved.
Alternatively, provide a jsfiddle that reproduces the bug.
If applicable, provide the FULL DATA of both/all fingerprints using this page: https://fingerprintjs.github.io/fingerprintjs/.
Alternatively, provide a JSFiddle that reproduces the bug.
29 changes: 29 additions & 0 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Reference on this file: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
# To make it work, go to the repository settings, then Options, GitHub Pages and select `gh-pages` under Source.
name: Publish the demo
on:
push:
branches:
- master
jobs:
publish:
name: Publish the demo
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@master
- name: Install Node packages
run: yarn install
- name: Build the demo
run: yarn playground:build
- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@3.7.1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: playground/dist
CLEAN: true
SINGLE_COMMIT: true
- name: Print the demo URL
run: echo "✅ The demo has been deployed to https://$(cut -d'/' -f1 <<< $GITHUB_REPOSITORY).github.io/$(cut -d'/' -f2 <<< $GITHUB_REPOSITORY)/"
4 changes: 2 additions & 2 deletions docs/browser_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The library supports all popular browsers.
We use the following terminal command to decide which browsers to support:

```
```bash
npx browserslist "cover 95% in us, not IE < 10"
```

Expand All @@ -23,7 +23,7 @@ Other browsers may work, but we don't guarantee the correct operation.
## Old browsers requirements

Very old browsers like Internet Explorer 11 and Android Browser 4.1
require a [Promise]([Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)) polyfill to work.
require a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) polyfill to work.
Add any Promise polyfill you like before loading the FingerprintJS agent.
Examples for various installation methods:

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"eslint": "^7.11.0",
"eslint-config-prettier": "^6.13.0",
"eslint-plugin-prettier": "^3.1.4",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^4.5.0",
"karma": "^5.2.3",
"karma-browserstack-launcher": "^1.6.0",
Expand All @@ -73,8 +74,8 @@
"rollup-plugin-dts": "^1.4.13",
"rollup-plugin-license": "^2.2.0",
"rollup-plugin-terser": "^7.0.2",
"terser-webpack-plugin": "^4.2.2",
"ts-loader": "^8.0.4",
"terser-webpack-plugin": "^4.2.3",
"ts-loader": "^8.0.7",
"typescript": "^4.0.3",
"ua-parser-js": "^0.7.22",
"webpack": "^4.44.2",
Expand Down
154 changes: 121 additions & 33 deletions playground/index.html
Original file line number Diff line number Diff line change
@@ -1,58 +1,146 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title><%= htmlWebpackPlugin.options.title %></title>
<link rel="icon" type="image/x-icon" href="<%= require('../resources/favicon.ico').default %>" />
<style>
html, body {
/* The full-height solution for IE 11 is taken from https://gist.github.com/palicko/26b327cd2198e52c25b13485b4dd02bc */
html {
display: flex;
min-height: 100%;
flex: 1;
}
body {
color: #333;
font-family: sans-serif;
display: flex;
flex-direction: column;
width: 100%;
min-height: 100vh;
padding: 0;
margin: 0;
font-family: sans-serif;
}
.content {
flex: 1;
width: 100%;
max-width: 60em;
box-sizing: border-box;
margin: 0 auto;
padding: 1.25em;
display: flex;
flex-direction: column;
}
header {
flex: none;
margin-bottom: 1.2vh;
}
main {
margin: auto;
max-width: 800px;
padding: 20px;
header img {
height: 5vh;
max-width: 100%;
}
button {
border: none;
background: #f04405;
color: #fff;
font: inherit;
font-size: 88%;
font-weight: 600;
line-height: 1.2;
border-radius: 0.57em;
cursor: pointer;
margin: 0;
padding: 0.85em 1.7em;
text-align: center;
outline: none;
transition: all 0.25s ease-out;
}
button:hover {
background: #8c2703;
}
h1 {
margin: 0 0 1.3em;
color: #393e9e;
button:active {
background: #cd3f10;
}
.visitorIdHeader {
font-size: 16px;
color: #999;
button:disabled {
cursor: not-allowed;
background: #e9987c;
}
.visitorId {
font-size: 24px;
font-weight: 500;
.buttons {
flex: none;
}
.buttons button {
margin: 0 0.8em 0.8em 0;
}
.outputHolder {
flex: 1;
min-height: 4em;
position: relative;
}
.output {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
box-sizing: border-box;
background: #282c34;
box-shadow: 0 0 1.25em rgba(0, 0, 0, 0.2);
border-radius: 0.7em;
padding: 1em 1.25em;
color: #e1e5ea;
overflow: auto;
}
.output pre {
padding: 0;
margin: 0;
font-size: 123%;
font-family: monospace;
white-space: pre-wrap;
word-break: break-all;
}
.visitorId.loading {
opacity: 0.3;
font-family: inherit;
.output pre.big {
font-size: 200%;
}
.output pre.small {
font-size: 100%;
}
.hint {
font-size: 14px;
.output .heading {
font-size: 81%;
margin-bottom: 0.5em;
color: #eac4a6;
}
.output .heading:not(:first-child) {
margin-top: 2em;
color: #555;
}

@media (max-width: 768px), (max-height: 568px) {
.content {
padding: 1em;
}
button {
padding: 0.7em 1em;
}
.output {
padding: 0.75em 1em;
}
}
</style>
</head>
<body>
<main>
<h1>FingerprintJS</h1>
<div class="visitorIdHeader">Visitor ID:</div>
<div class="visitorId loading">Getting the visitor ID...</div>
<div class="hint">See the browser console for debug data.</div>
</main>
<div class="content">
<header>
<a href="<%= require('../package.json').homepage %>">
<img src="<%= require('../resources/logo.svg').default %>" alt="FingerprintJS">
</a>
</header>
<div class="buttons">
<button disabled id="debugCopy">Copy Debug Data</button>
<button disabled id="debugShare">Share Debug Data</button>
</div>
<div class="outputHolder">
<section class="output">
<div class="heading">Getting the visitor identifier...</div>
</section>
</div>
</div>
</body>
</html>
105 changes: 94 additions & 11 deletions playground/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,108 @@
import 'promise-polyfill/src/polyfill'
import FingerprintJS from '../src'
import * as FingerprintJS from '../src'

async function getVisitorId() {
async function getVisitorData() {
const fp = await FingerprintJS.load()
const result = await fp.get({ debug: true })
return result.visitorId
return await fp.get({ debug: true })
}

async function startPlayground() {
const display = document.querySelector('.visitorId')
if (!display) {
throw new Error("The display element isn't found in the HTML code")
const output = document.querySelector('.output')
if (!output) {
throw new Error("The output element isn't found in the HTML code")
}

try {
const visitorId = await getVisitorId()
display.textContent = visitorId
display.classList.remove('loading')
const startTime = Date.now()
const { visitorId, components } = await getVisitorData()
output.innerHTML = ''
addOutputSection(output, 'Visitor identifier:', visitorId, 'big')
addOutputSection(output, 'Time took to get the identifier:', `${Date.now() - startTime}ms`)
addOutputSection(output, 'Entropy components:', FingerprintJS.componentsToDebugString(components), 'small')
initializeDebugButtons(`${visitorId}:
\`\`\`
${FingerprintJS.componentsToDebugString(components)}
\`\`\``)
} catch (error) {
display.textContent = 'Unexpected error'
const errorData = {
message: error.message,
stack: error.stack.split('\n'),
...error,
}
output.innerHTML = ''
addOutputSection(output, 'Unexpected error:', JSON.stringify(errorData, null, 2))
initializeDebugButtons(`Unexpected error:\n
\`\`\`
${JSON.stringify(errorData, null, 2)}
\`\`\``)
throw error
}
}

function addOutputSection(output: Node, header: string, content: string, size?: 'small' | 'big') {
const headerElement = document.createElement('div')
headerElement.classList.add('heading')
headerElement.textContent = header
output.appendChild(headerElement)

const contentElement = document.createElement('pre')
if (size) {
contentElement.classList.add(size)
}
contentElement.textContent = content
output.appendChild(contentElement)
}

function initializeDebugButtons(debugText: string) {
const copyButton = document.querySelector('#debugCopy')
if (copyButton instanceof HTMLButtonElement) {
copyButton.disabled = false
copyButton.addEventListener('click', (event) => {
event.preventDefault()
copy(debugText)
})
}

const shareButton = document.querySelector('#debugShare')
if (shareButton instanceof HTMLButtonElement) {
shareButton.disabled = false
shareButton.addEventListener('click', (event) => {
event.preventDefault()
share(debugText)
})
}
}

function copy(text: string) {
const textarea = document.createElement('textarea')
textarea.value = text
document.body.appendChild(textarea)
textarea.focus()
textarea.select()
try {
document.execCommand('copy')
} catch {
// Do nothing in case of a copying error
}
document.body.removeChild(textarea)
}

async function share(text: string) {
if (!navigator.share) {
alert(`Sharing is unavailable.
Sharing is available in mobile browsers and only on HTTPS websites. ${
location.protocol === 'https:'
? 'Use a mobile device or the Copy button instead.'
: `Open https://${location.host}${location.pathname}${location.search} instead.`
}`)
return
}
try {
await navigator.share({ text })
} catch {
// Do nothing in case of a share abort
}
}

startPlayground()
Loading

0 comments on commit f6314aa

Please sign in to comment.