Skip to content

Commit

Permalink
Attempt #1 to fix connectivity problems:
Browse files Browse the repository at this point in the history
After using an old computer for the first time in a while, I noticed it was having the connectivity problem.
So I checked the extension's console and saw that the response from mail.google.com was
"Failed to load resource: the server responded with a status of 401 (OK)"

After manually visiting mail.google.com, the problem went away. This mimic the workaround I tried.
  • Loading branch information
joeyespo committed Feb 20, 2016
1 parent 3ddf673 commit 365c20c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var canvasContext = canvas.getContext('2d');
var pollIntervalDefault = 60; // 1 minute
var pollIntervalMax = 3600; // 1 hour
var requestTimeout = 1000 * 2; // 2 seconds
var tryAgainTime = 1000 * 5; // 5 seconds
var rotation = 0;
var loadingAnimation = new LoadingAnimation();

Expand Down Expand Up @@ -188,7 +189,7 @@ function startRequest(params) {
);
}

function getInboxCount(onSuccess, onError) {
function getInboxCount(onSuccess, onError, workaroundAttempted) {
var xhr = new XMLHttpRequest();
var abortTimerId = window.setTimeout(function() {
xhr.abort(); // synchronously calls onreadystatechange
Expand All @@ -215,6 +216,20 @@ function getInboxCount(onSuccess, onError) {
if (xhr.readyState != 4)
return;

// Check for edge case where mail.google.com has not yet been visited and try again
if (xhr.status === 401) {
// Visit regular gmail to authorize feed access
console.log('Got error 401 while getting inbox count... opening', getGmailUrl());
chrome.tabs.create({ url: getGmailUrl() });
// Try again
if (!workaroundAttempted) {
window.setTimeout(function() {
getInboxCount(onSuccess, onError, true);
}, tryAgainTime);
}
return;
}

if (xhr.responseXML) {
var xmlDoc = xhr.responseXML;
var fullCountSet = xmlDoc.evaluate("/gmail:feed/gmail:fullcount",
Expand Down

0 comments on commit 365c20c

Please sign in to comment.