Embedding Google Apps Script in an iFrame Error - google-apps-script

I'm trying to load a web app into an iframe in an external html file. I've built and tested the app and it works fine, stand alone. But when I load it into an iframe i get the following error..
"Exception: No HTML file named WebAppBoot was found. (line 2, file "Code")"
I modified the Code.gs to set the XFrameOptionsMode to allow all, like so...
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('WebAppBoot');
output.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
I still get the same error
I used this tutorial as the starting point for my web app.. Bootstrap Google Web Application Form Take a look at it to see the file structure in the google "Project", its exactly the same as my web app

Remove the ; of line 2, and output from line 3
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('WebAppBoot')
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
then publish again your web app creating a new version (on the version dropdown, select New)
Every time that you made a change to your code that want to see on the /exec web app URL you have to publish again your web creating a new version.

try this:
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('WebAppBoot');
output.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}

Related

suddenly I get the error: Cannot find method setMimeType((class)) without any change

Suddenly my script get the error:
Cannot find method setMimeType((class)) (line xxx, file "Code")
It worked well for years, until this afternoon. I didn't modified it at all.
What I've done after:
copied this code from google documentation:
function doGet() {
var feed = UrlFetchApp.fetch('http://xkcd.com/rss.xml').getContentText();
feed = feed.replace(
/(<img.*?alt="(.*?)".*?>)/g,
'$1' + new Array(10).join('<br />') + '$2');
return ContentService.createTextOutput(feed)
.setMimeType(ContentService.MimeType.RSS);
}
pasted it into a new script
given it the proper authorizations
run it
It was ok.
Then:
renamed the doGet() function into doGet1() in my broken script
pasted the example doGet() function code
run my script (doGet function)
I obtained the same error:
Cannot find method setMimeType((class)) (line xxx, file "Code")
What could have happened?
i just had the same error. my script stopped working.
it looks like the "ContentService.MimeType.RSS" does no longer exist.
"RSS" is no longer an autocomplete option if you type that.
i changed it to the "ContentService.MimeType.TEXT".
it is the closest option.
i also had to make a new deployment after saving the new code.
now my script is working again.
Trying to debug my script, a message informed me that my project uses an old Apps Script runtime, and that in order to execute debug I have to upgrade to Javascript V8 engine. After doing that, everything went back to normal.
I attach a screenshot (from a different script, in Italian language).

GetURL returns wrong URL

I have a Google App Script program that has a number of HTML pages. To generate the URL's for links to individual pages, I use this function on the server code:
function getScriptUrl() {
var url = ScriptApp.getService().getUrl();
return url;
}
to return a URL that I could then embed like this, on the client side:
<?var myURL = getScriptUrl();?><a class="btn btn-success" href='<?=myURL?>?page=CreateNew'>My Button/a>
This always returned the URL of the app. So, if am testing in the Dev version, it returns the Dev URL, if I am in the Exe version, it returns the Exe URL. But, now, if I am in the Dev version, it returns the Exe URL. This was never an issue in the past but started today. Does anyone know why this is happening or a better way to generate the URL to create links between pages?
EDIT:
I have tried to republish the app (in Legacy Editor and the New Editor), log out of G Suite account, clear my cache but these attempts did not work to address the issue.
This should a Google part issue, I use the same logic to auto direct to prod and test page. It works fine in the passed few month. But it can't work from last week.
I too have this problem. Until recently I had this code to help me distinguish whether I was testing the development version or the deployed version. It worked for months.
const url = ScriptApp.getService().getUrl();
if (url.endsWith('dev')) {
// more code here
}
Now getUrl() will always return the exec url.
(I know this isn't an answer, but I am a first time poster and do not have enough points to "Add a comment" and I don't want to ask a duplicate question)

GMail Google Apps Script Plugin "The value returned from Apps Script has a type that cannot be used by the add-ons platform"

