In order to eliminate the security threat to HTML5 applications posed by debugging JavaScript code during attack process, a method of protecting JavaScript code through anti-debugging was proposed. The JavaScript debugging principle on Firefox and Chrome was analyzed, and the runtime features introduced by these mainstream browsers’ debuggers were explored. Then combined with these features and some penalties to the debugging behavior, some anti-debugging approaches were devised and applied to achieve anti-debugging protection on Web applications. The experiments showed that these anti-debugging approaches can effectively protect Web applications from being debugged dynamically without much overhead.