4

I'm working on a qr reader as part of a larger web application. Since the application is structured into several pages for each view, so not a single page app (SPA), I usually don't have any interaction from users on qr reader page because they've already done it on previous page by clicking "open reader" button. By calling navigator.vibrate(200) a browser won't vibrate if user hasn't tapped a screen on the page that calls it. I want to use the vibration api as a signal of successfully found qr code.

As far as I know it's a general problem of any "old school" non SPA web app which utilizes functions restricted to user interaction. E.g. vibration, fullscreen, autoplay.

Is there any way around it except merging the page with the button and qr reader into one to not lose "user has interacted" between page reloads?

function qrCodeFoundCallback() {
  if ('vibrate' in navigator) {
    navigator.vibrate(200)
  }
}

I expect a device which supports vibration api to always vibrate if a qr code is found even if user hasn't touch the screen after the page with camera finder has loaded.

Now the device vibrates only if the user randomly touched the screen but there's no reason for him/her to do it. The page contains camera finder and back button only.

  • The user has to have tapped on the page for the vibrate function to work. This is unavoidable. Have a look at [this question](https://stackoverflow.com/questions/46189105/how-to-bypass-blocked-call-to-navigator-vibrate-because-user-hasnt-tapped-on-t) – Wendelin May 01 '19 at 00:04
  • `so not a single page app (SPA)` Single page applications can have routing logic, they can use the history API to do page loading. IOW: From a users point of view it looks like a normal website, but in reality it's a SPA. – Keith May 01 '19 at 00:42
  • 1
    User has tapped but that interaction is lost when navigating from the page with the "open reader" button to camera finder. It feels unjustified that I can vibrate on one page and immediately after page navigation I'm not able to even though the user is kept on the same domain, same session. When done properly he/she can't even see whether it's SPA or not. The permission to vibrate is not gained for the whole site even after it's added to homescreen. Well it seems that rewriting the app to SPA or merging the qr reader part to other page is the only way to make vibration API reliable. – Filip Chalupa May 02 '19 at 10:43

0 Answers0