save state chrome extension with event pages - google-chrome

I have a Chrome extension I am working on that queries a remote server and shows a desktop notification when it changes. I am using an event page which will frequently go to sleep so I use a Google Alarm to have it do a check every 5 minutes. I save the last state out into a variable and compare it to current state to determine if a desktop notification should be displayed. I'm finding this last state variable is frequently going undefined when chrome is not in the foreground or under other conditions. I have a few variables this may be happening to as well.
How do I prevent this from happening?

Related

How do I start a DevTools user flow recording from a dynamic URL?

Google recently released their DevTools user flow recorder and it seems like an interesting and easy-to-use tool. One limitation I'm running into is that replaying a recording will always bring you to the page you initiated the recording on. For example, if I create and save a recording on this array processing question then navigate to this git question, running the recording on the latter will redirect me back to the former. I would like to be able to make a recording, then kick it off from whatever page I'm currently viewing. So far, I've tried both removing the URL from the initial step and replacing the initial URL with a JS IIFE that gets the current URL; neither of these have worked.

What happens after resuming from a tombstoned state?

When the user resumes an app that was tombstoned, does it start on the main app page and you have to handle with saved states to check where was the user and send him there again, or does it open directly the page where the user was and all you have to do is to restore your variables and date from the saved state?
Tombstoned
A tombstoned app has been terminated, but the operating system preserves information about its navigation state and also preserves the state dictionaries the app populated during Deactivated. The device will maintain tombstoning information for up to five apps at a time. If an app is tombstoned and the user navigates back to the application, it will be relaunched and the application can use the preserved data to restore state.
More info in the official documentation.
So, the navigation is kept, but you need to restore the state. You can always test this - in project properties, go to debug and select
Tombstone upon deactivation while debugging
So when you deactivate the app while debugging, it will actually go to tombstoned state and you can test it properly.

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 apps that run on startup?

What would be the easiest way for me to set up a Chrome extension that starts when I log in to my Windows account, and can be connected to a WebSocket server to check for, say, new messages, and then pop open a desktop notification, that clicks to the messages web page?
I expect that making an extension is straight forward, as well as getting it to communicate with WebSockets, and making the desktop notification.
But what about making it automatically start when I log in to the computer? What would be a good way to do this in Windows? I am not interested in having the chrome browser to open up at log in, but I certainly don't mind if I see Chrome in the task bar.
You might look into chrome.runtime.onStartUp: https://developer.chrome.com/apps/runtime#event-onStartup, which is
"Fired when a profile that has this extension installed first starts up."
Also, you can use chrome.alarms to schedule a function to run every minute or so, to open a WebSocket somewhere, etc.
The app may try to unload itself if there are no active windows, so you can call some action in chrome.runtime.onSuspend (like loading an XHR somewhere) to cause onSuspendCanceled to trigger.

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