1

How can I detect if my web app is running under the CocoonJS wrapper using WebView+? I've tried if (typeof Cocoon == 'undefined') ... but that doesn't seem to work. I've checked the CocoonJS site, but this information is not easily found.

James Wilkins
  • 6,836
  • 3
  • 48
  • 73

1 Answers1

1

Turns out there's a global property cocoonjsCheckArgs that exists in this environment. I just used if (typeof cocoonjsCheckArgs =='undefined') ... to know when not to show certain messages in this environment. I have no idea if this is the correct path, but it works for me at the moment.

Update: Also noticed a difference in the agent string: Mobile Safari shows "Version/8.0 Mobile/12F70 Safari/600.1.4" on the end of the agent string (navigator.userAgent), and under WebView+ it becomes just "Mobile/12F70". Still, for now, I recommend testing for the existence of cocoonjsCheckArgs as the better option, until someone else comes by with a better approach.

James Wilkins
  • 6,836
  • 3
  • 48
  • 73
  • Interesting - I'll need this again sometime very soon, so I'll be able to look into it again. If you do end up finding another way, feel free to share an answer here, thanks. – James Wilkins Oct 05 '16 at 19:50
  • With cocoon.io, the following works, but only with Canvas+ it seems: `var is_cocoon = ( typeof navigator !== 'undefined' && typeof navigator['isCocoonJS'] !== 'undefined' );` – Joncom Oct 06 '16 at 06:16