Browser On Suspend/On Resume not triggering

Bugs will be moved here once resolved.

Post » Mon Jul 06, 2015 2:11 am

Problem Description
Browser>On Suspend & Browser>On Resume not triggering on Chrome for iOS and Android stock browser.

Attach a Capx
https://drive.google.com/file/d/0B7P74F ... sp=sharing

Description of Capx
A blue sprite and a orange sprite show up when you load the layout, when the browser is suspended(minimized to background) and Browser>On Suspended is triggered, the blue sprite changes to green, and when Browser>On Resume is triggered the orange sprite changes to pink when the game is is the foreground again.

Steps to Reproduce Bug
  • Open the game in Chrome for iOS or the stock Android browser
  • Minimize the game to the background by pressing the home button on either iOS or Android
  • Reopen the browser to the foreground

Observed Result
When the browser is minimized to the background then reopened the blue sprite does not change to green because Browser>On Suspend was not triggered and the orange sprite does not change to pink because Browser>On Resume was not triggered.

Expected Result
The blue sprite should change to green when Browser>On Suspend is triggered, the orange sprite should change to pink when Browser>On Resume is triggered.

Affected Browsers
  • Chrome for iOS (YES)
  • Stock Android Browser for Android 5.0 (YES)
  • Internet Explorer: (NO)
  • Firefox: (NO)
  • Firefox Android: (NO)
  • Chrome for Android: (NO)
  • Chrome for PC: (NO)
  • Safari for iOS: (NO)
  • Safari for Mac: (NO)

Operating System and Service Pack
Windows 7 Home Premium, Service Pack 1

Construct 2 Version ID
r209

Notes: I noticed this bug when testing a game on Chrome for iOS and the stock Android browser, when you minimize the browser to the background your background music keeps playing, but on Safari for iOS and Chrome for Android it stops playing the music till the browser gains focus again. Not sure if this is on the C2 side or on the browser side.
B
50
S
17
G
2
Posts: 110
Reputation: 4,484

Post » Wed Jul 15, 2015 11:36 am

Closing as won't fix: the problem is with the browser, not C2.

In Chrome for iOS, it correctly triggers 'On suspend' and 'On resume' when switching tabs, but not when returning to the home screen and going back (which Safari does correctly). Old Android stock browsers simply don't support the Page Visibility API which is the way the browser tells C2 if the page has been hidden, so it can't be supported. It should work in Chrome for Android though.
Scirra Founder
B
399
S
236
G
89
Posts: 24,519
Reputation: 195,351

Post » Wed Jun 15, 2016 1:30 pm

Are there any methods I could call from Javascript manually, to inform construct about the visibility change?
B
7
S
1
G
1
Posts: 10
Reputation: 427

Post » Wed Jun 15, 2016 2:38 pm

Waog wrote:Are there any methods I could call from Javascript manually, to inform construct about the visibility change?


I found it out myself. Use this code to trigger the supend and resume manually:

Code: Select all
function simulatePageVisibilityApiHide() {
    document.hidden = true;
    document.mozHidden = true;
    document.webkitHidden = true;
    document.msHidden = true;
    var event = new Event('visibilitychange');
    document.dispatchEvent(event);
}

function simulatePageVisibilityApiUnhide() {
    document.hidden = false;
    document.mozHidden = false;
    document.webkitHidden = false;
    document.msHidden = false;
    var event = new Event('visibilitychange');
    document.dispatchEvent(event);
}
B
7
S
1
G
1
Posts: 10
Reputation: 427

Post » Mon Nov 13, 2017 10:46 am

@Waog Where do I put this code. Is it in the index file?
Image
B
29
S
8
G
1
Posts: 120
Reputation: 2,835


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 1 guest