New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 620857 link

Starred by 3 users

Issue metadata

Status: Duplicate
Merged: issue 616052
Owner:
Last visit > 30 days ago
Closed: Jun 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 1
Type: Bug



Sign in to add a comment

pauseTimers does not pause javascript

Reported by car...@instantbits.com, Jun 16 2016

Issue description


Device name: Nexus 5
Android version: 6.0.1
WebView version (from system settings -> Apps -> Android System WebView): 52.0.2743.41
Application: Web Video Caster
Application version: 4.0 (beta)




Steps to reproduce:
Go into the debug console and put this javascript in there

function foobar() {console.log(new Date()); setTimeout(foobar, 1000); } foobar();

It will print the date every second. 

Then pause the webview using onPause() and pauseTimers(), on my app I do this on the activity onPause() method. I unpage the webview on onResume() of the activity. 


Expected result:

On KitKat the javascript console.log messages stops until the activity is resumed. 

Actual result:

On Marshmallow the console messages continue. I was even able to change the webpage I was on using the console even though the activity was not visible. 


 
Just reverted one of my phones to version 39 (2237560-arm) which I'm guessing is what the phone came with and pauseTimers() worked just fine. Can you please tell me when this started being an issue? 

Thanks.

Comment 2 by boliu@chromium.org, Jun 16 2016

dunno, but that's not supposed to happen..

Comment 3 by boliu@chromium.org, Jun 16 2016

do you have a tiny app I could play with?

Comment 4 by boliu@chromium.org, Jun 16 2016

 Issue 617951  has been merged into this issue.
I'll make one really quick. 
I'm attaching the sample project. And figured out when it happens. If I call onPause() on the webview then pauseTimers() doesn't work. Doesn't matter if I call it first or second. 

Run the project, open chrome for debugging and look at the console, then press pause. 
WebViewTimers.zip
20.2 MB Download

Comment 7 by boliu@chromium.org, Jun 16 2016

Labels: -Pri-2 ReleaseBlock-Stable M-52 Pri-1
Owner: boliu@chromium.org
Status: Assigned (was: Unconfirmed)
Looks like this is broken in 52.0.2743.41 (current beta), but 51.0.2704.81 (current stable) is ok.

And looking at the beta behavior, when webview is paused, timer appears to be throttled, that it fires every two seconds. My guess is that this is chrome changing its policy of how/when js timers should be throttled, but just ignored the state of pauseTimers, which is definitely not ok

fwiw console logs by default are posted to logcat, so grepping logcat imo is a bit easier than looking at devtools

Comment 8 by boliu@chromium.org, Jun 16 2016

Bisected to between 2730 and 2733. missed two builds in between :/

Comment 9 by boliu@chromium.org, Jun 17 2016

Components: Blink>Scheduling
Owner: alexclarke@chromium.org
bisected to https://codereview.chromium.org/1958283005

webview.onPause maps roughly to RenderView becoming hidden
webview.pauseTimers maps to ViewMsg_SetWebKitSharedTimersSuspended

so looks like when when RenderView is hidden and timer is suspended, somehow the suspend state got ignored, and js timers only got throttled? Haven't actually read the CL yet

Comment 10 by boliu@chromium.org, Jun 17 2016

Yeah, that CL added new enable/disable calls when task queue is throttled, which basically overrides the actual is_enabled policy set by SetWebKitSharedTimersSuspended set only once

it's not really clear to me what the correct fix should be, so will wait for alexclarke to be back

Comment 11 by boliu@chromium.org, Jun 17 2016

Actually, that says ignore the "is_enabled" part of the policy if task queue is throttled: https://codereview.chromium.org/1958283005/diff/40001/components/scheduler/renderer/renderer_scheduler_impl.cc#newcode847

which kinda breaks the whole is_enabled thing..

trunk code looks a bit different now though
I'll take a look.
I think I see what's happened here.  The code in WebFrameSchedulerImpl::setPageVisible is probably getting called for the backgrounded tab and it's making the timers throttled.   That's conflicting with this snippet from RendererSchedulerImpl::UpdatePolicyLocked which tries to make sure suspended task queues are not throttled. 

if (MainThreadOnly().timer_queue_suspend_count != 0 ||
    MainThreadOnly().timer_queue_suspended_when_backgrounded) {
  new_policy.timer_queue_policy.is_enabled = false;
  new_policy.timer_queue_policy.time_domain_type = TimeDomainType::REAL;
}

I think we can fix this but I'll have to talk to Sami about what the best solution is.
Actually I think this might be fixed already.  Can you try again with a build that includes https://codereview.chromium.org/2028433004?

Comment 15 by boliu@chromium.org, Jun 20 2016

Yep that fixed it. Please merge to m52

Comment 16 by boliu@chromium.org, Jun 20 2016

Mergedinto: 616052
Status: Duplicate (was: Assigned)
Project Member

Comment 17 by bugdroid1@chromium.org, Jun 23 2016

Sign in to add a comment