mozApps.getSelf does not include .result, called from web app

RESOLVED FIXED in Firefox 26

Status

Firefox Graveyard
Web Apps
P1
major
RESOLVED FIXED
5 years ago
a year ago

People

(Reporter: Harald, Assigned: marco)

Tracking

Trunk
Firefox 26
x86
Mac OS X

Details

(Reporter)

Description

5 years ago
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

4 years ago
Verified this is still an issue- major problem for Desktop apps.
Bug 819037 fixed this for Firefox on Android

Updated

4 years ago
Component: DOM: Apps → Web Apps
Product: Core → Firefox
QA Contact: jsmith

Comment 3

4 years ago
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
(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

4 years ago
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!
(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.
Duplicate of this bug: 852958
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.
(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.
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.
For the second recommendation, "this page" refers to:
https://developer.mozilla.org/en-US/docs/DOM/Apps.install

Comment 12

4 years ago
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

4 years ago
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
      }
    }
  };
}
@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.
(Assignee)

Comment 15

4 years ago
I think this problem will be fixed by bug 892837.
Depends on: 892837
Priority: -- → P1
Marco: if this doesn't get fixed by bug 892837, can you dig into it further?
(Assignee)

Comment 17

4 years ago
(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)
(Assignee)

Updated

4 years ago
Assignee: nobody → mcastelluccio
Status: NEW → ASSIGNED
(Assignee)

Comment 18

4 years ago
Fixed by 892837.
Status: ASSIGNED → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 26
Product: Firefox → Firefox Graveyard
You need to log in before you can comment on or make changes to this bug.