Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ljhyeok/f21c296eb214ecfe870f5f1eef8bfe69 to your computer and use it in GitHub Desktop.
Save ljhyeok/f21c296eb214ecfe870f5f1eef8bfe69 to your computer and use it in GitHub Desktop.
ua-parser-js를 이용해 useragent를 파싱하고 웹뷰와 웹브라우져 구분하기

개요

  • A3 script에서 useragent를 이용해 현재 단말기로 로그인한 것인지 PC에서 로그인한 것인지 결정
  • ua-parser-js 오픈 소스 사용해서 useragent를 파싱

ua-parser-js 설치

  • npm install --save-dev ua-parser-js
  • import * as uaParserJS from 'ua-parser-js'; 해서 사용

작업 내용

  • 작업한 git commit
  • /js/util/aceUtils.js
  • 어떤 webview 인지 문자열로 sync로 리턴
    • iOS
      • wkwebview
        • "wk" 리턴
      • uiwebview
        • "ui" 리턴
    • AOS
      • webview
        • "wv" 리턴
  • 브라우져일경우
    • "un" 리턴

단말기별 파싱 결과

AOS Chrome

{"ua":"Mozilla/5.0 (Linux; Android 7.0; SM-N920S) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Mobile Safari/537.36","browser":{"name":"Chrome","version":"71.0.3578.98","major":"71"},"engine":{"name":"WebKit","version":"537.36"},"os":{"name":"Android","version":"7.0"},"device":{"vendor":"Samsung","model":"SM-N920S","type":"mobile"},"cpu":{}}

AOS 기본 삼성 브라우져

{"ua":"Mozilla/5.0 (Linux; Android 7.0; SAMSUNG SM-N920S Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/7.4 Chrome/59.0.3071.125 Mobile Safari/537.36","browser":{"name":"Samsung Browser","version":"7.4","major":"7"},"engine":{"name":"WebKit","version":"537.36"},"os":{"name":"Android","version":"7.0"},"device":{"vendor":"Samsung","model":"SM-N920S","type":"mobile"},"cpu":{}}

AOS Webview

{"ua":"Mozilla/5.0 (Linux; Android 7.0; SM-N920S Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.98 Mobile Safari/537.36","browser":{"name":"Chrome WebView","version":"71.0.3578.98","major":"71"},"engine":{"name":"WebKit","version":"537.36"},"os":{"name":"Android","version":"7.0"},"device":{"vendor":"Samsung","model":"SM-N920S","type":"mobile"},"cpu":{}}

iOS Safari

{"ua":"Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1","browser":{"name":"Mobile Safari","version":"12.0","major":"12"},"engine":{"name":"WebKit","version":"605.1.15"},"os":{"name":"iOS","version":"12.1.1"},"device":{"vendor":"Apple","model":"iPhone","type":"mobile"},"cpu":{}}

iOS Chrome

{"ua":"Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/71.0.3578.89 Mobile/15E148 Safari/605.1","browser":{"name":"Chrome","version":"71.0.3578.89","major":"71"},"engine":{"name":"WebKit","version":"605.1.15"},"os":{"name":"iOS","version":"12.1"},"device":{"vendor":"Apple","model":"iPhone","type":"mobile"},"cpu":{}}

iOS WKWebview

{"ua":"Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16C50","browser":{"name":"WebKit","version":"605.1.15","major":"605"},"engine":{"name":"WebKit","version":"605.1.15"},"os":{"name":"iOS","version":"12.1.1"},"device":{"vendor":"Apple","model":"iPhone","type":"mobile"},"cpu":{}}

iOS UIWebview

{"ua":"Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16C50","browser":{"name":"WebKit","version":"605.1.15","major":"605"},"engine":{"name":"WebKit","version":"605.1.15"},"os":{"name":"iOS","version":"12.1.1"},"device":{"vendor":"Apple","model":"iPhone","type":"mobile"},"cpu":{}}

관련 자료

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment