javascriptcocoonjs

How To Detect If Web App Is Wrapped By CocoonJS


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.


Solution

  • 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.