WhichBrowser / Parser-PHP

Browser sniffing gone too far — A useragent parser library for PHP
http://whichbrowser.net
MIT License
1.8k stars 237 forks source link

Add `WebPageTest` to app section #553

Closed summercms closed 2 years ago

summercms commented 4 years ago

See github issue: https://github.com/WhichBrowser/Parser-PHP/issues/555

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.02%) to 99.97% when pulling 1ebff72ea896ca414b7ec64c08d304f88e96410a on ayumi-cloud:WebPageTest into 880b9fa797401d14b28956442944c3daa70240ff on WhichBrowser:master.

NielsLeenheer commented 3 years ago

I don't think we should classify WebPageTest as an application on its own. WebPageTest uses actual browsers on actual devices to load a webpage and measure loading speed. So the browser in the UA string is the browser that is being used.

summercms commented 3 years ago

Therefore change family into using

Old:

    headers: 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 PTST 200730.21064'
    readable: 'WebPageTest 200730.21064 on Linux'
    result: { browser: { name: WebPageTest, family: { name: Chrome, version: 84 }, version: '200730.21064', type: app }, engine: { name: Blink }, os: { name: Linux }, device: { type: desktop } }

Into:

    headers: 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 PTST 200730.21064'
    readable: 'WebPageTest 200730.21064 on Linux'
    result: { browser: { name: WebPageTest, using: { name: Chrome, version: 84 }, version: '200730.21064', type: app }, engine: { name: Blink }, os: { name: Linux }, device: { type: desktop } }

Code to be moved in php section as well.

        /* WebPageTest */

        if (preg_match('/\sPTST(\s|\/)([0-9.]+)/u', $ua, $match)) {
            $this->data->browser->name = 'WebPageTest';
            $this->data->browser->version = new Version([ 'value' => $match[2], 'details' => 2 ]);
            $this->data->browser->type = Constants\BrowserType::APP;

            if ((isset($this->data->browser->family->name)) && (isset($this->data->browser->family->version))) {
                $this->data->browser->using = $this->data->browser->family;
            }

            if (isset($this->data->browser->family)) {
                $this->data->browser->family = null;
            }

            $this->data->device->reset();
            $this->data->device->type = Constants\DeviceType::DESKTOP;
        }
summercms commented 3 years ago

Cleaned version: https://github.com/summercms/sc-parser-module/pull/179/files