69
Mobile Web Application 苦談 othree @ MOPCON 2013

Mobile web application

  • Upload
    -

  • View
    264

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Mobile web application

Mobile Web Application ⽢甘苦談

othree @ MOPCON 2013

Page 2: Mobile web application

me

• @othree

• MozTW member

• PhD Candidate of civil engineering

• F2E at HTC

• https://blog.othree.net/

Page 3: Mobile web application

• Front End related

• Experience sharing

• No code listing

Page 4: Mobile web application

Why Mobile

• We are HTC....

Page 5: Mobile web application

Mozilla Summit 2013

Page 6: Mobile web application

Mozilla Summit 2013

Page 7: Mobile web application

PM Says

“We are going to support mobile browsers”

Page 8: Mobile web application

What We Thought

• Web Standards rule the web

• Not big problem

Page 9: Mobile web application

Reality

• Browser have bugs

• Standard implementation not the same

• Ambiguous standards

• Hard to debug on some browser

• Any issue might be new, not like IE

Page 10: Mobile web application

Reality

• Browser have bugs

• Standard implementation not the same

• Ambiguous standards

• Hard to debug on some browser

• Any issue might be new, not like IE

Survey

Page 11: Mobile web application

What browser you use on smartphone?

Page 12: Mobile web application

What browser you use on smartphone?

b) You install browser by yourself

a) Default browser from your phone

Page 13: Mobile web application

Android Browser

Page 14: Mobile web application

Android Browser

• No updates anymore

• Google use Chrome as new default

• Still exists: HTC, Samsung Galaxy S3

Page 15: Mobile web application

Mozilla Summit 2013

Page 16: Mobile web application

• Have bugs, issues

Page 17: Mobile web application

S4 Chrome?

Page 18: Mobile web application

S4 Chrome?

Page 19: Mobile web application
Page 20: Mobile web application

Suggestion to Users

• Use Chrome or Firefox or …

Page 21: Mobile web application

So...

Page 22: Mobile web application

So...Issues

Page 23: Mobile web application

Issues

• No repaint

• Ghost Click

• Toggle location bar will not trigger resize

• preventDefault not work on touch event

• HTML5 Video

Page 24: Mobile web application

Repaint

• To save power, browser will reduce repaint

• It predicts best timing for repaint, what to repaint

• Prediction might fail

Page 25: Mobile web application

If Not Repaint

• Things will disappear, in wrong position...etc

Page 26: Mobile web application

Force Repaint

• Access some attribute related to layout

• ex: offsetHeight

Page 27: Mobile web application

Ghost Click

• Mobile device don’t have real ‘click’ event

• Simulate ‘click’ using touch events

• ‘click’ has 300ms delay after ‘touchend’

Page 28: Mobile web application

Avoid Lag

• Use ‘touchend’

• tap.jshttps://github.com/alexgibson/tap.js

• fastbuttonhttps://developers.google.com/mobile/articles/fast_buttons

Page 29: Mobile web application

But..

• Android Browser

• Trigger simulated click on wrong element

Page 31: Mobile web application

Location Bar

• 3 states in Android Browser

• show

• hide

• pinned

Page 32: Mobile web application

Location Bar

• 3 states in Android Browser

• show

• hide

• pinned

Page 33: Mobile web application
Page 34: Mobile web application
Page 35: Mobile web application
Page 36: Mobile web application

What’s the Deal

• Window size changes

• Trigger ‘resize’ event?

• Android 2: Yes

• Android 3: No

http://www.quirksmode.org/dom/events/resize_mobile.html

Page 37: Mobile web application

Fix

• Time Interval to check window size change

• 200ms interval will cause video not play

• Manuel trigger resize handler when window size might change

Page 38: Mobile web application

preventDefault

• Can used to prevent user scroll web page

• Not work on HTC browser

• Not a bug, its spec...

Page 39: Mobile web application

HTML5 Video

• Loop not work

• Play event not reliable

• Duration update issue

• iPhone, iPod have different implementation

Page 40: Mobile web application

Loop

• Video loop not work on all mobile browser

• But you can call `play()` on ‘ended’ event

Page 41: Mobile web application

Video Bugs

• ‘play’, ‘playing’ event not reliable

• Duration have default value

• Won't stop when buffer ready even if `pause()` were called

Page 42: Mobile web application

MOPCON 2013

Page 43: Mobile web application

pause() not work

play()

download buffer

pause()

buffer ready, playplayingplay

Page 44: Mobile web application

RobustVideo

• A video wrapper to fix issues above

• https://github.com/othree/robust-video

Page 45: Mobile web application

iPhone

• Open native player to play HTML5 video

Page 46: Mobile web application

iPhone

• Open native player to play HTML5 video

Page 47: Mobile web application
Page 48: Mobile web application
Page 49: Mobile web application

Limitation

• Video needs visible to be able to play

• Poster will not used to render in web page

• No video event is available

Page 50: Mobile web application

Limitation

• Video needs visible to be able to play

• Poster will not used to render in web page

• No video event is available

Page 51: Mobile web application

Tip

• Video element outside of window

• Tap img(poster) to trigger `video.play()`

Page 52: Mobile web application

Tip

• Video element outside of window

• Tap img(poster) to trigger `video.play()`

<video>

<img>

Page 53: Mobile web application

呼...

Page 54: Mobile web application

Next Time PM Says

“We are going to support mobile browsers”

Page 55: Mobile web application

We Say

“Well, it takes x times longer to do it.”

Page 56: Mobile web application

We Say

“Well, it takes x times longer to do it.”

Mobile DebuggingHow to

Page 57: Mobile web application

Browsers

• Safari

• Chrome

• Firefox/Opera

• Android Browser

Page 58: Mobile web application

Safari

• Enable Debug

• Connect iDevice to your Mac

• Open Safari

https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/DebuggingSafarioniPhoneContent/DebuggingSafarioniPhoneContent.html

Page 59: Mobile web application

Chrome

• Install the ADB Chrome extension

• Install driver of your device

• Enable Debug

• Connect device to PC/Mac

https://developers.google.com/chrome-developer-tools/docs/remote-debugging

Page 60: Mobile web application
Page 61: Mobile web application

Firefox

• https://hacks.mozilla.org/2012/08/remote-debugging-on-firefox-for-android/

Page 62: Mobile web application

Android Browser

• Weinre http://people.apache.org/~pmuellr/weinre/docs/latest/

Page 63: Mobile web application
Page 64: Mobile web application
Page 65: Mobile web application
Page 66: Mobile web application
Page 67: Mobile web application
Page 69: Mobile web application

Thanks