In the last 24 hours, a previously working GMail plugin I run has started failing.
I stripped it all the way down to only trying to get the example from the docs working:
var action = CardService.newAction().setFunctionName('composeEmailCallback');
CardService.newTextButton()
.setText('Compose Email')
.setComposeAction(action, CardService.ComposedEmailType.REPLY_AS_DRAFT);
// ...
function composeEmailCallback() {
var thread = GmailApp.getThreadById(e.threadId);
var draft = thread.createDraftReply('This is a reply');
return CardService.newComposeActionResponseBuilder()
.setGmailDraft(draft)
.build();
}
On BUILD (not on button press), the previously working GMail Addon displays the error message:
The value returned from Apps Script has a type that cannot be used by the add-ons platform. Also make sure to call build on any builder before returning it. Value: values {
proto_value {
type_url: "type.googleapis.com/caribou.api.proto.addons.templates.publicapi.ContextualAddOnMarkup.Card"
value: "...(omitted)"
}
}
Is this a new, known issue? Does anyone have some troubleshooting steps to share?
For me the error was was caused by open links not being whitelisted. For example, if you have code like this:
CardService.newOpenLink().setUrl(url)
Then the link returned by 'url' has to be whitelisted in the appscript manifest's openLinkUrlPrefixes list, like so:
"openLinkUrlPrefixes": [
"https://*.example.com"
]
This problem is caused by Google's silent upgrading of Apps Script to the V8 Runtime. To downgrade from this runtime to the old runtime (Rhino), perform this set of actions:
Run -> Disable New Apps Script runtime powered by Chrome V8
A related issue can be found here.

Basic UiApp failing with error "ReferenceError: "UIApp" is not defined."

I am creating some google app scripts for my company to use to generate random tests for employee training. I already have the basic scripts written to grab a list of questions from a google sheet, randomize them, grab the first 10 questions, etc. That all works fine. I decided it might be better to re-do the whole thing using a UiApp instead of just separate scripts. That is where the problem comes in. I did a simple bare bones UiApp to test with, published it and tried to hit the URL and that's where I encounter this error. I searched for this error and all I could find was some discussion about this being part of google apps premiere(which should have been folded into regular google apps around 2010). I've been staring at this so long I've frustrated myself. It should be something very simple and yet it's refusing to work. I'm assuming I am doing something wrong at a basic level but I've reached the point where my brain refuses to see it.
Here is the basic script I started with:
function doGet(e) {
var app = UiApp.createApplication();
var mainPanel = app.createVerticalPanel().setId('mainPanel');
mainPanel.add(app.createLabel('test'));
return app;
}
I save it, publish it and go to the URL and that's when I get the above error message. I know it's something simple but I've reached the point of frustration and simply can't see it.
Update: to reflect comments
Another possibility for WebApps not updating is not publishing a new version and only checking the exec URL. For instant changes to the code, always check the dev URL. The exec will only change after saving a version in Manage Versions and re-publishing the app.
First Answer:
I think your question title says it all.
UIApp is not defined, but Class is UiApp. JS is case sensitive. I copied and pasted the code exactly as it is in your question and received no errors. I did have to add one line to make the label show up.
function doGet(e) {
var app = UiApp.createApplication();
var mainPanel = app.createVerticalPanel().setId('mainPanel');
mainPanel.add(app.createLabel('test'));
app.add(mainPanel); // <-- I added this line to see the label
return app;
}

dynamically loading data from JSON in Google App Script on Sites

I have a google app script where I am trying to get data from a JSON call:
var ajaxError = function(){
$loadingItem.text('Could not load examples :(');
};
// dynamically load sites using Masonry from Zootool
$.getJSON('http://zootool.com/api/users/items/?username=desandro' +
'&apikey=8b604e5d4841c2cd976241dd90d319d7' +
'&tag=bestofmasonry&callback=?')
.error( ajaxError() )
.success(function( data ){...
Basically I am trying to implement this JQuery plugin example http://masonry.desandro.com/
in a Google Apps script returning Html from a file.
This Jason call ends up in error... but why? where can I see what is going wrong? Javascript console is not displaying any error. The URL works: http://zootool.com/api/users/items/?username=desandro&apikey=8b604e5d4841c2cd976241dd90d319d7&tag=bestofmasonry&callback=?