ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
51.07k stars 13.51k forks source link

platform.is('cordova') returns true when running on the browser #11528

Closed jsayol closed 7 years ago

jsayol commented 7 years ago

Ionic version: (check one with "x") [ ] 1.x [ ] 2.x [x] 3.x

I'm submitting a ... (check one with "x") [x] bug report [ ] feature request [ ] support request

Current behavior: When running a production build on the browser, checking platform.is('cordova') returns true. That is not the case when running in development mode (for example, in ionic serve)

Expected behavior: AFAIK, platform.is('cordova') should only return true when run in a device as a packaged app.

Steps to reproduce:

  1. ionic cordova build browser --prod
  2. Serve the platform/browser/www folder via a web server

Related code: A simple AppComponent to reproduce:

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';

@Component({
  template: ''
})
export class AppComponent {
  constructor(platform: Platform) {
    platform.ready().then(() => {
      console.log(`platform.is('cordova') === ${platform.is('cordova')}`);
    });
  }
}

Other information:

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

global packages:

    @ionic/cli-utils : 1.0.0-rc.1
    Cordova CLI      : 6.5.0
    Ionic CLI        : 3.0.0-rc.1

local packages:

    @ionic/app-scripts              : 1.3.7
    @ionic/cli-plugin-cordova       : 1.0.0-rc.1
    @ionic/cli-plugin-ionic-angular : 1.0.0-rc.1
    Ionic Framework                 : ionic-angular 3.1.1

System:

    Node       : v7.9.0
    OS         : Windows 10
    Xcode      : not installed
    ios-deploy : not installed
    ios-sim    : not installed
jsayol commented 7 years ago

Nevermind, I was making a cordova build for the browser platform so of course it detects it as Cordova.

For anyone else facing this, the correct way to build your app for the browser without Cordova is with npm run ionic:build -- --prod and then serving the contents of the www folder (not platform/browser/www).

Cheers, and sorry for the noise.

P.S.: doing it this way, platform.ready() never fires but that's expected.

arturalkaim commented 7 years ago

What if I need to run the app with cordova? Since there is the "mobileweb" tag, I expected that the platform.is('mobileweb') would be true. Is there any way to check if I'm running in the browser or is the app in the mobile?

ionitron-bot[bot] commented 6 years ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.