次の 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();
});
私は他のポリフィルを試しました
しかし、実際にはどれも機能しませんでした。これを修正する方法はありますか?