Closed spektraldevelopment closed 10 years ago
I'm not sure if this is a grunt-casper issue versus a casperjs issue, but the CustomEvent method was not working for me through casper.evaluate:
casper.evaluate(function(){ var obj = document.createElement('div'); obj.addEventListener("cat", function(e) { console.log(e.detail) }); var event = new CustomEvent("cat", {"detail":{"hazcheeseburger":true}}); obj.dispatchEvent(event); });
I finally got it to work by implementing this polyfill on the page I was testing:
(function () { function CustomEvent ( event, params ) { params = params || { bubbles: false, cancelable: false, detail: undefined }; var evt = document.createEvent( 'CustomEvent' ); evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail ); return evt; }; CustomEvent.prototype = window.Event.prototype; window.CustomEvent = CustomEvent; })();
I thought I'd point it out as this caused me a few hours of grief, and I'd thought it might save someone some time.
Seems to be an issue with PhantomJS. https://github.com/ariya/phantomjs/issues/11289 Thank you for commenting this Polyfill
I'm not sure if this is a grunt-casper issue versus a casperjs issue, but the CustomEvent method was not working for me through casper.evaluate:
I finally got it to work by implementing this polyfill on the page I was testing:
I thought I'd point it out as this caused me a few hours of grief, and I'd thought it might save someone some time.