Search code examples
javascriptiosiphonepolymerpolyfills

Polymer/platform.js polyfill addEventListener null in iOS device


On Polymer's demo page, everything works fine, on my page, it's broken.

Choking at this line:

      var isSafari = nav.userAgent.match('Safari') && !nav.userAgent.match('Chrome');
      if (isSafari) {
        // v -- choking here --  v
        document.body.addEventListener('touchstart', function(){});
      }
    }
  }
  dispatcher.register(document, true);
})(window.PolymerGestures);

I get the following error in the console:

Uncaught TypeError: Cannot read property 'addEventListener' of null

It would appear that body is null, and the debugger confirms.

Here is where I include platform.js:

<!DOCTYPE html>
<html class="no-js">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>{{ page.title }}</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">

    <script src="/components/platform/platform.js"></script>

    <link rel="import" href="/components/paper-tabs/paper-tabs.html">

Solution

  • This is a bug fixed in master: https://github.com/Polymer/polymer-gestures/pull/47

    Please file any other bugs like this on github.