Last Comment Bug 806597 - mozApps.getSelf does not include .result, called from web app
: mozApps.getSelf does not include .result, called from web app
Status: RESOLVED FIXED
:
Product: Firefox Graveyard
Classification: Graveyard
Component: Web Apps (show other bugs)
: Trunk
: x86 Mac OS X
: P1 major
: Firefox 26
Assigned To: Marco Castelluccio [:marco]
: Jason Smith [:jsmith]
Mentors:
: 852958 (view as bug list)
Depends on: 892837
Blocks:
  Show dependency treegraph
 
Reported: 2012-10-29 15:32 PDT by Harald Kirschner :digitarald
Modified: 2016-02-04 15:00 PST (History)
21 users (show)
See Also:
QA Whiteboard:
Iteration: ---
Points: ---


Attachments

Description Harald Kirschner :digitarald 2012-10-29 15:32:41 PDT
Works on B2G dog fooding device, does not work on Desktop and Android WebRT.

Calling mozApps.getSelf is expected to to fire onsuccess with the .result attached to the request object. success is called, without the .result.

Testable here: After installing the app, it should not ask to install again (see section "Apps getSelf"): http://about-device.testno.de/index.html
Comment 1 Potch [:potch] 2013-01-05 15:43:47 PST
Verified this is still an issue- major problem for Desktop apps.
Comment 2 Mark Finkle (:mfinkle) (use needinfo?) 2013-02-11 05:28:58 PST
Bug 819037 fixed this for Firefox on Android
Comment 3 dragonrider 2013-03-19 13:06:13 PDT
any updates on this?  
I just tried this using FirefoxOS Simulator and used the following code:
<code>
var request = window.navigator.mozApps.getSelf();
request.onsuccess = function(){
   console.log("NAME:" + request.result.manifest.name);
}
</code>

Tried using FirefoxOS Simulator pre3 from the march19 build.
also with Firefox 19.0.2 on windows 7

