detect-browser
Drop-in tag provides browser, OS, device, and language metadata — target Safari, standalone mode, mobile devices, etc. Helpful in creating device-specific UX.
Features
- Attribute metadata Set once on connect for CSS / Quark targeting
- Standalone / PWA detection
is-standalonereflects installed mode - Language detection
language-idreflects system-selected language - Device class
device-type(mobile/desktop) for coarse targeting - Full metadata
.provisionexposes user agent, languages, hardware hints
Installation
This package is available in the
<script src="https://unpkg.com/@excom/kit-utils@0.3.0/dist/index.umd.min.js"></script>
<script src="https://unpkg.com/@excom/neutron@0.2.0/dist/index.umd.min.js"></script>
<script src="https://unpkg.com/@excom/detect-browser@0.1.4/dist/index.umd.min.js"></script>npm install @excom/detect-browser<!-- import path to `node_modules` will depend on your build setup -->
<script type="module" src="/node_modules/@excom/detect-browser"></script>
<link rel="stylesheet" href="/node_modules/@excom/detect-browser">import "@excom/detect-browser";Peer dependencies (0)
Packages a consumer must install alongside this one. Workspace deps are bundled.
| Package | Version |
|---|---|
|
Usage
Drop it anywhere and select on its attributes with plain CSS.
<detect-browser></detect-browser><detect-browser></detect-browser>html:has(detect-browser[browser-name="safari"]) .safari-only {
display: block;
}html:has(detect-browser[browser-name="safari"]) .safari-only {
display: block;
}Live touch / pointer detection is detect-media media-query="(pointer: coarse)" — this element reports what the user agent says once, not what the input is now.
API Reference
Attributes
Role —option is configurable, state
is managed by the element (read-only), or hybrid which is both.
Provision
Thisprovision property lives on the DOM node.
Read / watch it with Quark’s prop("provision"), or listen
for the neutron-provision event from app JS.
Events
Type
command event (HTML Command API): from a
<button command commandfor>, an <event-handler
command-name>, or a CommandEvent.
Recognized Elements
Child or descendant elements are recognized by and relevant to its functionality.Styles
@custom-selector synonyms so custom elements can share
semantic styles. Element aliases match the host tag / .tag-* class; state
aliases match attributes (nested under the element alias).
detect-browser
Attributes (11)
Role —option is configurable, state
is managed by the element (read-only), or hybrid which is both.
browser-engine
browserEngine
string
"blink" | "gecko" | "webkit" | "trident"nullbrowser-name
browserName
string
"chrome" | "firefox" | "safari" | "edge" | "opera" | internet explorernullbrowser-vendor
navigator.vendor, lowercased.
browserVendor
string
nullbrowser-version
browserVersion
string
nullcookies-enabled
navigator.cookieEnabled is true.
cookiesEnabled
boolean
falsedevice-type
deviceType
string
"mobile" | "desktop"nulldo-not-track
navigator.doNotTrack, as reported by the browser.
doNotTrack
string
nullis-standalone
isStandalone
boolean
falselanguage-id
navigator.language, lowercased.
languageId
string
nulloperating-platform
navigator.userAgentData.platform (falls back to navigator.platform), lowercased.
operatingPlatform
string
nulloperating-system
operatingSystem
string
windows 10+ | windows 8.1 | windows 8 | windows 7 | macos <version> | "android" | "ios" | "linux"nullProvision (1)
Thisprovision property lives on the DOM node.
Read / watch it with Quark’s prop("provision"), or listen
for the neutron-provision event from app JS.
provision
navigator.languages, hardware concurrency, and device memory (GB, where supported). Not reflected as an attribute.
provision
BrowserInfo
Events (0)
e.preventDefault() is not
synchronously called on the event.
Type
command event (HTML Command API): from a
<button command commandfor>, an <event-handler
command-name>, or a CommandEvent.
Recognized Elements (0)
Child or descendant elements are recognized by detect-browser and relevant to its functionality.Styles (0)
all: revert-layer.
Valence.css ships this as .unstyled and .unstyled-all for the entire tree.
@custom-selector synonyms so custom elements can share
semantic styles. Element aliases match the host tag / .tag-* class; state
aliases match attributes (nested under the element alias).
Release notes (1)
0.1.1
- Ship only dist (and declared extras) in the npm tarball; drop build logs, tests and sources
Release notes
e.preventDefault() is not
synchronously called on the event.
all: revert-layer.
Valence.css ships this as .unstyled and .unstyled-all for the entire tree.
Examples
Language
Showing a greeting in your system language (Only Spanish or English for this example). language-id mirrors navigator.language (lowercased). Spanish prefixes show Hola; everything else shows Hello. Change the browser language (or override it in DevTools) and reload to flip it.
Safari-only install hint
iOS Safari has no install prompt, so the sheet renders "Add to Home Screen" steps there, and not once the app is installed. Spoof an iOS Safari user agent in DevTools and reload to trigger it.