简体   繁体   English

如何在Google脚本的HtmlService中调试JavaScript

[英]How to go about debugging JavaScript in the HtmlService in Google Scripts

I can't find syntax errors in my JavaScript that is in the Google HTMLService (html window in Google Scripts). 我在Google HTMLService(Google脚本中的html窗口)中的JavaScript中找不到语法错误。 My work involves Google Visualizations which requires this. 我的工作涉及Google Visualizations,这需要这样做。 It is my first experience with JavaScript and HTML so I'm quite prone to mistakes making this a distressing problem. 这是我第一次使用JavaScript和HTML,因此我很容易出错,使这成为一个令人困扰的问题。

The execution log just shows that the html was run, and I don't where in my code to look for errors. 执行日志仅显示html已运行,并且我不在代码中查找错误的位置。 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. 我希望某个地方会说“错误:第x行”或“对象不接受第y行”,但我只是不知道在哪里看。

I would appreciate any pointers on where to find a solution or how to clarify my question. 对于在哪里找到解决方案或如何阐明我的问题的任何指示,我将不胜感激。

Thank you for you time. 谢谢您的时间。

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: 在Chrome中,按f12按钮,或选择更多工具开发人员工具 ,然后将在浏览器中打开如下所示的窗口:

开发者工具

One of the tabs is labeled Console . 选项卡之一标记为Console You can print information to the console by using a: 您可以使用以下方法将信息打印到控制台:

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

statement. 声明。

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. 当Apps脚本宏运行并将HTML提供给您的浏览器时,如果有错误,它们将显示在控制台日志中。

I used the HTML you posted, and got msgs in the console of this: 我使用了您发布的HTML,并在其控制台中获得了msgs:

HTML错误

So, for the JavaScript in a <script> tag of the HTML, you don't look for errors in the Apps Script code editor. 因此,对于HTML的<script>标记中的JavaScript,您无需在Apps脚本代码编辑器中查找错误。 You need to use the browsers Developer Tools. 您需要使用浏览器开发人员工具。 The JavaScript in a .gs code file is server side code. .gs代码文件中的JavaScript是服务器端代码。 It runs on Google's servers. 它运行在Google的服务器上。 The JavaScript in an HTML tag runs in the users browser on the users computer. HTML标记中的JavaScript在用户计算机上的用户浏览器中运行。

You can also step through client side JavaScript code in your browser. 您也可以在浏览器中逐步浏览客户端JavaScript代码。

One problem is, that when the HTML is served, Caja re-writes code. 一个问题是,当提供HTML时,Caja重新编写代码。

Apps Script Restrictions Apps脚本限制

So the JavaScript in your Apps Script code editor will not look the same as what gets served to the browser. 因此,您的Apps脚本代码编辑器中的JavaScript与提供给浏览器的JavaScript外观不同。 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. 如果您查看向浏览器提供的JavaScript,则其外观将与原始文件中Script标记中的代码完全不同。

You could also use a code editor that has error checking in it. 您还可以使用其中包含错误检查的代码编辑器。 Net Beans has a free code editor. Net Beans具有免费的代码编辑器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过HTMLService(Google App脚本)将电子表格数据获取到客户端数组中 - How to get Spreadsheet Data into clientside array via HTMLService (Google App Scripts) 如何使用htmlservice和javascript在组合框中动态添加选项 - How to add options dynamically in a combobox with htmlservice and javascript Google HtmlService 的切换按钮 - ToggleButton for Google HtmlService 如何在Google appScripts的HtmlService.SandboxMode.IFRAME中设置iframe属性 - How to set iframe attributes in Google appScripts' HtmlService.SandboxMode.IFRAME 如何在 HTMLService/Google Script/Sheet 中使用日期选择器返回值? - How to return a value using Date picker in HTMLService / Google Script / Sheet? 如何使用HtmlService将值从Google电子表格检索到文本字段 - How to retrieve values from a google spreadsheet to a textfield using HtmlService 如何调试通过 HtmlService 提供的 Javascript? - How do I debug Javascript served through HtmlService? 如何使用Google Web Toolkit或Javascript解析HTML来查找图像元素及其链接? - Using the Google Web Toolkit or Javascript how do I go about parsing HTML to find an image element and its link? 谷歌HtmlService和knockout.js - Google HtmlService and knockout.js Internet Explorer中的JavaScript调试(页面上的所有脚本) - JavaScript debugging in Internet Explorer (all scripts on page)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM