Recently I learned that it's possible to show JavaScript code added to the DOM / Dev Tools Elements tab by using document.write
, eval
, etc. to the Source panel of Chrome Dev Tools and other browsers. This is done by adding a comment before the closing <script>
:
<script>
...
//# sourceURL=filename.js
</script>
I tried to apply this but the comment is not added by the HtmlService to browser. How can the Google Apps Script client-side code be shown in the Dev Tools Sources panel?
Below is my attempt of adding sourceURL
as shown above
Code.gs
function doGet(e) {
return HtmlService.createHtmlOutput()
.append(`
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<form>
<input type="text" name="something" value="default value"><br>
<button type="submit">Submit</button>
</form>
<script>
function formSubmitHandler(){
google.script.run.doSomething(event.currentTarget)
}
//# sourceURL=javascript.js
</script>
</body>
</html>
`)
.setTitle('Demo')
.addMetaTag('viewport', 'width=device-width, initial-scale=1');
}
function doSomething(formData){
console.log(JSON.stringify(formData.something));
}
Related
- How to go about debugging JavaScript in the HtmlService in Google Scripts. Not a duplicate because the OP didn't included a MCVE, doesn't mention how the
HtmlOutput
was created. The most common case is to useHtmlService.createHtmlOutpuFromFile(filename)
but in this case I'm usingHtmlService.createHtmlOutput().append(string)
. - When minifying javascript, //@ sourceUrl is removed. Not a duplicate because in Google Apps Script HtmlService do not minimize the code.
- https://stackoverflow.com/a/13129905/1595451. Not a duplicate because the JavaScript code is added using jQuery and in this case the code is added by using the Google Apps Script HtmlService
References