3

次の Web コンポーネントまたはカスタム要素を作成しているとします。

<!doctype html>

<html>
  <head>
    <script src="js/MutationObserver.js"></script>
    <script src="js/CustomElements.js"></script>

    <script>
      var proto = Object.create(HTMLElement.prototype);

      proto.createdCallback = function() { console.log('created');};
      proto.enteredViewCallback = function() {};

      document.register('x-foo', {prototype: proto});

      document.createElement('x-foo');
    </script>
  </head>

  <body>
  </body>
</html>

( github の polyfill ) これは Chrome で動作します。しかし、これを PhantomJS で実行しようとすると、次のエラーが発生します。

TypeError: instanceof called on an object with an invalid prototype property.

http://localhost/~me/js/CustomElements.js:18
http://localhost/~me/js/CustomElements.js:217 in instantiate
http://localhost/~me/js/CustomElements.js:333
http://localhost/~me/js/CustomElements.js:342 in createElement
...

再現したい場合は、ここに私のphantomjsスクリプトがあります

var page = require('webpage').create();
page.open('http://localhost/~me/test.html', function() {
  phantom.exit();
});

私は他のポリフィルを試しました

しかし、実際にはどれも機能しませんでした。これを修正する方法はありますか?

4

1 に答える 1

1

私も同じ問題を抱えていました。このポリフィルで解決されました: https://github.com/WebReflection/document-register-element

document.registerElement メソッドを使用する必要があります。

于 2015-08-19T16:26:19.450 に答える