I've published a private sheets addon for my company, but unfortunately when I try to run it both onInstall and onOpen fail with no execution logs and a 0s execution time in the Apps Script Console. It works fine from the sheet associated with the script project, just not from anywhere else. All I have to go on is an error in the chrome console:
Google Apps Script: We're sorry, a server error occurred while reading from storage. Error code PERMISSION_DENIED.
Here are the relevant functions:
function onInstall(e) {
onOpen(e);
Logger.log("Installed")
// Perform additional setup as needed.
}
function onOpen(e) {
Logger.log("Opening...")
var ui = SpreadsheetApp.getUi();
ui.createAddonMenu()
.addItem("Launch", "run")
.addToUi()
Logger.log("Added menu items")
}
None of the logger messages are actually logged, making me think that the function is never being launched despite the execution showing up in the console.
Any tips on how to debug/track down the error would be greatly appreciated!
Edit: I've also tried testing it via the script editor with AuthMode.NONE and AuthMode.LIMITED. Both work fine. I only encounter the error when running after installing via the GSuite Marketplace.
Here is the manifest.json:
{
"timeZone": "America/New_York",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
It appears to be working now. I changed the timeZone in manifest.json to America/Los_Angeles (my local tz) and re-published and all errors are gone. Not sure if this change is what made the difference or not, but thanks to Aerials for the nudge to look there.
Edit: This may also have been related to my use of clasp deployments. The problem recurred for me after modifying the script. I created a new deployment via the script editor UI (Publish -> Publish from manifest) and then clicked the "install addon" next to the new version. I also updated the Gsuite marketplace listing to point at the new version, and everything seems to be working.
Related
I'm trying to implement the onEdit(e) simple trigger of Google Sheets. Everytime I try execute even a simple function such as:
function onEdit(e){
Logger.log(e.oldValue);
}
I get the following error:
My step by step:
I've tried following these two videos with no success:
https://www.youtube.com/watch?v=eWn_JxPSbds
https://www.youtube.com/watch?v=L1_nIhiVc5M
EDIT: SOLUTION
Thanks to #JPV and #TheMaster for the two potential solutions:
I was viewing the "Logs" and not the "Stackdriver Logging".
It seems you need to disable the V8 to view it in Logs, but need the Stackdriver Logging to view it with V8.
At least that seems to be the case with me
EDIT TWO
Here's the documentation where the issue is addressed:
https://developers.google.com/apps-script/guides/v8-runtime#ui_changes_for_logging
"If your script uses the Rhino runtime, selecting View > Logs in the Apps Script editor only shows you recent logs written by the Logger service. You must select View > Stackdriver Logging to see logs written with the console class."
Nothing is wrong with V8. That error is because you ran the script directly by clicking run button before. That caused the error and was logged. When you edit, it is logged to view>stackdriver logging. But the previous error is shown to you. You're looking at old logs.
As per the official documentation,
For scripts using the V8 runtime, the script editor View > Logs menu item shows both Logger and console results for the most recent execution in the current session
Only current session logs is available to View>Logs. To access previous session logs or logs logged not by running a function directly in the current session, use View > Stackdriver Logging
....
This seems to be a glitch in the new V8 engine. Disabling V8 should fix it. Let's hope this will be fixed soon.
Very simply, I would like to disable the display of the repeated workbox messages that appear in my browser console while I am debugging. For instance, I don't need to see:
WorkBox: Using NetworkFirst to respond to '/fonts/KFOlCnqEu92Fr1MmEU9fBBc-.woff'
It clutters my FireFox console and it is something I dislike very much. If you like it, fine, please don't try to change my mind about the benefit of such useless (to me) messages.
Do you know how to turn it off?
For info sake, I am using Quasar and Vue to create a SPA - not even a PWA.
Thanks.
Simply add self.__WB_DISABLE_DEV_LOGS = true at the top of your service worker (sw.js) file.
Contrarily to what answers posted here say, the solution is not:
to unregister your service worker to get rid of the messages. Your app may need it to run properly
to add workbox.setConfig({debug: false}) unless knowing what it does:
it switches between a production build and a debug build. workbox automatically selects the debug build when running on localhost.
For me worked:
Console -> Application tab -> Service workers -> sw.js unregister
You can use workbox.setConfig({ debug: false }); in order to use production build and remove extra logging, otherwise adjust your web console log level filtering accordingly.
Doc : https://developers.google.com/web/tools/workbox/guides/troubleshoot-and-debug
You add this setting in your service worker definition file, after the import. For example:
importScripts(`https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js`);
if (workbox) {
console.log(`Yay! Workbox is loaded 😁`);
} else {
console.log(`Boo! Workbox didn't load 😬`);
}
// Switch debug logging on/off here. Default is on in dev and off in prod.
workbox.setConfig({debug: false});
For more information on this see https://developers.google.com/web/tools/workbox/guides/configure-workbox#configure_debug_builds_vs_production_builds
Thanks to the answer provided by Antonina K, I was able to locate an answer for FireFox. In case anyone else needs this. As Antonina mentioned, in Chrome, the console has an application tab that has references to all the service workers used by the browser. FireFox does not have the tab (or, at least my version does not).
In FireFox, open a new tab and place about:serviceworkers in the address bar. Scroll through the list to find the workbox service worker. For me, it was listed as localhost:8080. I deregistered that worker and I no longer see the multitude of workbox messages in my console. I can finally debug my app again!
Here is the link that I referenced to fix the problem:
Manage Service Workers in FireFox and Chrome
I'm trying to create an add-on for Google Sheets. When the sheet is opened, the script should create a menu item in Add-ons.
The item is added and works when I open the Sheet it's originally bound to. When trying to test it as an add-on with onOpen as a declared function in my script, it always results in the item not being added and an error being logged in the Google Chrome DevTools console for the Sheet opened for the test:
Google Apps Script: We're sorry, a server error occurred. Please wait a bit and
try again.
This error doesn't occur if I comment out the onOpen method.
I've tried running it as an add-on in the following ways with both Auth.none and Auth.limited:
The original copy of the script attached to its original Sheet.
The original copy of the script running with a separate Sheet.
A copy of the script in a separate Google Scripts file running with a different Sheet.
Creating a new Sheet and bounded script with just an empty onOpen function.
These all result in the error above, and when I uncomment the contents of onOpen functions that do have code, none of their code appears to run.
Here's the original copy's code but keep in mind I still get the error even if the contents are commented out and this states that even if createMenu is used for an add-on, it's handled correctly by Google App Script:
function onOpen(e){
var menu = SpreadsheetApp.getUi().createAddonMenu(); // Or DocumentApp or FormApp.
if (e && e.authMode == ScriptApp.AuthMode.NONE) {
// Add a normal menu item (works in all authorization modes).
menu.addItem("Show Sidebar", "showSidebar");
menu.addToUi();
} else {
// Add a new menu (doesn't work in AuthMode.NONE).
var topUI = SpreadsheetApp.getUi();
topUI.createMenu("Mail Merge")
.addItem("Show Sidebar", "showSidebar")
.addToUi();
}
}
The Logger object also doesn't seem to log my messages while running the script as an add-on.
Copying the Sheet over to another account and just having it be owned by that account (not in a team drive) did allow the menu to appear when testing it as an add-on with both types of authorization. The Google App Script error also stopped occurring after doing this.
The most closely related information I could find about Team Drive restrictions was this, which says it limits cloud platform interaction. But this link is Google's page on setting up and running Test As Add-on and it doesn't state anything about the Team Drive or cloud platform.
I've given the docs a good looking over as well as SO, however can't seem to find any answers.
I have a packaged chrome app (new style, not legacy)
I can find many documents on enabling logging as in errors/crash reports, but can't find anything about custom logging. For example:
On initial load some 3rd party data is loaded via a api call, lets just assume it:
$http.get('/api/get-my-data').onSuccess(function(data){
// Yay, I gotz the dataz. Do something
}).onFail(function(error) {
// Damn son, something went wrong.
});
In the above pseudo code I'd like add to a chrome error/custom log to record the onFail condition. I'm not looking to record error in the sense that the app has crashed or a fatal error, I'm looking to log events that in the context of the app running correctly I regard as errors.
If an error caused the app to crash etc then I'd get a entry in the chrome logs, but there must (I assume) be away to log data directly to a log on the server that isn't considered an error (perfectly common if this was a web app on a server (log4j, KLogger, Morgan)) but I can't find it
Anyone else created a chrome packaged add and used the inbuilt logging?
Thanks
N.B. Just to be clear, we are talking about logging in a packaged app with javascript to a log file, not console.log
Thought I'd answer this incase someone else comes across it as it's not clear form the google docs.
when you use console.log it gets sent to your strdout/chrome log file.
You have to enable logging in your chrome app launch config/flags, then any console.log in your code will show up where ever you set your user-dir to be.
It's not clear from the documentation, but basically your chrome app will automatically log and console.log you have
This includes other console methods.
I have a weird problem where after around 30+ seconds after a local html page has finished loading, calling the google AutocompleteService or PlacesService javascript function does not send out a request to do the lookup. But if less than 30 seconds it works fine. I can even do multiple successful calls if within that time.
Background:
We have a C# dll that is used by a VB6 app that runs as a Windows service. The dll is used to do autocomplete and other places API lookups through the Javascript API.
Due to the asynchronous nature of the google lookups, the WebBrowser control lives in its own thread with its own message loop eg.
thrd = new Thread(new ThreadStart(
delegate
{
Init(false);
System.Windows.Forms.Application.Run(this);
}));
// set thread to STA state before starting
thrd.SetApartmentState(ApartmentState.STA);
thrd.Start();
This is all setup once as part of the startup process of the service.
This dll works fine elsewhere which includes apps running in IIS and on the desktop.
Troubleshooting:
I confirmed that the browser thread stays alive on subsequent lookup calls from the windows service.
Through debugging, i can see that the javascript function (below) is being run (i can see the debug outputs) with no errors thrown. However, the google call, autocomplete.getPlacePredictions, does not send anything out (our network guy was monitoring the traffic while i did the lookup)
Example of the javascript function:
function doAutoComplete(waitKey, searchString, latBias, longBias, radiusBias, components, typesFilter) {
//Removed irrelevant code to keep it brief
//debug output here
autocomplete.getPlacePredictions(options, function (waitKey) {
return (function (predictions, status) {
window.external.setResult(waitKey, status, JSON.stringify(predictions));
});
} (waitKey));
//debug output here
}
The service does not have the issue when installed to a windows 7 machine. So at this stage the issue only happens in a Windows 2012 Server machine.
I have run out of ideas as to what could be causing the google call to not work.
Any help or ideas will be greatly appreciated.
Edit history:
Added #3 to Troubleshooting.
I have sorted it out.
The issue was that the IE enchanced security configuration (IE ESC) was internally blocking/disabling the call to Google. Turning it off prevents the issue from happening but i will look further into tweaking it rather than turning it off.
What is annoying is that it was doing it silently so was hard to track down. I believe the issue only happened when running as a windows service because of the different security levels used for it versus running from the desktop or IIS.