├── .nvmrc ├── .gitignore ├── .travis.yml ├── index.d.ts ├── index.js ├── data └── rules.js ├── LICENSE ├── test ├── index.js └── data │ ├── not-webview.js │ └── webview.js ├── package.json ├── README.md └── CONTRIBUTING.md /.nvmrc: -------------------------------------------------------------------------------- 1 | 6.10.3 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "6" 4 | - "4" 5 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | declare module "is-ua-webview" { 2 | function isWebview(ua: string): boolean; 3 | export default isWebview; 4 | } 5 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var rules = require('./data/rules') 2 | var webviewRegExp = new RegExp('(' + rules.join('|') + ')', 'ig') 3 | 4 | module.exports = function isWebview(ua) { 5 | return !!ua.match(webviewRegExp) 6 | } 7 | -------------------------------------------------------------------------------- /data/rules.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | // if it says it's a webview, let's go with that 3 | 'WebView', 4 | // iOS webview will be the same as safari but missing "Safari" 5 | '(iPhone|iPod|iPad)(?!.*Safari)', 6 | // Android Lollipop and Above: webview will be the same as native but it will contain "wv" 7 | // Android KitKat to Lollipop webview will put Version/X.X Chrome/{version}.0.0.0 8 | 'Android.*(;\\s+wv|Version/\\d.\\d\\s+Chrome/\\d+(\\.0){3})', 9 | // old chrome android webview agent 10 | 'Linux; U; Android' 11 | ] 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, Adam Eivy 2 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 3 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 4 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai") 2 | chai.should() 3 | const isWebview = require('../index') 4 | const listWebview = require('./data/webview') 5 | const listNot = require('./data/not-webview') 6 | 7 | describe('is-ua-webview', function () { 8 | describe('webviews', function () { 9 | listWebview.forEach(function(ua) { 10 | it('should detect (' + ua + ') as webview', function() { 11 | isWebview(ua).should.be.true; 12 | }); 13 | }); 14 | }); 15 | describe('not webviews', function () { 16 | listNot.forEach(function(ua) { 17 | it('should not be detected (' + ua + ') as webview', function() { 18 | isWebview(ua).should.be.false; 19 | }); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "is-ua-webview", 3 | "version": "1.1.2", 4 | "description": "useragent parsing for webview detection", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "./node_modules/mocha/bin/mocha.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/atomantic/is-ua-webview.git" 12 | }, 13 | "keywords": [ 14 | "webview", 15 | "mobile", 16 | "detection", 17 | "parsing", 18 | "is-ua-webview", 19 | "is-webview", 20 | "user-agent" 21 | ], 22 | "author": "Adam Eivy", 23 | "license": "ISC", 24 | "bugs": { 25 | "url": "https://github.com/dtudury/is-ua-webview/issues" 26 | }, 27 | "devDependencies": { 28 | "chai": "^4.3.6", 29 | "mocha": "^10.1.0", 30 | "should": "^13.2.3" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/data/not-webview.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | // chrome android browser 3 | "Mozilla/5.0 (Linux; Android 4.4.4; One Build/KTU84L.H4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.135 Mobile Safari/537.36", 4 | // chrome android browser with round version number 5 | "Mozilla/5.0 (Linux; Android 12; ingot) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Mobile Safari/537.36", 6 | // iPad Safari 7 | "Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) CriOS/30.0.1599.12 Mobile/11A465 Safari/8536.25", 8 | // iPhone Safari 9 | "Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13C75 Safari/601.1", 10 | // chrome galaxy nexus 11 | "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19", 12 | // macOS 12.1 13 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15", 14 | // mac desktop 15 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:76.0) Gecko/20100101 Firefox/76.0" 16 | ] 17 | -------------------------------------------------------------------------------- /test/data/webview.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | // facebook for android 3 | "Mozilla/5.0 (Linux; Android 4.4.4; One Build/KTU84L.H4) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/28.0.0.20.16;]", 4 | // twitter for android 5 | "Mozilla/5.0 (Linux; Android 4.4.4; One Build/KTU84L.H4) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36", 6 | // facebook for iOS 7 | "Mozilla/5.0 (iPhone; CPU iPhone OS 8_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12D508 [FBAN/FBIOS;FBAV/27.0.0.10.12;FBBV/8291884;FBDV/iPhone7,1;FBMD/iPhone;FBSN/iPhone OS;FBSV/8.2;FBSS/3; FBCR/vodafoneIE;FBID/phone;FBLC/en_US;FBOP/5]", 8 | // twitter / tweetbot for IOS 9 | "Mozilla/5.0 (iPhone; CPU iPhone OS 8_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12D508", 10 | // old chrome webview UA 11 | "Mozilla/5.0 (Linux; U; Android 4.1.1; en-gb; Build/KLP) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30", 12 | // chrome kitkat to lollipop 13 | "Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/_BuildID_) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36", 14 | // lollipop and above 15 | "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36" 16 | ] 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # is-ua-webview 2 | 3 | A super simple webview user-agent detector 4 | 5 | [![Build Status](https://travis-ci.org/atomantic/is-ua-webview.png)](https://travis-ci.org/atomantic/is-ua-webview) [![](https://img.shields.io/npm/dm/is-ua-webview.svg?style=flat)](https://www.npmjs.org/package/is-ua-webview) 6 | [![](https://img.shields.io/npm/v/is-ua-webview.svg?style=flat)](https://www.npmjs.org/package/is-ua-webview) 7 | 8 | ## Installation 9 | 10 | $ npm install is-ua-webview 11 | 12 | ## Usage 13 | 14 | ```js 15 | const isWebview = require("is-ua-webview"); 16 | 17 | // just for testing: 18 | const assert = require("assert"); 19 | 20 | // Facebook App embedded page load 21 | assert( 22 | isWebview( 23 | "Mozilla/5.0 (Linux; Android 4.4.4; One Build/KTU84L.H4) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/28.0.0.20.16;]" 24 | ) 25 | ); 26 | 27 | // Chrome/Android browser 28 | assert( 29 | !isWebview( 30 | "Mozilla/5.0 (Linux; Android 4.4.4; One Build/KTU84L.H4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.135 Mobile Safari/537.36" 31 | ) 32 | ); 33 | ``` 34 | 35 | ## Tests 36 | 37 | Run tests 38 | 39 | ```bash 40 | npm test 41 | ``` 42 | 43 | ## Why 44 | 45 | This was built for a web service that wanted to add a logging point in case the page load came from inside a webview where cookies were possibly throw away (not treated the same as a SafariViewController or native browser load). The tests are lacking completeness as this tool was only being used to discover and add detection in logs. The author of this module is no longer the owner/maintainer of the production service that used this module, so if you are interested in using it, please consider adding more tests and make a PR with tests :) 46 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | This guide forked from https://github.com/js-n/CONTRIBUTING.md (many thanks) 2 | 3 | # Request for contributions 4 | 5 | Please contribute to this repository if any of the following is true: 6 | - You know of a case that fails the tests but shouldn't 7 | - You have more test data to contribute 8 | - You want to help improve documentation or other parts of the project 9 | - You are human (or a sufficiently advanced life-form capable of demonstrating conscious empathy) 10 | 11 | # How to contribute 12 | 13 | Prerequisites: 14 | 15 | - Familiarity with [pull requests](https://help.github.com/articles/using-pull-requests) and [issues](https://guides.github.com/features/issues/). 16 | - Knowledge of [Markdown](https://help.github.com/articles/markdown-basics/) for editing `.md` documents. 17 | 18 | In particular, this community seeks the following types of contributions: 19 | 20 | - **Test Data**: `./test/data/webview.js` and `./test/data/not-webview.js` could use more data! 21 | - **Rules**: The regex rules for testing might grow out of date 22 | 23 | # Conduct 24 | 25 | We are committed to providing a friendly, safe and welcoming environment for 26 | all, regardless of gender, sexual orientation, disability, ethnicity, religion, 27 | or similar personal characteristic. 28 | 29 | On IRC/Slack/Github, please avoid using overtly sexual nicknames or other nicknames that 30 | might detract from a friendly, safe and welcoming environment for all. 31 | 32 | Please be kind and courteous. There's no need to be mean or rude. 33 | Respect that people have differences of opinion and that every design or 34 | implementation choice carries a trade-off and numerous costs. There is seldom 35 | a right answer, merely an optimal answer given a set of values and 36 | circumstances. 37 | 38 | Please keep unstructured critique to a minimum. If you have solid ideas you 39 | want to experiment with, make a fork and see how it works. 40 | 41 | We will exclude you from interaction if you insult, demean or harass anyone. 42 | That is not welcome behavior. We interpret the term "harassment" as 43 | including the definition in the 44 | [Citizen Code of Conduct](http://citizencodeofconduct.org/); 45 | if you have any lack of clarity about what might be included in that concept, 46 | please read their definition. In particular, we don't tolerate behavior that 47 | excludes people in socially marginalized groups. 48 | 49 | Private harassment is also unacceptable. No matter who you are, if you feel 50 | you have been or are being harassed or made uncomfortable by a community 51 | member, please contact one of the channel ops, project maintainers, or any of the core team 52 | immediately. Whether you're a regular contributor or a newcomer, we care about 53 | making this community a safe place for you and we've got your back. 54 | 55 | Likewise any spamming, trolling, flaming, baiting or other attention-stealing 56 | behavior is not welcome. 57 | 58 | # Communication 59 | 60 | GitHub issues and pull-requests are the primary way for communicating about specific proposed 61 | changes to this project. 62 | 63 | Please follow the conduct guidelines above. Language issues 64 | are often contentious and we'd like to keep discussion brief, civil and focused 65 | on what we're actually doing, not wandering off into too much imaginary stuff. 66 | 67 | # Frequently Asked Questions 68 | 69 | *TBD* 70 | --------------------------------------------------------------------------------