I am trying to code a gnome-shell extension. It uses Javascript. But one major problem when I want to use setTimeout() it tells me this in the log: ReferenceError: setTimeout is not defined, what I am going to reach here is I want to call a function in non-blocking way using setTimeout(). Maybe one of you has met this issue before or you may have a solution/alternative for me.

  • setTimeout is not part of ECMAScript so it is possible that a framework does not supply it. Try with window.setTimeout() (the difference: global and local timeout).
    – Rinzwind
    Jul 7, 2020 at 9:26
  • this._timeout = Mainloop.timeout_add_seconds(10, Lang.bind(this, this.{function})); works as a timeout to {function}.
    – Rinzwind
    Jul 7, 2020 at 9:59
  • It works, of course with const Mainloop = imports.mainloop; at the top. Thanks for the help.
    – fsevenm
    Jul 8, 2020 at 6:28
  • make it an answer :)
    – Rinzwind
    Jul 8, 2020 at 7:57

1 Answer 1


Just to capture this in an answer:

const Mainloop = imports.mainloop;


Mainloop.timeout_add(1000, () => log('one second later!'));

As seen here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.