如何在Google Scripts中的HtmlService中调试JavaScript [英] How to go about debugging JavaScript in the HtmlService in Google Scripts

查看:243
本文介绍了如何在Google Scripts中的HtmlService中调试JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google HTMLService(Google Scripts中的html窗口)中的JavaScript中找不到语法错误。我的工作涉及Google Visualizations,需要这样做。这是我第一次使用JavaScript和HTML,所以我很容易出错,这使得这个问题很麻烦。

I can't find syntax errors in my JavaScript that is in the Google HTMLService (html window in Google Scripts). My work involves Google Visualizations which requires this. It is my first experience with JavaScript and HTML so I'm quite prone to mistakes making this a distressing problem.

执行日志只显示html已经运行,并且我不在我的代码中寻找错误的地方。我希望某个地方会说错误输入:第x行或对象不被接受行y,但我只是不知道在哪里看。

The execution log just shows that the html was run, and I don't where in my code to look for errors. I expect that somewhere would say "error in: line x" or "object not accepted line y" but I just don't know where to look.

我会很感激关于在哪里找到解决方案或如何澄清我的问题的任何指示。

I would appreciate any pointers on where to find a solution or how to clarify my question.

谢谢你的时间。

推荐答案

你可以用你的浏览器的开发人员工具。在Chrome中,按f12按钮,或者选择更多工具开发人员工具,将在浏览器中打开如下所示的窗口:

You can use your browser's Developers Tools. In Chrome, press the f12 button, OR choose More Tools, Developer Tools, and window will open in your browser that looks like this:

其中一个标签标记为控制台。您可以使用以下命令将信息打印到控制台:

One of the tabs is labeled Console. You can print information to the console by using a:

console.log('This is text: ' + myVariable);

声明。

当Apps脚本宏运行,并将HTML提供给您的浏览器,如果有错误,它们将显示在控制台日志中。

When the Apps Script macro runs, and serves the HTML to your browser, if there are errors, they will be displayed in the Console Log.

我使用了您发布的HTML,并获得了msgs在这个控制台中:

I used the HTML you posted, and got msgs in the console of this:

因此,对于HTML的< script> 标记中的JavaScript,您不会查找错误在Apps脚本代码编辑器中。您需要使用浏览器开发人员工具。 .gs代码文件中的JavaScript是服务器端代码。它在Google的服务器上运行。 HTML标记中的JavaScript在用户计算机上的用户浏览器中运行。

So, for the JavaScript in a <script> tag of the HTML, you don't look for errors in the Apps Script code editor. You need to use the browsers Developer Tools. The JavaScript in a .gs code file is server side code. It runs on Google's servers. The JavaScript in an HTML tag runs in the users browser on the users computer.

您还可以在浏览器中单步执行客户端JavaScript代码。

You can also step through client side JavaScript code in your browser.

一个问题是,当提供HTML时,Caja会重写代码。

One problem is, that when the HTML is served, Caja re-writes code.

Apps脚本限制

因此,您的Apps脚本代码编辑器中的JavaScript与提供给浏览器的JavaScript看起来不一样。如果您查看提供给浏览器的JavaScript,它看起来将与原始文件中Script标记中的代码完全不同。

So the JavaScript in your Apps Script code editor will not look the same as what gets served to the browser. If you view the JavaScript served to the browser, it will look totally different than the code in the Script tag in the original file.

您还可以使用在其中进行错误检查的代码编辑器。 Net Beans有一个免费的代码编辑器。

You could also use a code editor that has error checking in it. Net Beans has a free code editor.

这篇关于如何在Google Scripts中的HtmlService中调试JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