From 6ac20ffcdc972341bee723a0de610d2ca4450af0 Mon Sep 17 00:00:00 2001 From: Igor Hlina Date: Tue, 17 Jan 2017 15:12:08 +0100 Subject: [PATCH 1/3] Add module support for AMD & Webpack --- .eslintrc.js | 1 + README.md | 65 ++++++-- index.js => browser-report.js | 41 +++-- package.json | 2 +- test-amd.html | 283 ++++++++++++++++++++++++++++++++ sample.html => test-global.html | 2 +- test/index.html | 2 +- 7 files changed, 363 insertions(+), 33 deletions(-) rename index.js => browser-report.js (94%) create mode 100644 test-amd.html rename sample.html => test-global.html (99%) diff --git a/.eslintrc.js b/.eslintrc.js index c01127c..66f750e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,6 @@ module.exports = { "env": { + "amd": true, "browser": true, "node": true }, diff --git a/README.md b/README.md index e9d1d93..8ec71f9 100644 --- a/README.md +++ b/README.md @@ -8,29 +8,62 @@ Lately, in this situation, I ask my visitors to send me the report from whatsmyb Note, this is meant for reporting and not for application logic; your application should use feature detection, not browser detection. Therefore, only the most common browser names and OS names are reported, see the [Coverage](#coverage) section below for more details. The full user agent string is always provided and it can help you identify any browser. If you need to report on every browser and OS or other information in the user agent string, then take a look at [platform.js][2] and/or [UAParser.js][7]. # Usage -Package manager support is planned, but for now load this script into a browser and call `browserReport()` with a callback. Note, some values maybe `null` if the information is not available. +You can load `browser-report` via plain script tag, AMD loader or module bundler (Webpack). In every environment you're provided with two functions -## Asynchronous Usage + 1. `browserReport()` + 2. `browserReportSync()` - - +Note, some values maybe `null` if the information is not available. + +## Asynchronous Usage (via script tag) + +```html + + +``` ## Synchronous Usage Note, the remote client IP address is not available in the synchronous function call. - - +```html + + +``` + +## AMD +```html + + + + + + diff --git a/sample.html b/test-global.html similarity index 99% rename from sample.html rename to test-global.html index 306bd54..693270e 100644 --- a/sample.html +++ b/test-global.html @@ -123,7 +123,7 @@

Your full user agent string is:
{{userAgent}}

- + - + From ce3f68964bc396e568a3f2930cfb0c9cdd8785fc Mon Sep 17 00:00:00 2001 From: Igor Hlina Date: Wed, 8 Feb 2017 14:38:26 +0100 Subject: [PATCH 2/3] Don't ask cached identifier It breaks multiple calls to `browserReport(callback)` Only callback from 1st call to `browserReport()` is executed. --- browser-report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser-report.js b/browser-report.js index d4e3e33..86970a0 100644 --- a/browser-report.js +++ b/browser-report.js @@ -497,7 +497,7 @@ // use ipify.org to get the remote client ip address // define function to handle data from ipify.org - window.getip = window.getip || function (data) { + window.getip = function (data) { report.ip = data.ip; callback(null, report); }; From fa1ace5079099f55ab3716105524e71eed0b4c9d Mon Sep 17 00:00:00 2001 From: Igor Hlina Date: Thu, 9 Feb 2017 12:09:28 +0100 Subject: [PATCH 3/3] Fix package entry point --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1b60d14..7eb4b98 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "2.2.8", "description": "Report browser settings like whatsmybrowser.org.", "keywords": "browser user-agent useragent viewport screen layout plugins report detect", - "main": "./dist/browser-report.js", + "main": "./browser-report.js", "scripts": { "pretest": "eslint \"**/*.js\"", "test": "open file://`find $PWD/test -type f -name '*.html'`",