最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it possible to detect the Android captive portal browser? - Stack Overflow

programmeradmin4浏览0评论

I have a captive portal which, as of Android 5.0+ Lollipop, launches in Android's Captive Portal Browser rather than the device's default browser.

I need to somehow detect if they are in the captive portal browser (as opposed to a regular web browser) and if so, show different content.

Is it possible, by examining the User Agent, or through Javascript, to detect if they are within a Captive Portal Browser window? I have looked at the user agents on my Android 5.1 device, but I can't see anything to differentiate them:

CAPTIVE PORTAL BROWSER:

Mozilla/5.0 (Linux; Android 5.1; Elite 5 Build/LMY47D) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36

REGULAR GOOGLE CHROME:

Mozilla/5.0 (Linux; Android 5.1; Elite 5 Build/LMY47D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.94 Mobile Safari/537.36

There is a slight difference in the version numbers but this seems inconsistent across Android/Chrome versions and not a reliable way to determine the browser type.

Are there other ways to detect it? Thanks in advance.

I have a captive portal which, as of Android 5.0+ Lollipop, launches in Android's Captive Portal Browser rather than the device's default browser.

I need to somehow detect if they are in the captive portal browser (as opposed to a regular web browser) and if so, show different content.

Is it possible, by examining the User Agent, or through Javascript, to detect if they are within a Captive Portal Browser window? I have looked at the user agents on my Android 5.1 device, but I can't see anything to differentiate them:

CAPTIVE PORTAL BROWSER:

Mozilla/5.0 (Linux; Android 5.1; Elite 5 Build/LMY47D) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36

REGULAR GOOGLE CHROME:

Mozilla/5.0 (Linux; Android 5.1; Elite 5 Build/LMY47D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.94 Mobile Safari/537.36

There is a slight difference in the version numbers but this seems inconsistent across Android/Chrome versions and not a reliable way to determine the browser type.

Are there other ways to detect it? Thanks in advance.

Share Improve this question asked Oct 5, 2015 at 13:52 provenwebprovenweb 631 silver badge4 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

You can use Modernizr to detect the existence of the Fetch API or Local Storage features, both of which exist in regular Google Chrome and Firefox, etc but aren't available in the captive portal browser.

The Pixel devices I'm testing on now pass both these tests -

try {

    const test = 'test';
    
    localStorage.setItem(test, test);
    localStorage.removeItem(test);
    sessionStorage.setItem(test, test);
    sessionStorage.removeItem(test);
    alert("We're in a chrome instance!")
} catch(e) {
    alert("We're inside a Captive Portal!")
}

Running on Android 10 - Pixel XL and regular Pixel

For a lot of other devices - the above localStorage test works fine - we go into a catch block and determine that we are not inside a full fledged Chrome tab/Android Default browser tab, but Android has changed the way it runs captive portal it seems.

I just found a simple technique for finding captive portal in Android only, https://developer.chrome./docs/multidevice/user-agent. Follow this instruction, all captive portal in android 're webview and they have "Version" on useragent.

发布评论

评论列表(0)

  1. 暂无评论