Languages

Menu
Sites
Language
[Wearable 3.0]Uncaught TypeError: Failed to execute 'initCustomEvent' on 'CustomEvent': 4 arguments required, but only 3 present

I'm creating a gear watch face with Tizen studio. I write the code to create always-on mode and it works on wearable 2.3.2 without any errors. When I try it on wearable 3.0 it displays some errors when the always-on mode is activated and the device screen turns off. 

this is the error:

Uncaught TypeError: Failed to execute 'initCustomEvent' on 'CustomEvent': 4 arguments required, but only 3 present.

the source shows this:

(function(){var __event = document.createEvent("CustomEvent");
__event.initCustomEvent("timetick", true, true);
document.dispatchEvent(__event);

for (var i=0; i < window.frames.length; i++)
{ window.frames[i].document.dispatchEvent(__event); }})()

 

I found a fix on the internet for this, change

__event.initCustomEvent("timetick", true, true); "

to

__event.initCustomEvent("timetick", true, true, {});"

 

but how I can do that?

This is the javascript code for the always-on mode:
 
function bindEvents() {
          window.addEventListener('timetick', ambientWatch);
 
          window.addEventListener("ambientmodechange", function(e) {
               if (e.detail.ambientMode === true) {
                    //rendering ambient mode case
                    activateMode("Ambient");
                    } else{
                     //rendering normal case
                     activateMode("Normal"); 
                   }
             });
 
              document.addEventListener("visibilitychange",function(){
 
                    if(!document.hidden) {
                           updateTime();
 
                             if(isAmbientMode === true){
                                   activateMode("Ambient");
                             }else{
                                   activateMode("Normal");
                              }
                      }
           });
};
Edited by: Luca Bortolami on 28 Jul, 2018

Responses

1 Replies
Armaan-Ul- Islam

Hello Luca Bortolami,

Try initEvent() instead of initCustomEvent().It worked fine on my environment.

Code Snippet:

document.addEventListener('CustomEvent', function (ev) { 
   console.log("CustomEvent triggerd");
   });
   
var __event = document.createEvent('CustomEvent');
__event.initEvent('CustomEvent', true, true);
document.dispatchEvent(__event);

 

Check out the MDN Web docs: Creating and triggering events for further documentation. Please share feedback here.