Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrome's console value preview functionality spams the console commands #140

Open
benjameep opened this issue Dec 4, 2018 · 4 comments
Open

Comments

@benjameep
Copy link

Chrome recently added a value preview to their auto-completion.

So when typing the word help it auto-completes the word. And trying to preview the resulting value. Which calls the .toString method, spamming that function every-time you try to finish typing help

Is it possible detect who is calling the function, or use getters to only run the .toString function once enter is pressed?

@konklone
Copy link
Member

konklone commented Dec 4, 2018

Oh that is interesting! I can reproduce it easily. I am less sure how to fix it. But I will definitely look into this for this year.

@benjameep
Copy link
Author

Could you do something like replacing

var say = function(){ 
   emit('chat', {message: message});
}

say.toString = function(){
   say(prompt("What do you want to say?"));
   return " ";
}

with

Object.defineProperty(window,'say',{
   value:function(){
      emit('chat', {message: message});
   },
   get:function(){
      this(prompt("What do you want to say?"));
   }
})

Because Chrome is a lot more careful about firing getters and setters

@konklone
Copy link
Member

Hmm, this looks promising, though is new syntax to me. But I tried adapting the code to use it, and got this error:

(index):935 Uncaught TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #<Object>
    at Function.defineProperty (<anonymous>)
    at (index):935

That's with this code:

    Object.defineProperty(window,'say',{
       value:function(){
          if (!message) return;
          if (user.live.chat != "true") return;
          message = message.toString();

          said = true;
          emit('chat', {message: message});
          return blank();
       },

       // run without parens to use a popup dialog
       get:function(){
          this(prompt("What do you want to say?"));
          return " ";
       }
    })

@konklone
Copy link
Member

For now, I've updated the site to remove all of the ()-less methods, and it now requires parens for all of them. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants