CardService.OnClose.RELOAD_ADD_ON works intermittently - gmail-addons

I have CardService.newOpenLink() in my add-on that does authentication from our web site. Upon return I am using HtmlService.createHtmlOutputFromFile() to pass self-closing file that is closing pop-up with authentication code. Everything works.
The issue I an having - I am using setOnClose(CardService.OnClose.RELOAD_ADD_ON) with my open link, so I can reload add-on and re-read cached credentials. This works intermittently - sometimes add-on is reloaded and sometimes it stays on a current card. I cannot catch the pattern... Any suggestions on what could be the issue?
Thanks,
Sam

It appears that this is some kind of timing issue. The way my flow works - I open external HTML window, which is reloading itself with URL pointing back to my script. Script is using HtmlService to pass back simple page that will close itself. If I put window.close() inside setTimeout() - then Add-On will reload reliably if timeout is 5 sec. or more. Anything less than 2 sec will not reload at all. 2 to 5 sec will work intermittently. Not sure what Google is doing there, but apparently they are loosing handle to a window...

Related

Google analytics hit returns 302 and second request wont work

So basically the first hit is returning 302 and the user agent (in this case my web browser) is invited to send the SAME hit again to another url but this time even when im getting a 200 the hit is sent incorrectly because lots of the params are not being send. (This happens sometimes not always)
First Hit:
Second Hit:
To clarify a little more im getting this problem with an addToCart (EE) and its causing me to products sales without being added to cart. I checked the dataLayer and everything seems to be ok.
So im in doubt if its a problem with my web browser or its a problem with analytics?
If version of the web browser are needed you can read it on the user-agent of the images.
I had the same issue when I tried to manually insert the google analytics tracking code(gtag) in my .
First step was to remove the Google analytics code from the header. I had used the plugin 'Insert Headers and Footers'.
Afterwards I installed Insights Monster plugin, went through the launch wizard and the 302 redirect disappeared.
I didn't really want to use a heavy plugin to resolve this issue but unfortunately it was the only solution for me.
I copied and answer from here: https://tonnygaric.com/blog/prevent-google-analytics-from-making-requests-to-stats-g-doubleclick-net you need to do a configuration in Google Analytics dashboard.
The answer is pretty simple. Go to GA -> Admin -> Tracking info -> Data Collection -> disable both toggles and click on save. It can take up to 24 hours for the changes to take effect.

Launch Chrome with JS scripts suspended at startup

In NodeJS, you can run a script with the --debug-brk option, which pauses your script at the first line. You can then attach with a debugger and resume, ensuring you can hit any breakpoint no matter how early it is in your script.
Is there something similar in Chrome / Chrome Debugging Protocol?
I use an external debugger to debug JS in Chrome. Chrome is launched via command-line, with remote debugging enabled, pointing to a local server with my website / app. Once Chrome is launched, the debugger attaches to the page, but that takes time - by the time the debugger is attached, the scripts have pretty much already executed, meaning I cannot hit breakpoints that are early in the website / app's life cycle.
I thought of adding debugger; statements at the beginning of every script, but that would be annoying over time. I also think that the Chrome dev tools need to be open for debugger; statements to actually pause, so that might not even work.
In Chrome DevTools, you can use 'Event Listener Breakpoints' to force the execution to pause on 'Script First Statement'. There are others, such as load, which happens a little later on. You can then resume execution until the relevant breakpoints should be hit.

Why is Chrome calling the autocompleted url before validation?

I'm using an API on my website to send emails to the users and while testing my call I noticed I was receiving the email twice.
So the url looks like "localhost/api/sendEmail" and, at least on Chrome, when I'm on localhost and I start typing "/ap" the url is automatically completed.
And I can see on Fiddler that Chrome (well I think that's him) is actually calling it before I press Enter so the mail is sent, and when I press Enter it is of course sent a second time.
This is not a problem since it won't be directly callable by the end-user, but I was just wondering what is the purpose of this first call ? Is Chrome pre-calling the page to make it faster to load ? Can it cause problems in different situations? Can one prevent Chrome from behaving like this?
Again, not a problem at all, but I'm just wondering.
This is Google's prefetch feature, which loads the page quicker, assuming you execute the auto-completed URL.
You can disable this option in Google Chrome:
Settings > Advanced Settings > Privacy: (uncheck) Prefetch resources..
Update 2019
I came across a similar question on superuser, which I provided an updated answer for.
Disable page load prediction service
chrome://settings/ -> expand Advanced section
Disable NoState Prefetch
chrome://flags -> search for "nostate"

Windows .net Google.Apis hangs on the call to InsertMediaUpload.Upload -- there is no timeout

I am using GoogleApis to upload documents to Google Drive using the InsertMediaUpload class from the FilesResource namespace and the Upload method. It is working well for me with the following exception:
After calling InsertMediaUpload, a browser window appears asking the user to log into their Google (usually Gmail) account. If the user simply closes the browser window instead of clicking on "Accept" or "Cancel" then the current process appears to be hung. I suppose there should a timeout of a minute or two so that if the user opts to not log in the current windows application will not simply hang and stop working indefinitely.
There is no need for sample code here. What should happen when the user simply closes the browser window instead of clicking cancel if they are no longer interested in uploading a document? Crashing (or hanging) the current process should not be a possibility, but that is what occurs. One would hope closing the browser window would have the same effect as clicking the cancel button -- just another way of opting out of an upload to Google Drive, right?
Thanks in advance for any help with this.
You're not supposed to get authentication message from InsertMediaUpload class. You should handle authentication by yourself. Authentication browser window you get is for your development convenience, not for production code. Please take a look at .net quickstart. In this quickstart, you'll see GetAuthorization method which handles authentication. Modify this method on your needs and you'll get what you want.

Chrome is accessing links in webpages that were not clicked

I spent the day debugging my website, because I seem to be getting randomly logged out, but just on Chrome on Android.
After reviewing the server logs, I see requests from my Android tablets IP hitting my server for links that I never clicked on. After some experimentation I see every couple of links I click, Chrome will fetch another link at random in the page that was not clicked.
The issue is that there is an a link in the page with an href="logout" which will sign in, and Chrome calls this all on its own, disconnecting the session. I suppose if I changed the link to call a POST operation Google would not fetch it, but I can't see why Google would be fetching links that were not clicked.
This is very odd, and does not occur on Firefox, or Chrome on Windows.
Not sure if this is some sort of virus on the tablet, or some thing Google is doing to check the content of pages that it would not have access to without the session.
I have seen Google do this before, but only when there were Google ads in the page, then Google would fetch the links twice so that it could get the page content to choose the ad. This seems a huge privacy issue, as Chrome is fetching private data from the session.
So the issue is that Chrome is using a new feature "prefetching".
This is a "feature" that will have Chrome randomly fetch any linked URL from the page.
This seems like a very error prone "feature" for Chrome to enable by default. Seems like it could give the user cached or stale data, or change the server's state causing obscure difficult to debug issues. This will also use double the amount of the user's data (and server's CPU), which you would think would not be desirable to most users that pay for their data.
I confirmed this by disabling the feature in Chrome.
My solution was to switch the logout call to use a POST through a element.
See, https://www.technipages.com/google-chrome-prefetch