HTML5 website running geolocation and audio output while phone screen is off? - javascript

Very similar questions in the past:
HTML5 website running while phone screen is off?
HTML5 mobile app running while phone screen is off?
But now it's 2020... and just a few months ago this worked on firefox. I created a small test page that should "speak" every ~10 seconds and tell you the x/y offset in meters from when you first loaded the page. When the screen is on it also shows you this on a map.
https://supplyrunner.netlify.app/test0/index.html
When the screen was turned off I could not get this working using chrome on my android phone but it worked with firefox. I didn't think the support would get dropped so I didn't note the version of that browser. Now it no longer seems to work with the latest firefox, chrome, or Opera (with the screen off).
Is there anything I can do to tell these browsers to continue running in the background? I looked at requesting wakelocks (https://developer.mozilla.org/en-US/docs/Archive/B2G_OS/API/Navigator/requestWakeLock) but that didn't work on firefox and had no effect on chrome.
Is there another browser I can use that has more reasonable behavior or options? I believe a user should have the option to run webapps in the background, even if it means explicitly running the browser in a different mode (similar to incognito) for the sake of security and transparency.
Is there anything I can do in my JS code (web workers?) to force some code to run in the background? Can this code access geolocation and the speech API (so it can talk to the user).
Worse case option: Are there any apps I can run that would simulate a screen lock such that a user could run the webpage, then run this app instead of locking their screen, allowing the page to continue running while the screen turns black and becomes unresponsive to touch (so they can put the phone in their pocket), but the OS doesn't register this as a "screen off" event?
Are there any other alternatives that I haven't thought of?
Note that I have an application that requires background geolocation and access to audio out (to speak or play sounds). This was originally written as a native android app but in the past year I have refactored it to be a webapp to avoid issues with google API keys and licenses, to make it OS agnostic (iOS and android), and also to make it much simpler to extend and customize. Going back to a native app is not an option.
Edit:
Here is a simpler page that shows the same issue (with no map) in less than 50 lines of JS/html combined: https://supplyrunner.netlify.app/test1/index.html
I noticed that firefox on android actually still allows some things, like youtube videos, to keep running media in the background with the screen off, but seems to no longer run JS so window.speechSynthesis.speak() and navigator.geolocation.getCurrentPosition() don't work.

Related

DPR not working on firefox/chrome inspector

My last question was closed for some reasons (Chrome Inspector not even 1% accurate to real mobile devices)
However as it seems the problem was related to the DPR. I will attach images to show my problem
Chrome/Firefox Inspector with DPR 2.0 for Iphone 6/7/8:
Real Iphone 6:
I can not simulate the DPR on any website on any browser on my pc or my friends pc. It will always scale like 1. Doesnt matter if I use DPR 1,2 or 3.
So my questions is how to successfully simulate DPR 2.0?
I guess the problem is DPR or is it something else?
First of all the bigger text was my bad, my iphone got bigger text set that was the reason why the text was different. However the core of this topic is still the same and the resolution is different to chrome inspector and real devices. However mostly because of the browser taskbars.
As it seems no browser related inspector solution is working. However even when some people said it is not possible to emulate real devices it´s actually possible and also by google itself with android studio:
https://developer.android.com/studio
You can use any android version and create any resolution you want. You can also test localhost from your host os inside of your emulated smartphone browser by using this instead of the default localhost/127.0.0.1:
10.0.2.2
You can also open inspector of your emulated device from your main os! By using:
chrome://inspect/#devices
And here is starting the real question. Why does this inspector window clone the correct device resolution from the emulated device? I mean it´s literally the default chrome inspector window again. Very confusing.
They even clone the menubar, even when it´s now showing, the resolution and everything else was cloned 1to1 compared to the android studio emulator.
However I guess it´s more realtime streaming than actually cloning.
That´s to the point it´s not possible..
Also maybe very nice to know that you can use the fullscreen API to dodge problems with those annoying browser taskbars which crash your ui and take space. You can use this code to enter fullscreen with user gesture:
<button id="goFS">Go fullscreen</button>
<script>
$("#goFS").on("click",function(){
// this works with scroll - do not use document.body.requestFullscreen();
const elem = document.documentElement;
if (elem.requestFullscreen) {elem.requestFullscreen()}
if(document.fullscreenElement){
console.log('fullscreen detected');
}
});
</script>
In fact it´s really sad that you have to download android developer software just to emulate real display solutions as web designer. I hope google will build in this technology in future inside of their chrome inspector.
Also I guess apple is providing the same software for their ios app development. So you should be able to emulate iphones their too. However as far as I read you must use a MAC machine for this.
Hope this will help anybody.

LinkedIn App Browser Issues: Background Video and Animations

When you open a website in LinkedIn's app (iOS), html5 background videos set to autoplay do not play, and animations do not fire unless you stop scrolling. So, it often looks like there is a bunch of empty space when you use fade and slide animations.
Here are a few examples (you must view within LinkedIn's app to see the issue)...
Background video
https://jobs.netflix.com/
https://thelovinggroup.com/ (also has animation issues)
Animations
https://voidwatches.com/
http://www.clearmotion.com/
Any thoughts on how to tackle this issue until LinkedIn builds a better browser?
I've looked into browser detection as a possible solution. Thinking maybe I could do an if/else statement to check if it's a common browser (Chrome, Safari, Firefox, etc.), else do something else with those videos and animations.
But everything I've read for browser detection strongly recommends against using it unless you absolutely have to (https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent).
Any thoughts would be very much appreciated!
UPDATE
Ok, so I've implemented the code from this Github project to detect UIWebView: https://github.com/simpleweb/UIWebView-Detect
And it works well! However, I really need to differentiate between LinkedIn and other apps with WebView because LinkedIn is the only one with these issues.
I used Udger's parser (based on what I found in another Stack Overflow post): https://udger.com/resources/online-parser
And I can see that Facebook has its own browser, but LinkedIn seems to be using some version of Safari.
I feel like I'm starting to get closer, but I'm still not sure I've come up with a solid solution.

HTML5 audio/javascript stops working on android(google chrome) when screen is turned off

I have created a Web App which plays music playlist and it works well on desktop browsers and also in mozilla and opera of android. But When I play the songs on Chrome browser of Android and I turn off the screen, it stops after playing the current song. And as soon as I turn the screen on, it starts loading the next song in line.
From my observations, what I have understood is Google Chrome browser on android pauses the javascript code from executing if the screen is turned off till the screen is not waken up again. Is there any way I can prevent my specific library from pausing? Any approach or events?
Some related this question is what I am looking for: JavaScript halts in inactive android Chrome tab
There are so many WebApps which does not stop playing music. Does it need some permissions from Google App Store?
check what happens with youtube, at least few years ago i had an awful time dealing with that and that's what proved to my client it cant be done in the given time frame and budget. that was actually device specific, on some devices it worked fine and on others it didnt. check if it happens on other devices. the only solutions i could think of ware either to prevent screen turn off (on problematic devices or all of them at the beginning), or to build an app and handle onPause event
I don't think that you can change the behaviour of the Chrome app, if they want to save battery in the background and stop the javascript, you won't reactivate it.
There are maybe some other ways to get it working.
Tell your users that they should use Firefox or Opera on their mobile device.
All apps are allowed to play or stream music in the background, so you could make or use an app for your task.
Maybe you can use the default music player app on android. Open a playlist of streams using the app. (I don't know if this is possible, because I have no android device.)
I know that is not exactly what you want, but a maybe a way to get it working.

PhoneGap loading although script is running

I am developing a reasonably large application on PhoneGap version 2.8 for Android. The issue that I can't seem to fix or even understand why it is happening is described as follows. When I start the application, initially a white screen is shown, which is completely fine since I undestand that it takes a moment or two to launch cordova. I have added a plugin to the project that puts the application to the background when user clicks "back" button in the "home" view. I can see that my app is still running in the task manager which is all fine and dandy. If I click on the app to bring it to foreground, app returns to foreground but views blank white screen for ~3 seconds, after which my view is rendered. I am wondering if there is any way I could speed up whatever the process is going on. I have noticed that it doesn't happen if my app isn't installed with APK but is run by IDE in debug mode (in which case it runs instantly just like any other normal app), but it still persists, if I click on the app icon in the apps menu.
I know that onDeviceReady event is fired way before the blank screen is gone. I know that some html is added into DOM tree. By the time white screen disappears even my ajax request is back with more data to be displayed on the screen. I know that whatever is, that effect is not because of my scripts being loaded in.
I suspect that this is effect is due to Phonegap taking a moment to restore it's Activity, or WebView to restore (if that makes sense).
I have tested that on different physical devices (Galaxy S2 and S3, HTC One X).
There is alot of optimization still to be done (memory is leaking somewhere, and there seems to be alot of performance issues with older phones eg. HTC One V).
I have tried to show Splashscreen while the white screen is up, but it is hard to estimate, when i should hide it (javascript seems to be running asynchroniously in relation to white screen).
Perhaps anyone would be kind enough to explain what is causing the white screen to be present and what could be done to resolve that issue.
Much obliged,
Erich

'Firebug' for iPad

I have a site that uses javascript to launch a css overlay of a google map (see [link deleted because I can only have one at a time] and click the 'Enlarge' button under the map).
This doesn't work on the ipad. I believe it has something to do with this not being a link, but using the jquery live('click',.. approach. I need to fix this but I'm new to using the ipad and I don't even know how to step through the javascript to see what the problem is.
What kind of development tools are available for testing on the ipad?
Edit: My mistake. The link above works fine in the iPad - no problem bringing up the larger map. However the sister site http://lowes-realty.com/Stateline-Plaza_Enfield_CT-11.aspx is not working. What I need is a development system that will let me look at them both on the ipad (I really want to avoid emulating or spoofing).
Have you tried firebug lite?
http://getfirebug.com/firebuglite#Install
Have you tested this in google chrome? As google chrome is a webkit browser, you may be able to do the majority of your debugging in chrome, and iron out smaller issues on the iPad itself.
Edit:
Removed unnecessary comment about iPad.
The problem ended up being that I had a javascript error that aborted the script before I ever got to the jQuery code. Once I fixed that, I was able to use jQuery without making any special modifications for the ipad - awesome! I did not have to do anything with the swipe or tap events (sweet!).
However I was not able to get any kind of javascript debugger; I had to work this one out for myself. As of Nov '09 firebug lite crashed the ipad for me and there don't seem to be any developer tools build for testing the ipad. I tried several sites that claimed to perform the same way the ipad does in your browser and not one of them held water.
I have no reason to believe that there is a good option for debugging a site on an ipad (yet).
Edit A Year Later... I'm still looking for a good way to develop on an iPad. I just got Adobe Shadow up and running - it's not actually a useful tool, but there is potential (http://tv.adobe.com/watch/adobe-technology-sneaks-2012/adobe-shadow). Right now (3-29-12) the code inspector is essentially non-functional (cannot view inherited styles, can't view elements without expanding the DOM from the body element, no javascript debugging, and much more).
I know that sounds hopeless, but it has one thing going for it that nothing else I'm aware of does: Shadow works with all existing mobile devices and its code inspector is independent of device and browser. So although the inspector sucks spectacularly right now, once they build some functionality into it Shadow could be a good solution. From their site:
Shadow will be updated regularly to stay ahead of web standards, web
browser updates and support for new mobile devices entering the
market, while incorporating user feedback to provide the best
functionality and experience possible.
~ http://labs.adobe.com/technologies/shadow/
I think the problem is that on the iPhone / iPad there are no clicks events generated but instead touch events (swipe, tap).
You can use something like jQTouch (you can start reading here Getting started and then proceed to callback events hint: tap==click).
If you have more to adapt you can also look at (and wait for a stable release) of jQuery Mobile
weinre lets you remotely attach a WebKit inspector (the built-in Dev Tools you use on desktop browsers) to a page running on your mobile device (iPad/iPhone/iPod/Android/BlackBerry 6/webOS) over WiFi.
http://phonegap.github.com/weinre/images/weinre-demo.jpg
JavaScript debugging is limited to console.logs, but it's better than nothing.
If you have an ICS device, Chrome Mobile lets you remotely attach a full-featured Inspector (with full JS debugging/breakpoints) over USB. I've been thoroughly thrilled using this tool with my Galaxy Nexus.
(source: google.com)

Categories