Vibration API only works when firefox is in foreground

RESOLVED DUPLICATE of bug 1053165

Status

()

RESOLVED DUPLICATE of bug 1053165
2 years ago
2 years ago

People

(Reporter: massaro.antonio, Unassigned, NeedInfo)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [specification][type:bug])

(Reporter)

Description

2 years ago
What did you do?
================
Hello I'm using vibration API with firefox android 46.0.1 on a google nexus 4 with android 5.1.1.
The function 
window.navigator.vibrate([300, 500, 300]);
called from a script in the html page


What happened?
==============
works well when firefox is in foreground but if firefox goes in background it doesn't work anymore. 
On the other hand the notification API works well also in background, with a call like this
last_notification = new Notification(theTitle, options);

What should have happened?
==========================
I want the vibration to work together with the notification, in background, that's when it's needed more. The vibration is the best way to call user attention when the phone is in the pocket (and firefox in background of course) if you disable the function in this situation you almost defeat the purpose of it.

Is there anything else we should know?
======================================
I love firefox because allows functions similar to mobile apps (scripts running in background is great!!) while other browsers IMO are intentionally crippled to protect the app stores. I hope firefox will disrupt the mobile app mania. IMO a good web app can replace a mobile app .
Component: API → DOM: Device Interfaces
Product: Mozilla Developer Network → Core
snorp, do you think this is because Fennec is being killed in the background?
Flags: needinfo?(snorp)
Maybe you're hitting the permissions prompt? That was added in bug 1243431.
Flags: needinfo?(snorp) → needinfo?(massaro.antonio)
(Reporter)

Comment 3

2 years ago
Thanks James for the advice. 
I have read the old thread you mentioned but I didn't find a solution. Firefox is not asking a permission prompt for the vibration as it does for gps or notifications. What I'm experimenting is that the vibration works always when the script runs into an active (foreground) tab and *never* when in background. Another user is reporting this hardcoded behaviour in this forum (2nd comment by Andrew Champ)
https://davidwalsh.name/vibration-api
It would be nice if firefox asked the user a (revokable) permission for vibration as it is for the gps, in this way malicious web sites cannot bother (well, the user could also avoid to visit these sites in first place) . 
Currently I am stuck with no way to vibrate the phone from a web app when the phone is in the pocket with screen off. It's a pity that for such a simple option missing you need to write a native android app. 
Thanks for your attention. 
Antonio
If we don't allow it from background tabs then we probably don't allow it from Service Workers, either, right? If this is intentional we should note it somewhere.

Marcos, WDYT?
Flags: needinfo?(massaro.antonio) → needinfo?(mcaceres)
(In reply to Andrew Overholt [:overholt] from comment #4)
> If we don't allow it from background tabs then we probably don't allow it
> from Service Workers, either, right? If this is intentional we should note
> it somewhere.
> 
> Marcos, WDYT?

Agree, it wouldn't make sense to have the service worker spin up and start vibrating. 

However, you can look at creating a web notification as a result of a push notification instead (which can, optionally, include a request to vibrate). That's significantly more work, but if you have the push server set up. See:
https://developer.mozilla.org/en-US/docs/Web/API/Notification/vibrate

You should be able to combine that with service workers (the example actually includes vibration!:)):
https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification

Hope that helps!
Status: UNCONFIRMED → RESOLVED
Last Resolved: 2 years ago
Flags: needinfo?(mcaceres)
Resolution: --- → INVALID
(Reporter)

Comment 6

2 years ago
Hi Marcos,
thanks for your advice. 
I implemented the web notification in my app, it's a nice feature and it works, but unfortuantely in firefox the vibration does not work (in chrome it does, even in background when screen is off). Apparently this behaviour is up to the spec defined here:
https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification
if you scroll down to the compatibility / mobile tab you will see that the vibrate option is not implemented in firefox while it is implemented in Chrome. 
Chrome has also some other nice features beside the vibration, when the notification arrives the typical notify sound is played and the led on the phone shows the new notification status, overall an experience almost identical to when you have a new message from Whatsapp. On the other hand firefox handles better the notification click because it jumps directly to the web app and clear the notification popup. These actions have to be implemented with some code instead with chrome, but it's not difficult. 
I strongly suggest you to implement the showNotification function exactly like chrome, it should be not difficult for you since you are almost close. Remember , it must vibrate also from background  ;-), play the notify sound and show the flashing led until the popup is clicked.You can test yourself with a chrome android.
REgarding the old functions, this one is going to be deprecated, it's already catching an exception in chrome: 
https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification
and window.navigator.vibrate can remain as it is to prevent abuses, but there must be the correct implementation of ServiceWorkerRegistration.showNotification.
I hope my feedbacks can be useful. Firefox is a great browser and I hope it can fully embrace the exciting  movement of progressive web apps, hoping they can disrupt native apps and make them a thing of the past.  
Best regards
Antonio
(Reporter)

Comment 7