Both of these error out the same way.:
TypeError: request.result is null
Comment 4 Mark Finkle (:mfinkle) (use needinfo?) 2013-03-19 13:34:42 PDT
(In reply to dragonrider from comment #3)
> any updates on this?  

This bug is about the runtime on Firefox for Android, not Firefox OS (or the emulator)
Comment 5 dragonrider 2013-03-20 06:25:41 PDT
Apologies Mark.  I didn't read the bug as applying specifically to Firefox Android.  I thought 819037 that you included in comment 2 on Feb 11th was for Firefox Android.  Will run a new search and open a new bug if none turn up.
Thanks!
Comment 6 Hernán Rodriguez Colmeiro (:peregrino) 2013-03-24 11:47:32 PDT
(In reply to Mark Finkle (:mfinkle) from comment #4)
> (In reply to dragonrider from comment #3)
> > any updates on this?  
> 
> This bug is about the runtime on Firefox for Android, not Firefox OS (or the
> emulator)

Mark, I guess you refer to bug 819037, that was RESOLVED FIXED on January. This one has pretty much the same title, but filed under "Firefox". dragonrider filed bug 852958 but is basically a copy of this one, so I'm marking it as a dupe.

In regard to this issue, is there any fix? This makes it somewhat difficult to develop apps without an actual device, as you can't detect if the app is installed. I found a workaround asking for mozApps.getInstalled(), that does return the app if it's installed as the first (and only) element of the request.result array.
Comment 7 Hernán Rodriguez Colmeiro (:peregrino) 2013-03-24 11:48:05 PDT
*** Bug 852958 has been marked as a duplicate of this bug. ***
Comment 8 Jonas Sicking (:sicking) PTO Until July 5th 2013-03-24 20:25:24 PDT
The .getSelf() function is only intended to return a non-null value from *inside* the app itself.

If you are calling from a website and want to check if an app is installed, use checkInstalled() instead.
Comment 9 Hernán Rodriguez Colmeiro (:peregrino) 2013-03-24 20:40:20 PDT
(In reply to Jonas Sicking (:sicking) from comment #8)
> The .getSelf() function is only intended to return a non-null value from
> *inside* the app itself.
> 
> If you are calling from a website and want to check if an app is installed,
> use checkInstalled() instead.

Jonas, thanks again for the clarification here. I see that in MDN .getSelf() is the method to call when detecting if the app is installed (https://developer.mozilla.org/en-US/docs/Apps/Getting_Started#Checking_whether_the_app_is_installed) If the call should be to .getInstalled() I can try chasing the outdated wiki pages and update them.
Comment 10 (not reading bugmail) Nick Desaulniers [:\n] 2013-04-08 13:54:02 PDT
This tripped me up.  I found this bug referenced from this page:

https://developer.mozilla.org/en-US/docs/DOM/Apps.install

The page I got to that one from does not mention navigator.mozApps.checkInstalled:

https://developer.mozilla.org/en-US/docs/JavaScript_API?redirectlocale=en-US&redirectslug=Apps%2FApps_JavaScript_API

But this page did mention navigator.mozApps.checkInstalled:

https://developer.mozilla.org/en-US/docs/Apps/Getting_Started

I'm currently doing a documentation review, and I'm go to suggest:

1. Add navigator.mozApps.checkInstalled to the following page:
https://developer.mozilla.org/en-US/docs/JavaScript_API?redirectlocale=en-US&redirectslug=Apps%2FApps_JavaScript_API

2. Update the example on this page to install only if checkInstalled does not add the result attribute.

Please tell me that checkInstalled works on Firefox OS as it does on desktop?  If a developer is developing within desktop Firefox, they have to use checkInstalled, so hopefully they don't have to switch to getSelf when developing on device or within the simulator.
Comment 11 (not reading bugmail) Nick Desaulniers [:\n] 2013-04-08 13:55:46 PDT
For the second recommendation, "this page" refers to:
https://developer.mozilla.org/en-US/docs/DOM/Apps.install
Comment 12 Andy McKay [:andym] 2013-05-23 10:41:55 PDT
checkInstalled and getSelf are not equivalent though. From what I can tell checkInstalled does not populate an app object. This means on desktop you can't get access to any app information such as receipts, manifest etc, you just get null. This makes development on the desktop impossible for paid apps.
Comment 13 jaxo 2013-07-05 09:05:42 PDT
Have the same problem after installing a WebApp on Ubuntu [25.0a1 (2013-07-05)]
You might be interested in a bug I just filed on mozillaZine -- not sure if that was the right place: http://forums.mozillazine.org/viewtopic.php?f=23&t=2726177&e=0

In-extenso:

i suspect a asynch problem -- the debugger displays all req.result (App) members) -- or stringization leading to empty?

Bad code (req.result is empty, as shown by stringify)

var req = navigator.mozApps.checkInstalled(installUrl);
req.onsuccess = function() {
  if (req.result) {
    JSON.stringify(req.result); // <== {} e.g. empty
  }
};

Workaround with getInstalled + clone

var req = navigator.mozApps.checkInstalled(installUrl);
req.onsuccess = function() {
  if (req.result) {
    var req2 = navigator.mozApps.getInstalled();
    req2.onsuccess = function() {
    var max = req2.result.length;
    var app;
    var apps = req2.result;
    for (var i=0; i < max; ++i) {
      if (installUrl == apps[i].manifestURL) {
         app = cloneAppObject(apps[i]); // recreate by member per member assign
         break;
      }
    }
    JSON.stringify(app);  // <== OK! 
  }
};

where cloneAppObject is (pretty boring):
function cloneAppObject(app) {
  return {
    name: app.name,
    //  [...]
    manifest: {
      name: app.manifest.name,
      version: app.manifest.version,
      description: app.manifest.description,
      developer: {
        name: app.manifest.developer.name,
        url: app.manifest.developer.url
      }
    }
  };
}
Comment 14 (not reading bugmail) Nick Desaulniers [:\n] 2013-07-08 14:04:29 PDT
@jaxo: The reason has why JSON.stringify doesn't work in the first case but does in the second has to do with prototype traversal, or rather the lack of it from JSON.stringify.  Example:

function Base () {
    this.klass = "Base";
    this.member = 5;
}

function Derived () {
    this.klass = "Derived";
}

Derived.prototype = new Base();

let d = new Derived();

JSON.stringify(d); // => '{"klass":"Derived"}'
d.member; // => 5

In your first example, there are no enumerable properties on the req.result obj.  In the second, you're creating a new object whose member are copies of the req.result obj's members found by traversing the prototype chain at runtime.  Whether or not we should or shouldn't be doing that is another story, but that's the difference between your two example cases.
Comment 15 Marco Castelluccio [:marco] 2013-07-26 13:14:46 PDT
I think this problem will be fixed by bug 892837.
Comment 16 Myk Melez [:myk] [@mykmelez] 2013-08-05 10:31:16 PDT
Marco: if this doesn't get fixed by bug 892837, can you dig into it further?
Comment 17 Marco Castelluccio [:marco] 2013-08-05 10:34:35 PDT
(In reply to Myk Melez [:myk] [@mykmelez] from comment #16)
> Marco: if this doesn't get fixed by bug 892837, can you dig into it further?

Yes, sure, but I'm quite confident the problem is the principal appId (http://mxr.mozilla.org/mozilla-central/source/dom/apps/src/Webapps.jsm#2801)
Comment 18 Marco Castelluccio [:marco] 2013-08-19 16:09:12 PDT
Fixed by 892837.

Note You need to log in before you can comment on or make changes to this bug.