Closed Bug 806597 Opened 12 years ago Closed 11 years ago

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

Categories

(Firefox Graveyard :: Web Apps, defect, P1)

x86
macOS

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 26

People

(Reporter: Harald, Assigned: marco)

References

Details

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
Verified this is still an issue- major problem for Desktop apps.
Bug 819037 fixed this for Firefox on Android
Component: DOM: Apps → Web Apps
Product: Core → Firefox
QA Contact: jsmith
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)
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.
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.
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.
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.
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?
(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: nobody → mcastelluccio
Status: NEW → ASSIGNED
Fixed by 892837.
Status: ASSIGNED → RESOLVED
Closed: 11 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.