2 years ago
Sorry Marcos, 
I forgot to ask something (I am not able to edit the prev. message).
While developing the service worker I was not able to debug it remotely (usb or wifi) on my phone, I can only debug it when running a local instance of firefox on my dev machine. In chrome I can remote debug both the app and the remote service worker running on the phone and eventually stop/unregister it from the pc. Did i miss something or this feature is not available in firefox? 
Thanks again
Antonio
Hi Antonio,
Great that you got it going. These APIs are fairly new, so I'm sure proper vibration support is coming soon (Bug 1053165)

(In reply to Antonio from comment #7)
> I forgot to ask something (I am not able to edit the prev. message).
> While developing the service worker I was not able to debug it remotely (usb
> or wifi) on my phone, I can only debug it when running a local instance of
> firefox on my dev machine. 

Unfortunately, I've never attempted to do remote debugging on Firefox for Android. I did a bit of digging and found this article:
https://developer.mozilla.org/en-US/docs/Tools/Remote_Debugging/Debugging_Firefox_for_Android_with_WebIDE 

(I don't know if it's still relevant, but I hope so... I've asked Sole, who is on our Dev Rel team, to comment if remote debugging of service workers is possible). 

> In chrome I can remote debug both the app and the
> remote service worker running on the phone and eventually stop/unregister it
> from the pc. Did i miss something or this feature is not available in
> firefox? 

It should be... but again, service workers are fairly new, so it might not yet be possible.
Flags: needinfo?(sole)
Resolution: INVALID → DUPLICATE
Duplicate of bug: 1053165
Not sure myself, I'm going to send the needinfo to jryans and jdescottes who should know more about this.
Flags: needinfo?(sole)
Flags: needinfo?(jryans)
Flags: needinfo?(jdescottes)
I have also been told in IRC that "remote debugging service workers is planned, and will be available when the remote debugging feature lands in about:debugging" - so in other words: not available now, but it will be in the future.

I'll leave the needinfo flags on-hopefully they can add the bug that corresponds to enabling remote debugging in about:debugging!
(Reporter)

Comment 11

2 years ago
Thank you Sole, that's a great news! This forum is used mainly to report bugs but let me praise the firefox remote debugging which is very cool, it works even with wifi, something I guess not even chrome has ;) currently I have debugged service workers in firefox locally and it works very well, keep it up ;)

Now if someone knows any developer working on this command:
https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification
it would be nice to know if they intend to implement also the vibrate option and notification led like Chrome does, I hope so. Maybe they can just be pinged on this thread to read more. 
Thank you Mozilla!
Comment 10 seems like an accurate summary to me.  Bug 1212802 tracks general remote debugging in about:debugging.  :jdescottes may know more details about remote service worker debugging.
Flags: needinfo?(jryans)
Antonio: this is not a forum, it's a bug tracker, which is why it's used to mainly report bugs =)

I don't know who might be working on that, so I'm going to ping Andrew and hope he can direct us to who is implementing showNotification. I have a feeling it might depend on the platform (Android or Firefox desktop), but I don't know enough. Help, Andrew!
Flags: needinfo?(overholt)
Hi,

We shipped showNotification in bug 1114554. sole is correct that there's platform-specific code there ... I don't know if we have any plans for coupling with vibration but William Chen will know. There's probably also some UX consideration here so if William doesn't know I suggest we ask Bryan Clark.
Flags: needinfo?(overholt) → needinfo?(wchen)
(In reply to Antonio from comment #11)
> showNotification
> it would be nice to know if they intend to implement also the vibrate option
> and notification led like Chrome does, I hope so.

I spoke with William and we have no current plans to do this and it seems we don't have a bug on file for it, either :) Can you file one? Just point to the relevant section of the living spec: https://notifications.spec.whatwg.org/. Thanks!
Flags: needinfo?(wchen) → needinfo?(massaro.antonio)
(Reporter)

Comment 16

2 years ago
(In reply to Andrew Overholt [:overholt] from comment #15)
> I spoke with William and we have no current plans to do this and it seems we
> don't have a bug on file for it, either :) Can you file one? Just point to
> the relevant section of the living spec:
> https://notifications.spec.whatwg.org/. Thanks!
Is it ok if I add an issue on github here? 
https://github.com/whatwg/notifications/issues
Basically I'd ask firefox to implement the missing showNotification options (like Chrome has already done)
Oh, sorry, I should have been more clear: here in Bugzilla. You can use https://bugzilla.mozilla.org/enter_bug.cgi?product=Toolkit&component=Notifications%20and%20Alerts. Thanks!
(Reporter)

Comment 18

2 years ago
(In reply to Andrew Overholt [:overholt] from comment #17)
> Oh, sorry, I should have been more clear: here in Bugzilla. You can use
> https://bugzilla.mozilla.org/enter_bug.
> cgi?product=Toolkit&component=Notifications%20and%20Alerts. Thanks!
Done, Bug 1314393
Thanks
The relevant implementation bug to follow for about:debugging is bug 1243329 which will allow about:debugging to be connected to a remote instance/device.

It's very likely that we will land this in two steps:
1 - connect to a host:port
2 - detect remote runtimes over wifi/USB

Once this is implemented, I think one should be able to debug the service workers available on the remote device using the usual about:debugging workflow (https://developer.mozilla.org/en-US/docs/Tools/about:debugging#Workers)
Flags: needinfo?(jdescottes)
You need to log in before you can comment on or make changes to this bug.